mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-20 21:59:07 +02:00
Revert "Introduces a forced WG handshake on initial MLKEM bootstrap."
This reverts commit b5a72eca65.
This commit is contained in:
@@ -738,35 +738,6 @@ func (conn *Conn) RequestReoffer() {
|
||||
}
|
||||
}
|
||||
|
||||
// ForcePQRehandshake makes WireGuard adopt a freshly bootstrapped post-quantum PSK on
|
||||
// an already-up session. The KEM exchange can complete after the WG endpoint was
|
||||
// configured (a race between the KEM and the relay/ICE connection coming up), so the
|
||||
// live session may be keyed with a pre-PQ key (the strict sentinel, or the ordinary
|
||||
// key in permissive mode); SetPresharedKey only updates config, not the running
|
||||
// session. Removing and re-adding the peer forces a fresh handshake that uses the real
|
||||
// PSK. No-op if not connected yet (the upcoming endpoint config will pull the PSK) or
|
||||
// if no PSK exists (a non-PQ peer stays fail-closed).
|
||||
func (conn *Conn) ForcePQRehandshake() {
|
||||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
|
||||
if conn.ctx.Err() != nil || conn.config.PQ == nil {
|
||||
return
|
||||
}
|
||||
psk, ok := conn.config.PQ.PSK(conn.config.Key)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if conn.currentConnPriority == conntype.None {
|
||||
return
|
||||
}
|
||||
conn.Log.Debugf("pqkem: bootstrap PSK ready, forcing WireGuard re-handshake to adopt it")
|
||||
wgPsk := wgtypes.Key(psk)
|
||||
if err := conn.endpointUpdater.ForceRehandshake(&wgPsk); err != nil {
|
||||
conn.Log.Warnf("pqkem: force re-handshake failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (conn *Conn) onWGDisconnected(watcherCtx context.Context) {
|
||||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
|
||||
@@ -20,13 +20,10 @@ type EndpointUpdater struct {
|
||||
wgConfig WgConfig
|
||||
initiator bool
|
||||
|
||||
// mu protects cancelFunc and lastEndpoint
|
||||
// mu protects cancelFunc
|
||||
mu sync.Mutex
|
||||
cancelFunc func()
|
||||
updateWg sync.WaitGroup
|
||||
// lastEndpoint is the most recent non-nil endpoint applied to the peer, used to
|
||||
// re-add it on a forced re-handshake (ForceRehandshake).
|
||||
lastEndpoint *net.UDPAddr
|
||||
}
|
||||
|
||||
func NewEndpointUpdater(log *logrus.Entry, wgConfig WgConfig, initiator bool) *EndpointUpdater {
|
||||
@@ -41,10 +38,6 @@ func (e *EndpointUpdater) ConfigureWGEndpoint(addr *net.UDPAddr, presharedKey *w
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
if addr != nil {
|
||||
e.lastEndpoint = addr
|
||||
}
|
||||
|
||||
if e.initiator {
|
||||
e.log.Debugf("configure up WireGuard as initiator")
|
||||
return e.configureAsInitiator(addr, presharedKey)
|
||||
@@ -58,36 +51,12 @@ func (e *EndpointUpdater) SwitchWGEndpoint(addr *net.UDPAddr, presharedKey *wgty
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
if addr != nil {
|
||||
e.lastEndpoint = addr
|
||||
}
|
||||
|
||||
// prevent to run new update while cancel the previous update
|
||||
e.waitForCloseTheDelayedUpdate()
|
||||
|
||||
return e.updateWireGuardPeer(addr, presharedKey)
|
||||
}
|
||||
|
||||
// ForceRehandshake removes and re-adds the peer so WireGuard drops the current session
|
||||
// and negotiates a fresh one with the given PSK. Used when a post-quantum PSK is
|
||||
// bootstrapped after the session already came up on a pre-PQ key. No-op if no endpoint
|
||||
// has been applied yet (the pending config will pull the PSK itself).
|
||||
func (e *EndpointUpdater) ForceRehandshake(presharedKey *wgtypes.Key) error {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
if e.lastEndpoint == nil {
|
||||
return nil
|
||||
}
|
||||
// Cancel any pending delayed responder update: it carries the stale pre-PQ key and
|
||||
// would otherwise re-poison the session after we reset it.
|
||||
e.waitForCloseTheDelayedUpdate()
|
||||
if err := e.wgConfig.WgInterface.RemovePeer(e.wgConfig.RemoteKey); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.updateWireGuardPeer(e.lastEndpoint, presharedKey)
|
||||
}
|
||||
|
||||
func (e *EndpointUpdater) RemoveWgPeer() error {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user