Commit Graph

3234 Commits

Author SHA1 Message Date
riccardom
8a203e7e4e pqkem: strict (fail-closed) mode + wire status Quantum resistance
Strict mode (NB_PQ_MLKEM_STRICT, default off) closes the initial PQ-vulnerable
window (NET-1408): when enabled, conn.presharedKey programs a per-conn random
sentinel PSK until the ML-KEM exchange derives the real one, so no session can form
on a non-PQ key (the real PSK is pushed via SetPresharedKey once it converges).
Default stays opportunistic.

Also surface PQ status: the peer 'Quantum resistance' flag (RosenpassEnabled) is now
true when an ML-KEM PSK has been derived for the peer, not only for Rosenpass.
2026-08-07 10:24:01 +02:00
riccardom
2625b3d5ee pqkem: rotate PSK in kernel mode instead of skipping
The idle-gate reads LastActivities, which only tracks per-peer data in userspace;
in kernel mode it is empty, so the gate treated every kernel peer as idle and
disabled data-path rotation entirely. Detect the bind via IsUserspaceBind and, in
kernel mode, report zero activity age (always 'active') so rotation runs on every
rekey. Lazy back-to-idle is already limited in kernel; the eBPF WG-activity
detection will later supply a real signal that excludes handshake/pqkem traffic.
2026-08-07 10:24:01 +02:00
riccardom
27ac3ca9f6 pqkem: derive PSK with HKDF-SHA256
Replace the raw SHA-256 concat combiner with HKDF-SHA256 (crypto/hkdf, Go 1.24):
IKM = ML-KEM_ss || X25519_ss (draft-ietf-tls-ecdhe-mlkem order), salt = the
domain-separation label, info = full transcript (offer || answer) || canonicalised
peer identities. Keeps the transcript + identity binding while using a proper KDF.
2026-08-07 10:24:01 +02:00
riccardom
3ad2989556 Don't rotate PQ keys if data path is idle for ~90s (less than a WG handhshake time 2026-08-07 10:24:01 +02:00
riccardom
c9a66a7fbc Adds log tracepoints
- Add a trace slog level (NB_PQ_MLKEM_LOG_LEVEL=trace) and move the verbose
  per-exchange lifecycle logs (offer/answer/PSK/ack/rotation) to it, so debug
  stays quiet and troubleshooting is opt-in.
- Stop logging the raw preshared key; drop the temporary pqkem-dbg OnRemoteOffer/
  OnRemoteAnswer probes.
