|
|
@ -9,7 +9,6 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
crand "crypto/rand"
|
|
|
|
crand "crypto/rand"
|
|
|
|
"crypto/tls"
|
|
|
|
"crypto/tls"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
@ -941,12 +940,9 @@ func testTwoDevicePing(t *testing.T, d *devices) {
|
|
|
|
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")},
|
|
|
|
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")},
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
wgcfg.Peer{
|
|
|
|
wgcfg.Peer{
|
|
|
|
PublicKey: m2.privateKey.Public(),
|
|
|
|
|
|
|
|
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")},
|
|
|
|
|
|
|
|
Endpoints: wgcfg.Endpoints{
|
|
|
|
|
|
|
|
PublicKey: m2.privateKey.Public(),
|
|
|
|
PublicKey: m2.privateKey.Public(),
|
|
|
|
DiscoKey: m2.conn.DiscoPublicKey(),
|
|
|
|
DiscoKey: m2.conn.DiscoPublicKey(),
|
|
|
|
},
|
|
|
|
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -956,12 +952,9 @@ func testTwoDevicePing(t *testing.T, d *devices) {
|
|
|
|
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")},
|
|
|
|
Addresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.2/32")},
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
wgcfg.Peer{
|
|
|
|
wgcfg.Peer{
|
|
|
|
PublicKey: m1.privateKey.Public(),
|
|
|
|
|
|
|
|
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")},
|
|
|
|
|
|
|
|
Endpoints: wgcfg.Endpoints{
|
|
|
|
|
|
|
|
PublicKey: m1.privateKey.Public(),
|
|
|
|
PublicKey: m1.privateKey.Public(),
|
|
|
|
DiscoKey: m1.conn.DiscoPublicKey(),
|
|
|
|
DiscoKey: m1.conn.DiscoPublicKey(),
|
|
|
|
},
|
|
|
|
AllowedIPs: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("1.0.0.1/32")},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1158,19 +1151,6 @@ func newTestConn(t testing.TB) *Conn {
|
|
|
|
return conn
|
|
|
|
return conn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func makeEndpoint(tb testing.TB, public tailcfg.NodeKey, disco tailcfg.DiscoKey) string {
|
|
|
|
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
ep := wgcfg.Endpoints{
|
|
|
|
|
|
|
|
PublicKey: wgkey.Key(public),
|
|
|
|
|
|
|
|
DiscoKey: disco,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
buf, err := json.Marshal(ep)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
tb.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(buf)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// addTestEndpoint sets conn's network map to a single peer expected
|
|
|
|
// addTestEndpoint sets conn's network map to a single peer expected
|
|
|
|
// to receive packets from sendConn (or DERP), and returns that peer's
|
|
|
|
// to receive packets from sendConn (or DERP), and returns that peer's
|
|
|
|
// nodekey and discokey.
|
|
|
|
// nodekey and discokey.
|
|
|
@ -1190,7 +1170,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (tailcf
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
conn.SetPrivateKey(wgkey.Private{0: 1})
|
|
|
|
conn.SetPrivateKey(wgkey.Private{0: 1})
|
|
|
|
_, err := conn.ParseEndpoint(makeEndpoint(tb, nodeKey, discoKey))
|
|
|
|
_, err := conn.ParseEndpoint(wgkey.Key(nodeKey).HexString())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
tb.Fatal(err)
|
|
|
|
tb.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1374,7 +1354,7 @@ func TestSetNetworkMapChangingNodeKey(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
_, err := conn.ParseEndpoint(makeEndpoint(t, nodeKey1, discoKey))
|
|
|
|
_, err := conn.ParseEndpoint(wgkey.Key(nodeKey1).HexString())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|