Commit Graph

3303 Commits

Author SHA1 Message Date
riccardom
ec2d6c9004 pqkem: clock data-path PSK rotation from WireGuard handshakes
Source OnDataPathRekeyed from the WGWatcher's per-handshake callback
(onWGCheckSuccess), which fires only on a fresh handshake, and OnDataPathDown
from the handshake-timeout path. A fresh handshake clocks the next chained
KEM exchange pushed over the data-path UDP transport.
2026-08-27 12:18:07 +02:00
riccardom
c49666c859 pqkem: register data-path endpoint from signalling
Learn the peer's data-path endpoint from the signalling offer/answer: its WG
overlay IP combined with the advertised pq UDP port (SetRemotePort -> AddPeer).
Registering here is safe before the tunnel is up because sends only ever fire
once it is (clocked by OnDataPathRekeyed). RemovePeer is wired at peer teardown
(engine.removePeer), not on transient disconnect.
2026-08-27 12:18:07 +02:00
riccardom
5fabb87b02 pqkem: apply derived PSK at WG peer-config time (pull) + keep push for rekey 2026-08-27 12:18:07 +02:00
riccardom
2400eaa246 pqkem: carry KEM offer/answer over the signalling exchange 2026-08-27 12:18:07 +02:00
riccardom
850d35b896 pqkem: dedicated slog logger via NB_PQ_MLKEM_LOG_LEVEL 2026-08-27 12:18:07 +02:00
riccardom
b861d57856 Homogeneous logs prefix 2026-08-27 12:18:07 +02:00
riccardom
d255b53279 Bit of renaming
peer -> peerAddrs
have types for remoteID and localID
t.Close log error
Manager SetTransport -> Start
2026-08-27 12:18:07 +02:00
riccardom
3e188eaf13 Typo 2026-08-27 12:18:07 +02:00
riccardom
8f9e18aa31 Race fix 2026-08-27 12:18:07 +02:00
riccardom
11f8409354 Makes Transport just a UDP socket.
Manager owns maps for remoteID <-> remote UDP addr
Engine talks to manager only
2026-08-27 12:18:07 +02:00
riccardom
bf7ed45ca9 Adds transport 2026-08-27 12:18:07 +02:00
riccardom
e1f91d02ee Communicate the port over the signal exchange 2026-08-27 12:18:07 +02:00
riccardom
3bdf2db52f Ensure iface is up and with overlay ip assigned to get a valid UDP port 2026-08-27 12:18:07 +02:00
riccardom
07c5ac6bac Adds real callback setter for PSK on ready 2026-08-27 12:18:07 +02:00
riccardom
dc9ea94c61 Initializes PQ ML-KEM manager 2026-08-27 12:18:07 +02:00
riccardom
87a3f1e056 Adds no-op Transports and callbacks 2026-08-27 12:18:07 +02:00
riccardom
3da87de12a Added enabled env var 2026-08-27 12:18:07 +02:00
riccardom
87fbf0ac26 Adds MLKEM Payload placeholder to client internals 2026-08-27 12:18:07 +02:00
riccardom
1cab588bc0 Invert order of keys as per draft 2026-08-27 12:18:07 +02:00
riccardom
d29faa7f46 Protocol update 2026-08-27 12:18:07 +02:00
riccardom
a8350c77f8 Removes confirm. Uses next offer to deliver confirmation/ack of previous round
We clock the next Offer initiation to the OnDataPathRekeyed, so we have 2 minutes
ahead of us to do our attempts and stuff before to give up.
On failure, we will know because we will not receive a new answer.. but more importantly
the wg handshake will fail :D
2026-08-27 12:18:07 +02:00
riccardom
6f6fdfff4d Leave signal offer/answer as a pull/push operation not as an actual transport 2026-08-27 12:18:07 +02:00
riccardom
65948ca76d Assume two transports: initial "signal" (control plane) one (no data path established yet) + data path one
Define OnDataPathRekeyed event to transition from control plane path to data plane path over the WG tunnel.

Keep confirm ALWAYS on NEW established WG tunnel (posthandshake with rekeying). We keep an active method
irrelevant of the WG handshake (we might decide that the indirect wg handshake is sufficient in the future).

Optimistic commit on responder(when sending answer), while on initiator we set it on getting the answer
2026-08-27 12:18:07 +02:00
riccardom
da6a56a7ef Epurate wg refs 2026-08-27 12:18:07 +02:00
riccardom
4582c5b4fc Collapse Driver and Manager in one.
- Have just one manager => one lock
 - Session state is needed in driver to => we have it available now.
 - Isomorphically align to rosenpass components and functionality

