wgengine/magicsock: open discovery naclbox messages from known peers

And track known peers.

Doesn't yet do anything with the messages. (nor does it send any yet)

Start of docs on the message format. More will come in subsequent changes.

Updates #483
This commit is contained in:
Brad Fitzpatrick
2020-06-26 14:38:53 -07:00
parent 9258d64261
commit 103c06cc68
2 changed files with 115 additions and 3 deletions
+28
View File
@@ -23,6 +23,7 @@ import (
"github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/tun/tuntest"
"github.com/tailscale/wireguard-go/wgcfg"
"golang.org/x/crypto/nacl/box"
"tailscale.com/derp"
"tailscale.com/derp/derphttp"
"tailscale.com/derp/derpmap"
@@ -835,3 +836,30 @@ func TestAddrSet(t *testing.T) {
})
}
}
func TestDiscoMessage(t *testing.T) {
peer1Priv := key.NewPrivate()
peer1Pub := peer1Priv.Public()
c := &Conn{
logf: t.Logf,
discoPrivate: key.NewPrivate(),
nodeOfDisco: map[tailcfg.DiscoKey]tailcfg.NodeKey{
tailcfg.DiscoKey(peer1Pub): tailcfg.NodeKey{1: 1},
},
}
const payload = "why hello"
var nonce [24]byte
crand.Read(nonce[:])
pkt := append([]byte("TS💬"), peer1Pub[:]...)
pkt = append(pkt, nonce[:]...)
pkt = box.Seal(pkt, []byte(payload), &nonce, c.discoPrivate.Public().B32(), peer1Priv.B32())
got := c.handleDiscoMessage(pkt, &net.UDPAddr{})
if !got {
t.Error("failed to open it")
}
}