Merge pull request #37 from slackhq/remove_deprecated_hmac
remove old hmac function. superceded by ix_psk0
This commit is contained in:
commit
b01e181704
|
@ -61,16 +61,6 @@ punchy: true
|
|||
# path to a network adjacent nebula node.
|
||||
#local_range: "172.16.0.0/24"
|
||||
|
||||
# Handshake mac is an optional network-wide handshake authentication step that is used to prevent nebula from
|
||||
# responding to handshakes from nodes not in possession of the shared secret. This is primarily used to prevent
|
||||
# detection of nebula nodes when someone is scanning a network.
|
||||
#handshake_mac:
|
||||
#key: "DONOTUSETHISKEY"
|
||||
# You can define multiple accepted keys
|
||||
#accepted_keys:
|
||||
#- "DONOTUSETHISKEY"
|
||||
#- "dontusethiseither"
|
||||
|
||||
# sshd can expose informational and administrative functions via ssh this is a
|
||||
#sshd:
|
||||
# Toggles the feature
|
||||
|
|
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
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ func ixHandshakeStage0(f *Interface, vpnIp uint32, hostinfo *HostInfo) {
|
|||
Cert: ci.certState.rawCertificateNoKey,
|
||||
}
|
||||
|
||||
hsBytes := []byte{}
|
||||
|
||||
hs := &NebulaHandshake{
|
||||
Details: hsProto,
|
||||
Hmac: nil,
|
||||
}
|
||||
hsBytes, err = proto.Marshal(hs)
|
||||
|
||||
hsBytes, err := proto.Marshal(hs)
|
||||
//hsBytes, err := HandshakeBytesWithMAC(hsProto, f.handshakeMACKey)
|
||||
if err != nil {
|
||||
l.WithError(err).WithField("vpnIp", IntIp(vpnIp)).
|
||||
WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to marshal handshake message")
|
||||
|
@ -67,9 +67,6 @@ func ixHandshakeStage0(f *Interface, vpnIp uint32, hostinfo *HostInfo) {
|
|||
hostinfo.HandshakePacket[0] = msg
|
||||
hostinfo.HandshakeReady = true
|
||||
hostinfo.handshakeStart = time.Now()
|
||||
/*
|
||||
l.Debugln("ZZZZZZZZZZREMOTE: ", hostinfo.remote)
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -151,7 +148,6 @@ func ixHandshakeStage1(f *Interface, addr *udpAddr, hostinfo *HostInfo, packet [
|
|||
hostinfo.remoteIndexId = hs.Details.InitiatorIndex
|
||||
hs.Details.ResponderIndex = myIndex
|
||||
hs.Details.Cert = ci.certState.rawCertificateNoKey
|
||||
hs.Hmac = nil
|
||||
|
||||
hsBytes, err := proto.Marshal(hs)
|
||||
if err != nil {
|
||||
|
@ -237,11 +233,6 @@ func ixHandshakeStage1(f *Interface, addr *udpAddr, hostinfo *HostInfo, packet [
|
|||
}
|
||||
|
||||
f.hostMap.AddRemote(ip, addr)
|
||||
/*
|
||||
l.Debugln("111 ZZZZZZZZZZADDR: ", addr)
|
||||
l.Debugln("111 ZZZZZZZZZZREMOTE: ", hostinfo.remote)
|
||||
l.Debugln("111 ZZZZZZZZZZREMOTEs: ", hostinfo.Remotes[0].addr)
|
||||
*/
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -350,7 +341,4 @@ func ixHandshakeStage2(f *Interface, addr *udpAddr, hostinfo *HostInfo, packet [
|
|||
}
|
||||
|
||||
return false
|
||||
/*
|
||||
l.Debugln("222 ZZZZZZZZZZREMOTE: ", hostinfo.remote)
|
||||
*/
|
||||
}
|
||||
|
|
55
interface.go
55
interface.go
|
@ -1,15 +1,11 @@
|
|||
package nebula
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rcrowley/go-metrics"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
const mtu = 9001
|
||||
|
@ -26,8 +22,6 @@ type InterfaceConfig struct {
|
|||
lightHouse *LightHouse
|
||||
checkInterval int
|
||||
pendingDeletionInterval int
|
||||
handshakeMACKey string
|
||||
handshakeAcceptedMACKeys []string
|
||||
DropLocalBroadcast bool
|
||||
DropMulticast bool
|
||||
UDPBatchSize int
|
||||
|
@ -45,8 +39,6 @@ type Interface struct {
|
|||
serveDns bool
|
||||
createTime time.Time
|
||||
lightHouse *LightHouse
|
||||
handshakeMACKey []byte
|
||||
handshakeAcceptedMACKeys [][]byte
|
||||
localBroadcast uint32
|
||||
dropLocalBroadcast bool
|
||||
dropMulticast bool
|
||||
|
@ -72,37 +64,6 @@ func NewInterface(c *InterfaceConfig) (*Interface, error) {
|
|||
return nil, errors.New("no firewall rules")
|
||||
}
|
||||
|
||||
// Use KDF to make this useful
|
||||
hmacKey, err := sha256KdfFromString(c.handshakeMACKey)
|
||||
if err != nil {
|
||||
l.Debugln(err)
|
||||
}
|
||||
|
||||
allowedMacs := make([][]byte, 0)
|
||||
//allowedMacs = append(allowedMacs, mac)
|
||||
if len(c.handshakeAcceptedMACKeys) > 0 {
|
||||
for _, k := range c.handshakeAcceptedMACKeys {
|
||||
// Use KDF to make these useful too
|
||||
hmacKey, err := sha256KdfFromString(k)
|
||||
if err != nil {
|
||||
l.Debugln(err)
|
||||
}
|
||||
allowedMacs = append(allowedMacs, hmacKey)
|
||||
}
|
||||
} else {
|
||||
if len(c.handshakeMACKey) > 0 {
|
||||
l.Warnln("You have set an outgoing MAC but do not accept any incoming. This is probably not what you want.")
|
||||
} else {
|
||||
// This else is a fallback if we have not set any mac keys at all
|
||||
hmacKey, err := sha256KdfFromString("")
|
||||
if err != nil {
|
||||
l.Debugln(err)
|
||||
}
|
||||
allowedMacs = append(allowedMacs, hmacKey)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ifce := &Interface{
|
||||
hostMap: c.HostMap,
|
||||
outside: c.Outside,
|
||||
|
@ -114,8 +75,6 @@ func NewInterface(c *InterfaceConfig) (*Interface, error) {
|
|||
handshakeManager: c.HandshakeManager,
|
||||
createTime: time.Now(),
|
||||
lightHouse: c.lightHouse,
|
||||
handshakeMACKey: hmacKey,
|
||||
handshakeAcceptedMACKeys: allowedMacs,
|
||||
localBroadcast: ip2int(c.certState.certificate.Details.Ips[0].IP) | ^ip2int(c.certState.certificate.Details.Ips[0].Mask),
|
||||
dropLocalBroadcast: c.DropLocalBroadcast,
|
||||
dropMulticast: c.DropMulticast,
|
||||
|
@ -261,17 +220,3 @@ func (f *Interface) emitStats(i time.Duration) {
|
|||
f.handshakeManager.EmitStats()
|
||||
}
|
||||
}
|
||||
|
||||
func sha256KdfFromString(secret string) ([]byte, error) {
|
||||
// Use KDF to make this useful
|
||||
mac := []byte(secret)
|
||||
hmacKey := make([]byte, sha256.BlockSize)
|
||||
hash := sha256.New
|
||||
hkdfer := hkdf.New(hash, []byte(mac), nil, nil)
|
||||
n, err := io.ReadFull(hkdfer, hmacKey)
|
||||
if n != len(hmacKey) || err != nil {
|
||||
l.Errorln("KDF Failed!")
|
||||
return nil, fmt.Errorf("%s", err)
|
||||
}
|
||||
return hmacKey, nil
|
||||
}
|
||||
|
|
9
main.go
9
main.go
|
@ -12,8 +12,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
"github.com/slackhq/nebula/sshd"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var l = logrus.New()
|
||||
|
@ -238,8 +238,9 @@ func Main(configPath string, configTest bool, buildVersion string) {
|
|||
|
||||
handshakeManager := NewHandshakeManager(tunCidr, preferredRanges, hostMap, lightHouse, udpServer)
|
||||
|
||||
handshakeMACKey := config.GetString("handshake_mac.key", "")
|
||||
handshakeAcceptedMACKeys := config.GetStringSlice("handshake_mac.accepted_keys", []string{})
|
||||
//TODO: These will be reused for psk
|
||||
//handshakeMACKey := config.GetString("handshake_mac.key", "")
|
||||
//handshakeAcceptedMACKeys := config.GetStringSlice("handshake_mac.accepted_keys", []string{})
|
||||
|
||||
checkInterval := config.GetInt("timers.connection_alive_interval", 5)
|
||||
pendingDeletionInterval := config.GetInt("timers.pending_deletion_interval", 10)
|
||||
|
@ -255,8 +256,6 @@ func Main(configPath string, configTest bool, buildVersion string) {
|
|||
lightHouse: lightHouse,
|
||||
checkInterval: checkInterval,
|
||||
pendingDeletionInterval: pendingDeletionInterval,
|
||||
handshakeMACKey: handshakeMACKey,
|
||||
handshakeAcceptedMACKeys: handshakeAcceptedMACKeys,
|
||||
DropLocalBroadcast: config.GetBool("tun.drop_local_broadcast", false),
|
||||
DropMulticast: config.GetBool("tun.drop_multicast", false),
|
||||
UDPBatchSize: config.GetInt("listen.batch", 64),
|
||||
|
|
Loading…
Reference in New Issue