File	Role	                                  rosenpass equivalent
kem.go	primitive pure X25519MLKEM768	          crypto.go/handshake
message.go	Offer/Answer/Confirm + Encode/Decode  messages.go
manager.go	Manager stateful, single lock	      server logic
callbacks.go	WGCallbackHandler (seam output)	  Handler
Transport (interfaccia)	seam trasporto pluggable  Conn
2026-08-27 12:18:07 +02:00
riccardom
5eea1b1c8e [squash] isInitial and answered can be inferred without state variables 2026-08-27 12:18:07 +02:00
riccardom
b92f7c54d0 Manages convergence 2026-08-27 12:18:07 +02:00
riccardom
0cf67417f9 Models reattempts 2026-08-27 12:18:07 +02:00
riccardom
f66b94be07 Reuse answer, don't calculate again 2026-08-27 12:18:07 +02:00
riccardom
7cb08f7282 Adds driver to glue together manager and outside world 2026-08-27 12:18:07 +02:00
riccardom
33734635bf Defines event callbacks 2026-08-27 12:18:07 +02:00
riccardom
1d7acada1c Admits possible errors on Encode 2026-08-27 12:18:07 +02:00
riccardom
bfcc8aaa94 Bench key material boilerplate time/allocs
CGO_ENABLED=1 go test ./client/internal/pqkem/ -run '^$' -bench . -benchmem 2>&1 | grep -E "Benchmark|ns/op|PASS|ok" | head -20

