mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +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:
parent
32156330a8
commit
6196b7e658
@ -361,9 +361,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
|
||||
var discoPublic tailcfg.DiscoKey
|
||||
if controlclient.Debug.Disco {
|
||||
discoPrivate := key.NewPrivate()
|
||||
b.e.SetDiscoPrivateKey(discoPrivate)
|
||||
discoPublic = tailcfg.DiscoKey(discoPrivate.Public())
|
||||
discoPublic = b.e.DiscoPublicKey()
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -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{
|
||||
// ...
|
||||
|
@ -827,8 +827,8 @@ func (e *userspaceEngine) SetNetworkMap(nm *controlclient.NetworkMap) {
|
||||
e.magicConn.SetNetworkMap(nm)
|
||||
}
|
||||
|
||||
func (e *userspaceEngine) SetDiscoPrivateKey(k key.Private) {
|
||||
e.magicConn.SetDiscoPrivateKey(k)
|
||||
func (e *userspaceEngine) DiscoPublicKey() tailcfg.DiscoKey {
|
||||
return e.magicConn.DiscoPublicKey()
|
||||
}
|
||||
|
||||
func (e *userspaceEngine) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
|
@ -14,7 +14,6 @@
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/wgengine/filter"
|
||||
"tailscale.com/wgengine/router"
|
||||
"tailscale.com/wgengine/tsdns"
|
||||
@ -101,8 +100,9 @@ func (e *watchdogEngine) SetDERPMap(m *tailcfg.DERPMap) {
|
||||
func (e *watchdogEngine) SetNetworkMap(nm *controlclient.NetworkMap) {
|
||||
e.watchdog("SetNetworkMap", func() { e.wrap.SetNetworkMap(nm) })
|
||||
}
|
||||
func (e *watchdogEngine) SetDiscoPrivateKey(k key.Private) {
|
||||
e.watchdog("SetDiscoPrivateKey", func() { e.wrap.SetDiscoPrivateKey(k) })
|
||||
func (e *watchdogEngine) DiscoPublicKey() (k tailcfg.DiscoKey) {
|
||||
e.watchdog("DiscoPublicKey", func() { k = e.wrap.DiscoPublicKey() })
|
||||
return k
|
||||
}
|
||||
func (e *watchdogEngine) Close() {
|
||||
e.watchdog("Close", e.wrap.Close)
|
||||
|
@ -12,7 +12,6 @@
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/wgengine/filter"
|
||||
"tailscale.com/wgengine/router"
|
||||
"tailscale.com/wgengine/tsdns"
|
||||
@ -117,9 +116,9 @@ type Engine interface {
|
||||
// new NetInfo summary is available.
|
||||
SetNetInfoCallback(NetInfoCallback)
|
||||
|
||||
// SetDiscoPrivateKey sets the private key used for path discovery
|
||||
// DiscoPublicKey gets the public key used for path discovery
|
||||
// messages.
|
||||
SetDiscoPrivateKey(key.Private)
|
||||
DiscoPublicKey() tailcfg.DiscoKey
|
||||
|
||||
// UpdateStatus populates the network state using the provided
|
||||
// status builder.
|
||||
|
Loading…
Reference in New Issue
Block a user