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:
Brad Fitzpatrick
2020-07-06 12:10:39 -07:00
parent 32156330a8
commit 6196b7e658
6 changed files with 20 additions and 25 deletions

View File

@@ -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.