From 80122940422c291aacdd2d35c0cd96e58a64d9d4 Mon Sep 17 00:00:00 2001 From: riccardom Date: Mon, 6 Jul 2026 18:19:29 +0200 Subject: [PATCH] Add logs for Rosenpass to check for lost key --- client/internal/peer/conn.go | 4 ++++ client/internal/peer/endpoint.go | 6 ++++++ client/internal/peer/wg_watcher.go | 1 + client/internal/rosenpass/netbird_handler.go | 1 + 4 files changed, 12 insertions(+) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index fb468696f..1e563f6e0 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -932,18 +932,22 @@ func (conn *Conn) AgentVersionString() string { func (conn *Conn) presharedKey(remoteRosenpassKey []byte) *wgtypes.Key { if conn.config.RosenpassConfig.PubKey == nil { + conn.Log.Warnf("PSK-DIAG: rosenpass off -> static PSK (present=%v)", conn.config.WgConfig.PreSharedKey != nil) return conn.config.WgConfig.PreSharedKey } if remoteRosenpassKey == nil && conn.config.RosenpassConfig.PermissiveMode { + conn.Log.Warnf("PSK-DIAG: rosenpass permissive + no remote RP key -> static PSK bridge (present=%v)", conn.config.WgConfig.PreSharedKey != nil) return conn.config.WgConfig.PreSharedKey } // If Rosenpass has already set a PSK for this peer, return nil to prevent // UpdatePeer from overwriting the Rosenpass-managed key. if conn.rosenpassInitializedPresharedKeyValidator != nil && conn.rosenpassInitializedPresharedKeyValidator(conn.config.Key) { + conn.Log.Warnf("PSK-DIAG: rosenpass initialized -> returning nil (keep existing on-wire PSK; NOT re-set)") return nil } + conn.Log.Warnf("PSK-DIAG: rosenpass strict, not yet initialized -> seeding PSK (staticPresent=%v)", conn.config.WgConfig.PreSharedKey != nil) // Use NetBird PSK as the seed for Rosenpass. This same PSK is passed to // Rosenpass as PeerConfig.PresharedKey, ensuring the derived post-quantum diff --git a/client/internal/peer/endpoint.go b/client/internal/peer/endpoint.go index 9ba1efb6e..302ac01dc 100644 --- a/client/internal/peer/endpoint.go +++ b/client/internal/peer/endpoint.go @@ -38,6 +38,8 @@ func (e *EndpointUpdater) ConfigureWGEndpoint(addr *net.UDPAddr, presharedKey *w e.mu.Lock() defer e.mu.Unlock() + e.log.Warnf("PSK-DIAG: ConfigureWGEndpoint endpoint=%s psk_present=%v", addr, presharedKey != nil) + if e.initiator { e.log.Debugf("configure up WireGuard as initiator") return e.configureAsInitiator(addr, presharedKey) @@ -51,6 +53,8 @@ func (e *EndpointUpdater) SwitchWGEndpoint(addr *net.UDPAddr, presharedKey *wgty e.mu.Lock() defer e.mu.Unlock() + e.log.Warnf("PSK-DIAG: SwitchWGEndpoint endpoint=%s psk_present=%v", addr, presharedKey != nil) + // prevent to run new update while cancel the previous update e.waitForCloseTheDelayedUpdate() @@ -69,6 +73,8 @@ func (e *EndpointUpdater) RemoveEndpointAddress() error { e.mu.Lock() defer e.mu.Unlock() + e.log.Warnf("PSK-DIAG: RemoveEndpointAddress -> peer re-added with only PublicKey+AllowedIPs; on-wire PSK is dropped") + e.waitForCloseTheDelayedUpdate() return e.wgConfig.WgInterface.RemoveEndpointAddress(e.wgConfig.RemoteKey) } diff --git a/client/internal/peer/wg_watcher.go b/client/internal/peer/wg_watcher.go index 4fc883d17..b81aa4235 100644 --- a/client/internal/peer/wg_watcher.go +++ b/client/internal/peer/wg_watcher.go @@ -66,6 +66,7 @@ func (w *WGWatcher) PrepareInitialHandshake() (ok bool) { handshake, _ := w.wgState() w.initialHandshake = handshake + w.log.Warnf("PSK-DIAG: watcher baseline handshake=%v (zero=%v)", handshake, handshake.IsZero()) return true } diff --git a/client/internal/rosenpass/netbird_handler.go b/client/internal/rosenpass/netbird_handler.go index 9de2409ef..8fa4a5057 100644 --- a/client/internal/rosenpass/netbird_handler.go +++ b/client/internal/rosenpass/netbird_handler.go @@ -100,6 +100,7 @@ func (h *NetbirdHandler) outputKey(_ rp.KeyOutputReason, pid rp.PeerID, psk rp.K log.Errorf("Failed to apply rosenpass key: %v", err) return } + log.Warnf("PSK-DIAG: rosenpass set PSK on WG for peer %s (updateOnly=%v)", peerKey, isInitialized) // Mark peer as isInitialized after the successful first rotation if !isInitialized {