BenchmarkX25519Keygen-14    	   33795	     34966 ns/op	     224 B/op	       5 allocs/op
BenchmarkX25519ECDH-14      	   33855	     33973 ns/op	      32 B/op	       1 allocs/op
BenchmarkMLKEMKeygen-14     	   21817	     67778 ns/op	    8200 B/op	       2 allocs/op
BenchmarkMLKEMEncaps-14     	   29918	     43235 ns/op	    1216 B/op	       2 allocs/op
BenchmarkMLKEMDecaps-14     	   26048	     56291 ns/op	      64 B/op	       2 allocs/op
PASS
ok  	github.com/netbirdio/netbird/client/internal/pqkem	9.751s
Shell cwd was reset to /home/riccardo/Desktop/Personal/netbirdio/netbird
2026-08-27 12:18:07 +02:00
riccardom
59a23d706a Pure mechanics of manager 2026-08-27 12:18:07 +02:00
riccardom
045678c184 Messages definition 2026-08-27 12:18:07 +02:00
riccardom
cb9f8f75e6 ML-KEM encapsulate/decapsulate module 2026-08-27 12:18:07 +02:00
Viktor Liu
473392a935 [client] Tolerate a still-locked updater binary when cleaning up after an update (#7286) 2026-08-26 20:03:56 +02:00
Viktor Liu
0bd1147ff0 [client] Keep NetBird traffic out of third-party fwmark rules (#7314) 2026-08-26 20:03:40 +02:00
Viktor Liu
f221347c7a [infrastructure] Trigger the dashboard wasm client bump on release tags (#7277) 2026-08-26 15:34:10 +02:00
dmitri-netbird
0a9ce7f797 [client] fix a flake in TestResolver_ConcurrentStaleHitsCollapseRefresh test (#7326)
* fix a flake in TestResolver_ConcurrentStaleHitsCollapseRefresh test

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* use testify's eventually asserts

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

---------

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
2026-08-26 12:51:19 +02:00
Viktor Liu
7e8b4e1417 [client, proxy] Remove lazy connection exclusions and run Rosenpass on the embedded proxy (#6763)
* Run lazy connection manager for rosenpass peers

* Treat forward-target peers as normal lazy connections

* Run Rosenpass in permissive mode on the embedded proxy
2026-08-26 12:43:48 +02:00
dmitri-netbird
2621aaa619 [management, client] add protobuf breaking changes check (#7305)
* add protobuf breaking changes check

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* disable path check for now

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* enable breaking checks

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* testing breaking change

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* Revert "testing breaking change"

This reverts commit 05e6ef9b78.

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* remove commented out proto paths

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* disable pushes

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* responded to feedback

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* trigger workflow on changes to buf config or the workflow itself

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* fix the workflow file name

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* explicit config for actions

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

---------

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
2026-08-26 11:48:05 +02:00
Zoltan Papp
ed7d4de999 [client, ios] Migrate switft profile manager to go (#6528)
* [client] Add iOS NetBirdSDK profile manager binding

Mirror the Android profile manager in the iOS gomobile binding so the
core's ID-based profilemanager.ServiceManager owns profile state on iOS
too, instead of a parallel Swift reimplementation.

Adds client/ios/NetBirdSDK/profile_manager.go (//go:build ios): an
ID-based ProfileManager wrapping ServiceManager with iOS-specific path
handling (default profile at the container-root netbird.cfg, others as
profiles/<id>.json) and a gomobile-friendly API: List/Add/Switch/Rename/
Logout/Remove plus active config/state path accessors. The default
profile keeps the reserved "default" id and is never assigned a hex id.

* fix(ios): preserve profile name when saving config during auth

NewAuth built a fresh in-memory config from only the management URL, so
the SSO/setup-key save (DirectWriteOutConfig) overwrote the profile config
file the profile manager had just written, wiping the display name to ""
and forcing the UI to fall back to the profile ID. Load the existing config
when present and override only the management URL, keeping the name and keys.

* [client] Extract the mobile profile manager into client/mobile

The Android and iOS gomobile bindings carried two near-identical copies of
the profile manager. Move the shared implementation into a new client/mobile
package and reduce both bindings to thin adapters that only translate to
gomobile-friendly types (gomobile binds per package, so the Profile /
ProfileArray wrappers have to stay platform-side).

Also bring the account-email layer over to the shared package: an SSO login
records the account under <stem>.account.json so the next login can pass it
as an OIDC login_hint. Logout keeps it, profile removal drops it. The suffix
deliberately differs from .state.json, which the engine's state manager owns
in the same directory on mobile.

Adds profilemanager.Prefs (namespaced per-profile preference store) and its
cleanup in ServiceManager.RemoveProfile, exposed through the shared manager
as ProfilePrefs.
2026-08-26 09:42:50 +02:00
Viktor Liu
51095cb986 [client, management] Support per-peer lazy connection state and default proxy peers to lazy (#6762)
* Support per-peer lazy connection state and default proxy peers to lazy

* Classify forward targets from incoming config in lazy exclusion

* Set IsUserspaceBind mock so lazy manager starts in engine test

* Skip lazy exclude reconciliation when the set is unchanged

* Keep cached lazy flag when a sync carries no peer config
2026-08-26 09:33:51 +02:00
Viktor Liu
ccf8f43cb1 [client] Ask the OS for privileges when a guarded SSH setting is changed (#7066) 2026-08-25 20:15:16 +02:00
Zoltan Papp
15fff4c164 [client] Sweep connections on network loss via a shared netevents manager (#7254)
Losing the last network only flipped the availability state: the dead management, signal and relay sockets stayed silently connected until their own timeouts, so the client kept reporting Connected with no network at all.

Introduce client/netevents with a Manager that ties the availability state, the connection sweeper and the status recorder together, and move the netstate and netsweep packages under it (netsweep renamed to sweep). SetNetworkAvailable(false) now also sweeps the registered connections so their owners redial and the listener reaches the NoNetwork state.

The Android and iOS bindings own a Manager instance and inject it through the constructors; consumers hold the concrete *Manager whose nil zero value reports always-online and never sweeps, with interfaces kept only as parameter contracts. The relay guard settle wait moved into the Manager as WaitSettled, removing the netevents import from the relay package.
2026-08-25 18:43:19 +02:00
dmitri-netbird
c512bf25aa [management] handle nil ptr in sendInitialSync() when the peer is deleted (#7315)
* fix a nil-ptr error occuring in sendInitialSync when the peer being synced is deleted

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

* handle a nil ptr in GetPeerNetworkMapComponents

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>

---------

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
2026-08-25 16:14:17 +02:00
Pascal Fischer
7d83a3902d [proxy] validate header auth on proxy (#7263) 2026-08-25 13:46:26 +02:00
Zoltan Papp
a08f7f63f4 [client] Create GUI windows on demand and destroy them on close (#7096)
The main and Settings windows were created at startup and kept alive hidden on close, so an idle tray held two webview processes for surfaces the user may never open. Both are now built on first show and destroyed on close, which takes the idle footprint on macOS from ~160 MB to ~74 MB.

The WindowManager owns creation: it rebuilds the main window on the next show and hands out live pointers, since a stored one goes stale. Every show is deferred until the frontend reports it has rendered, so a freshly created window is never on screen empty, with a timeout so a frontend that never reports cannot strand a window hidden.
2026-08-25 11:40:31 +02:00
Zoltan Papp
3f90181f35 [ci] Remove mobile build validation workflow (#7302)
The Android and iOS library builds now run in the android-client and
ios-client repositories, so this workflow duplicates them.
2026-08-24 14:11:02 +02:00