- Demote the per-handshake conn log to trace.
2026-08-07 10:24:01 +02:00
riccardom
e447011dc3 Fixes second answer dropped (the one carrying the PQ KEM data)
Prevents dropping concurrent answer / offer carrying the PQ ML-KEM data
2026-08-07 10:24:01 +02:00
riccardom
cec3ca229e Renames SetRemotePort to SetRemoteAddr 2026-08-07 10:24:01 +02:00
riccardom
7ceb319107 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-07 10:24:01 +02:00
riccardom
5f9c67cdaa 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-07 10:24:01 +02:00
riccardom
8b7c105b5e pqkem: apply derived PSK at WG peer-config time (pull) + keep push for rekey 2026-08-07 10:24:01 +02:00
riccardom
cfea741ab4 pqkem: carry KEM offer/answer over the signalling exchange 2026-08-07 10:24:01 +02:00
riccardom
e6cc446877 pqkem: dedicated slog logger via NB_PQ_MLKEM_LOG_LEVEL 2026-08-07 10:24:01 +02:00
riccardom
09664e84aa Homogeneous logs prefix 2026-08-07 10:24:01 +02:00
riccardom
4d2037ccc9 Bit of renaming
peer -> peerAddrs
have types for remoteID and localID
t.Close log error
Manager SetTransport -> Start
2026-08-07 10:24:01 +02:00
riccardom
f0eb275575 Typo 2026-08-07 10:24:01 +02:00
riccardom
341ed699d9 Race fix 2026-08-07 10:24:01 +02:00
riccardom
11d0ad13bb Makes Transport just a UDP socket.
Manager owns maps for remoteID <-> remote UDP addr
Engine talks to manager only
2026-08-07 10:24:01 +02:00
riccardom
5d8d87c050 Adds transport 2026-08-07 10:24:01 +02:00
riccardom
b9d83de47c Communicate the port over the signal exchange 2026-08-07 10:24:01 +02:00
riccardom
5b808d1c2b Ensure iface is up and with overlay ip assigned to get a valid UDP port 2026-08-07 10:24:01 +02:00
riccardom
c5759b086d Adds real callback setter for PSK on ready 2026-08-07 10:24:01 +02:00
riccardom
f852f15e42 Initializes PQ ML-KEM manager 2026-08-07 10:24:01 +02:00
riccardom
6fc11f5fa6 Adds no-op Transports and callbacks 2026-08-07 10:24:01 +02:00
riccardom
8fa2a41888 Added enabled env var 2026-08-07 10:24:01 +02:00
riccardom
717c9297d9 Adds MLKEM Payload placeholder to client internals 2026-08-07 10:24:01 +02:00
riccardom
3059e7d141 Invert order of keys as per draft 2026-08-07 10:24:01 +02:00
riccardom
4dd8cc97c2 Protocol update 2026-08-07 10:24:01 +02:00
riccardom
551145def6 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-07 10:24:01 +02:00
riccardom
40016ae082 Leave signal offer/answer as a pull/push operation not as an actual transport 2026-08-07 10:24:01 +02:00
riccardom
9dbc7401c9 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-07 10:24:01 +02:00
riccardom
abe28c41ee Epurate wg refs 2026-08-07 10:24:01 +02:00
riccardom
56a8681b76 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-07 10:24:01 +02:00
riccardom
9c6b00125b [squash] isInitial and answered can be inferred without state variables 2026-08-07 10:24:01 +02:00
riccardom
090f97d3c4 Manages convergence 2026-08-07 10:24:01 +02:00
riccardom
b0f5731699 Models reattempts 2026-08-07 10:24:01 +02:00
riccardom
e69b9ccc18 Reuse answer, don't calculate again 2026-08-07 10:24:01 +02:00
riccardom
cb3285a79b Adds driver to glue together manager and outside world 2026-08-07 10:24:01 +02:00
riccardom
14df9d75a3 Defines event callbacks 2026-08-07 10:24:01 +02:00
riccardom
b23b757380 Admits possible errors on Encode 2026-08-07 10:24:01 +02:00
riccardom
744508f742 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-07 10:24:01 +02:00
riccardom
d808ecf8dd Pure mechanics of manager 2026-08-07 10:24:01 +02:00
riccardom
f5b350a812 Messages definition 2026-08-07 10:24:01 +02:00
riccardom
acb8970346 ML-KEM encapsulate/decapsulate module 2026-08-07 10:24:01 +02:00
riccardom
465e977ce1 Without the comment 2026-08-07 10:02:24 +02:00
riccardom
4daf7da383 [client] peer: re-arm the WireGuard watcher after a lazy wake
The Conn struct is reused across lazy-connection deactivate/activate. Close
cancels the WireGuard watcher (via wgWatcherCancel, and ctxCancel also tears
down its context) but left conn.wgWatcher pointing at the stopped instance.
enableWgWatcherIfNeeded skips while conn.wgWatcher is non-nil, so the next Open
never started a fresh watcher: once a lazy connection had idled and woken, the
peer ran with no watcher at all — no WireGuard handshake-timeout detection and
none of the escalation that depends on it.

Clear conn.wgWatcher and conn.wgWatcherCancel in Close so the next Open re-arms
a fresh watcher.
2026-08-07 09:42:27 +02:00
Viktor Liu
9a05a1c698 [client] Reword the firewalld package comment (#7081) 2026-08-06 20:36:13 +02:00
Viktor Liu
5dd914782a [client] Stop the macOS UI on pkg upgrade (#7079) 2026-08-06 16:50:17 +02:00
Ben
8c19b7a30a [infrastructure] Generate a session cookie encryption key on fresh self-hosted installs (#7056)
The community and enterprise bootstrap scripts now generate a dedicated
`server.auth.sessionCookieEncryptionKey` from 32 random bytes for fresh
installations.
The key is Base64-encoded, persisted independently from the datastore
encryption key, and reused from the generated configuration after
restarts.

The community script now also creates `config.yaml` with mode `0600`
before writing it, matching the existing enterprise behavior.

The server already supports the session cookie encryption key, but the
bootstrap scripts left it unset.
This adds defense-in-depth for newly generated deployments while
preserving the existing server-side nonce validation.
Because this only changes newly generated configuration, existing
installations and sessions are unchanged.

A focused regression test checks key presence, decoded length,
separation from the datastore key, YAML placement, and file mode for
both scripts.
It is included in the infrastructure workflow.
2026-08-06 13:55:43 +02:00
Zoltan Papp
1e2a7aa571 [client] Add a UI setting to stay connected after quitting (#7078)
Quitting the GUI from the tray always sent a Down RPC, dropping the VPN
connection with it. Some users want the connection to survive the UI.
2026-08-06 12:56:27 +02:00
Zoltan Papp
98f8a24108 [client] Ship a legacy GTK3 UI package for distros without WebKitGTK 6.0 (#7040)
Ship a legacy GTK3 UI package for distros without WebKitGTK 6.0
2026-08-06 12:13:20 +02:00