remove old hmac function. superceded by ix_psk0
This commit is contained in:
51
handshake.go
51
handshake.go
@ -1,12 +1,5 @@
|
||||
package nebula
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
handshakeIXPSK0 = 0
|
||||
handshakeXXPSK0 = 1
|
||||
@ -36,47 +29,3 @@ func HandleIncomingHandshake(f *Interface, addr *udpAddr, packet []byte, h *Head
|
||||
f.handshakeManager.DeleteVpnIP(newHostinfo.hostId)
|
||||
}
|
||||
}
|
||||
|
||||
func HandshakeBytesWithMAC(details *NebulaHandshakeDetails, key []byte) ([]byte, error) {
|
||||
mac := hmac.New(sha256.New, key)
|
||||
|
||||
b, err := proto.Marshal(details)
|
||||
if err != nil {
|
||||
return nil, errors.New("Unable to marshal nebula handshake")
|
||||
}
|
||||
mac.Write(b)
|
||||
sum := mac.Sum(nil)
|
||||
|
||||
hs := &NebulaHandshake{
|
||||
Details: details,
|
||||
Hmac: sum,
|
||||
}
|
||||
|
||||
hsBytes, err := proto.Marshal(hs)
|
||||
if err != nil {
|
||||
l.Debugln("failed to generate NebulaHandshake protobuf", err)
|
||||
}
|
||||
|
||||
return hsBytes, nil
|
||||
}
|
||||
|
||||
func (hs *NebulaHandshake) CheckHandshakeMAC(keys [][]byte) bool {
|
||||
|
||||
b, err := proto.Marshal(hs.Details)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, k := range keys {
|
||||
mac := hmac.New(sha256.New, k)
|
||||
mac.Write(b)
|
||||
expectedMAC := mac.Sum(nil)
|
||||
if hmac.Equal(hs.Hmac, expectedMAC) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
//l.Debugln(hs.Hmac, expectedMAC)
|
||||
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user