mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 18:11:59 +00:00
wgengine/magicsock: change API to not permit disco key changes
Generate the disco key ourselves and give out the public half instead. Fixes #525
This commit is contained in:
@@ -504,19 +504,18 @@ func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo)) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetDiscoPrivateKey sets the discovery key.
|
||||
func (c *Conn) SetDiscoPrivateKey(k key.Private) {
|
||||
// DiscoPublicKey returns the discovery public key.
|
||||
func (c *Conn) DiscoPublicKey() tailcfg.DiscoKey {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if !c.discoPrivate.IsZero() && c.discoPrivate != k {
|
||||
// TODO: support changing a key at runtime; need to
|
||||
// clear a bunch of maps at least
|
||||
panic("unsupported")
|
||||
if c.discoPrivate.IsZero() {
|
||||
priv := key.NewPrivate()
|
||||
c.discoPrivate = priv
|
||||
c.discoPublic = tailcfg.DiscoKey(priv.Public())
|
||||
c.discoShort = c.discoPublic.ShortString()
|
||||
c.logf("magicsock: disco key = %v", c.discoShort)
|
||||
}
|
||||
c.discoPrivate = k
|
||||
c.discoPublic = tailcfg.DiscoKey(k.Public())
|
||||
c.discoShort = c.discoPublic.ShortString()
|
||||
c.logf("magicsock: set disco key = %v", c.discoShort)
|
||||
return c.discoPublic
|
||||
}
|
||||
|
||||
// c.mu must NOT be held.
|
||||
|
||||
@@ -855,12 +855,11 @@ func initAddrSet(as *AddrSet) {
|
||||
}
|
||||
|
||||
func TestDiscoMessage(t *testing.T) {
|
||||
peer1Priv := key.NewPrivate()
|
||||
peer1Pub := peer1Priv.Public()
|
||||
|
||||
c := newConn()
|
||||
c.logf = t.Logf
|
||||
c.SetDiscoPrivateKey(key.NewPrivate())
|
||||
|
||||
peer1Pub := c.DiscoPublicKey()
|
||||
peer1Priv := c.discoPrivate
|
||||
c.endpointOfDisco = map[tailcfg.DiscoKey]*discoEndpoint{
|
||||
tailcfg.DiscoKey(peer1Pub): &discoEndpoint{
|
||||
// ...
|
||||
|
||||
Reference in New Issue
Block a user