* Add KKT cryptographic primitives Post-quantum Key Encapsulation Mechanism (KEM) Key Transfer protocol. Enables efficient distribution of post-quantum KEM public keys. Squashed from georgio/noise-psq branch. * Implement LP registration protocol with KKT/PSQ integration Initial implementation of the Lewes Protocol (LP) for gateway registration: - Add nym-lp crate with Noise protocol handshake - Add LP listener to gateway for handling registrations - Add LP client for registration flow - Integrate KKT for post-quantum KEM key exchange - Integrate PSQ for post-quantum PSK derivation - Add Ed25519 authentication throughout - Add docker/localnet support for testing Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> * Add LP telescoping with nested sessions and subsession support Extends LP protocol with telescoping architecture for nested sessions: - Add nested session support with KKpsk0 rekeying - Add subsession support with collision detection - Implement unified packet format with outer header - Refactor gateway handlers for single-packet forwarding - Add TTL-based state cleanup for stale sessions - Add outer AEAD encryption layer - Refactor registration client for packet-per-connection model * Add gateway-probe localnet mode with WireGuard tunnel support Adds localnet testing mode to gateway-probe for LP development: - Add TestMode enum for different probe configurations - Add --gateway-ip flag for direct gateway testing - Implement two-hop WireGuard tunnel for localnet - Add mock ecash support for testing without real credentials - Add netstack Go bindings for userspace networking - Restructure probe with mode and common modules - Update README with localnet mode documentation * Increase KCP fragment limit from u8 to u16 - Change frg field from u8 to u16 in packet header (25 bytes total) - Update encode/decode to use get_u16_le/put_u16_le - Update Segment struct frg field to u16 - Remove truncating cast in session.rs - Max message size now ~91MB (65,535 fragments × MTU) - Internal protocol only, no interop concerns Nym uses KCP for reliability and multiplexing, not standard real-time use cases. The u8 limit (255 fragments, ~355KB) was insufficient. Addresses: nym-yih9 * Zeroize Ed25519 key material in to_x25519 conversion Wrap hash and x25519_bytes in zeroize::Zeroizing to ensure private key material is cleared from memory after use. Closes: nym-k55g * Return Result from KCP session input() for error detection Change KcpSession::input() to return Result<(), KcpError> so callers can detect invalid packets instead of silently ignoring them. - Add ConvMismatch error variant for conversation ID mismatches - Update driver to propagate errors from session.input() - Update all test and example callers Closes: nym-n0kk * Fix Zeroizing deref in ed25519 to_x25519 conversion The from_bytes() function expects &[u8], need to deref the Zeroizing wrapper to get the inner array. * Add semaphore-based connection limiting for LP packet forwarding Limits concurrent outbound connections when forwarding LP packets to prevent file descriptor exhaustion under high load. Key changes: - Add max_concurrent_forwards config (default 1000) - Add forward_semaphore to LpHandlerState - Acquire semaphore permit before connecting in handle_forward_packet - Return "Gateway at forward capacity" error when at limit This provides load signaling so clients can choose another gateway when the current one is overloaded. Design note: Connection pooling was considered but provides minimal benefit since telescope setup is one-time and targets are distributed across many different gateways. See AIDEV-NOTE in LpHandlerState for full analysis. Closes: nym-xi3m * Return error on session unavailable in handle_subsession_packet Replace .session().ok() with proper error handling to fail fast when session is Closed or Processing after state machine processing. Previously, the code silently continued with outer_key = None, which could cause protocol errors downstream. Closes: nym-8de0 * Use explicit bincode Options helper in nested_session Add bincode_options() helper that returns DefaultOptions with explicit big_endian and varint_encoding configuration. This future-proofs against bincode 1.x/2.x default changes and makes serialization format explicit. Updated all 4 bincode usages in nested_session.rs to use the helper. * Deduplicate outer_key lookup pattern in nested_session.rs Extract common state_machine.session().ok().and_then(...) pattern into two helper methods: - get_send_key() for encryption (outer_aead_key_for_sending) - get_recv_key() for decryption (outer_aead_key) Updated 6 call sites to use the helpers, reducing verbosity. * Add LpConfig struct and AIDEV-NOTE documentation for KKT+PSQ - Create config.rs with LpConfig struct (kem_algorithm, psk_ttl, enable_kkt) - Export LpConfig from lib.rs - Add AIDEV-NOTE to psk.rs explaining: - Why PSQ is embedded in Noise (single round-trip, PSK binding) - KEM migration path (X25519 → MlKem768 → XWing) - Add AIDEV-NOTE to state_machine.rs explaining protocol flow: - KKTExchange → Handshaking → Transport state transitions - PSK derivation formula (ECDH || PSQ || salt) * Add forward_timeout to LP client config Add forward_timeout (30s default) to LpConfig and wrap send_forward_packet's connect_send_receive call with tokio::time::timeout, matching the pattern used by register() with registration_timeout. This prevents indefinite hangs when forwarding packets through entry gateway. * Add negotiated_version field to LpSession Add AtomicU8 field to store the protocol version from handshake packet headers. Includes getter and setter methods for future version negotiation and compatibility checks. - negotiated_version() returns current version (defaults to 1) - set_negotiated_version() allows setting during handshake - Subsessions inherit version 1 (can be enhanced to inherit parent's) * Change MessageType from u16 to u32 Breaking wire protocol change: MessageType field increased from 2 bytes to 4 bytes in LP packets. This future-proofs the message type space and aligns with other u32 fields. Changes: - message.rs: #[repr(u32)], from_u32(), to_u32() - error.rs: InvalidMessageType(u32) - codec.rs: All serialization/deserialization updated to 4-byte msg_type - Cleartext parsing: inner_bytes[4..8], content at [8..] - AEAD parsing: decrypted[4..8], content at [8..] - Serialization: 4 bytes for message type * Various smaller fixes * Refactor LP to stream-oriented TCP processing Gateway (handler.rs): - Add bound_receiver_idx field for session-affine connections - Convert handle() from single-packet to loop with EOF detection - Add validate_or_set_binding() for receiver_idx validation - Set binding in handle_client_hello after collision check - Centralize emit_lifecycle_metrics in main loop only - Add is_connection_closed() helper for graceful EOF Client (client.rs): - Add stream field for persistent TCP connection - Add ensure_connected(), send_packet(), receive_packet(), close() methods - Modify perform_handshake_inner() to use persistent stream - Modify register_with_credential() to use persistent stream - Modify send_forward_packet() to use persistent stream - Keep connect_send_receive() for reference (marked dead_code) This reduces handshake overhead from ~5 TCP connections to 1. Drive-by: Fix log::info! -> info! in wireguard peer_controller.rs * Add persistent exit stream for entry→exit forwarding Entry gateway now maintains a persistent TCP connection to the exit gateway per client session, reusing it for all forward requests from that client. This reduces TCP handshake overhead significantly. Key changes: - Add exit_stream: Option<(TcpStream, SocketAddr)> to LpConnectionHandler - Modify handle_forward_packet() to open on first forward, reuse after - Clear exit_stream on connection errors (auto-reconnect on next forward) - Semaphore only acquired for connection opens, not reuse (sequential access) * Fix code review issues for stream-oriented LP - Add 30s timeout to exit stream I/O operations (nym-df31) Prevents handler from hanging on unresponsive exit gateway - Return error on forward target address mismatch (nym-zegu) Previously warned and proceeded, which could mask bugs - Close client stream on handshake error paths (nym-scvm) Prevents state machine inconsistency on timeout or failure * Add LP registration idempotency and retry logic Make LP registration resilient to network failures that could waste credentials. When registration succeeds on the gateway but the response is lost (e.g., network drop), clients can retry with the same WG key and get the cached result instead of spending another credential. Gateway-side: - Add check_existing_registration() helper that looks up WG peer and returns cached GatewayData if already registered - Add idempotency check in process_registration() dVPN branch - Only return cached response if bandwidth > 0 (ensures registration was actually completed, not just peer created) - Track idempotent registrations with lp_registration_dvpn_idempotent metric Client-side: - Add register_with_retry() to LpRegistrationClient that acquires credential once and retries handshake+registration on failure - Add handshake_and_register_with_retry() to NestedLpSession for exit gateway registration via forwarding - Add exponential backoff with jitter between retry attempts - Verify outer session validity before nested session retry Both retry methods clear state machine before retry to ensure fresh handshake, and reuse the same credential across all attempts. * Add no-mix-acks feature flag to nym-sphinx-framing When enabled, mix nodes skip ack extraction and forwarding entirely. The full payload (including ack portion) is returned as the message. Closes: nym-3wrr * Create nym-lp-speedtest crate scaffold - Created tools/nym-lp-speedtest/ with Cargo.toml - Added main.rs with CLI argument parsing - Created stub modules: client.rs, speedtest.rs, topology.rs - Added to workspace members - Verified compilation with cargo check * Implement topology fetching for nym-lp-speedtest - Add topology.rs with NymTopology integration - Fetch mix nodes and gateways from nym-api - Build GatewayInfo with LP addresses (port 41264) - Provide random_route_to_gateway() for Sphinx routing - Add required Cargo.toml dependencies * Implement LP+Sphinx+KCP client with SURB support - Add send_data() and send_data_with_surbs() methods for mixnet data - Integrate KCP reliable delivery with Sphinx packet construction - Add x25519 encryption keypair for SURB reply mechanism - Wire up main.rs to test LP handshake and data path - Add NymRouteProvider support in topology for SURB construction - Refactor send_data() to delegate to send_data_with_surbs(0) (DRY) The client can now: - Perform LP handshake with gateways - Send data through the mixnet wrapped in KCP + Sphinx packets - Attach SURBs for bidirectional communication - Return encryption keys for decrypting replies * Rename nym-lp-speedtest to nym-lp-client and fix KCP bug - Rename crate from nym-lp-speedtest to nym-lp-client - Fix KCP bug: add driver.update() call before fetch_outgoing() Without update(), KCP never moves segments from snd_queue to snd_buf - Update CLI name, about string, and user agent to match new name * Add LP mixnet mode registration with nym address return - Extend RegistrationMode::Mixnet to include client_ed25519_pubkey and client_x25519_pubkey for nym address construction - Add LpGatewayData struct containing gateway_identity and gateway_sphinx_key for SURB reply routing - Add lp_gateway_data field to LpRegistrationResponse for mixnet mode - Implement success_mixnet() constructor for mixnet registrations - Update gateway registration to insert clients into ActiveClientsStore for SURB reply delivery, matching the websocket flow * Implement LP data handler on UDP:51264 - Add LpDataHandler for UDP data plane (port 51264) - Decrypt LP layer and forward Sphinx packets to mixnet - Add outbound_mix_sender to LpHandlerState - Integrate data handler spawn into LpListener::run() - Add metrics for data packets received/forwarded/errors Implements nym-yzzm * Fix replay protection vulnerability in LP data handler Use state machine process_input() instead of manual decryption to ensure proper replay protection: - Counter check against receiving window - Counter marking after successful decryption Also handle subsession actions gracefully (SendPacket ignored on UDP, clients should use TCP control plane for rekeying). Security fix for nym-yzzm implementation. * feat(ipr): add KcpSessionManager for LP client KCP handling - Add fetch_incoming() and recv() methods to KcpDriver for retrieving reassembled messages - Create KcpSessionManager in ip-packet-router that manages KCP sessions keyed by conv_id (first 4 bytes of KCP packet header) - Store ReplySurbs per session for sending anonymous replies - Implement session timeout (5 min) and max sessions limit (10000) - Add comprehensive tests for session lifecycle and KCP roundtrip * feat(ipr): integrate KcpSessionManager into MixnetListener - Add KcpSessionManager field to MixnetListener struct - Add is_kcp_message() helper to detect KCP-wrapped payloads - Add on_kcp_message() to process LP client KCP messages - Refactor on_reconstructed_message() to route KCP vs regular IPR - Add KCP tick timer (100ms) for session updates and cleanup - Initialize KcpSessionManager in IpPacketRouter::run_service_provider() KCP messages are detected by checking byte 4 for valid KCP commands (81-84), which doesn't conflict with IPR protocol version bytes (6-8) at position 0. Closes: nym-96zl * fix(ipr): prevent KCP detection false positives on IPR messages Add secondary check in is_kcp_message() to exclude messages that match IPR protocol header pattern (version 6-8 at byte 0, ServiceProviderType 0-2 at byte 1). This prevents false positives where IPR messages with byte 4 in range 81-84 would be incorrectly routed to KCP processing. Added 4 unit tests to validate the detection logic. Closes: nym-6f3x * fix(ipr): wrap KCP client responses in KCP before SURB reply - Modify on_kcp_message to handle responses directly instead of returning them - Add handle_kcp_response method that wraps response in KCP and sends via mixnet - Ensures KCP clients receive KCP-wrapped responses for proper reassembly Closes: nym-7oh2 * fix(ipr): send KCP protocol packets in tick instead of just logging - Add get_sender_tag() and fetch_outgoing_for_conv() to KcpSessionManager - Change handle_kcp_tick() to actually send ACKs/retransmissions via mixnet - Reduce KCP tick interval from 100ms to 10ms for better responsiveness This fixes the KCP reliability protocol which was broken because protocol packets (ACKs, retransmissions) were generated but never sent. * feat(lp-client): wrap payload in IpPacketRequest before KCP - Add nym-ip-packet-requests and bytes dependencies - Wrap payload in IpPacketRequest::new_data_request() before sending to KCP - Add LP_DATA_PORT constant (51264) and lp_data_address field to GatewayInfo This ensures IPR can properly parse incoming messages as DataRequest. LP framing (wrapping Sphinx in LP before sending) is a separate task. * feat(lp-client): add LP session management and UDP data plane support - Add wrap_data() and session_id() to LpRegistrationClient for LP packet creation after handshake - Add init_lp_session() and close_lp_session() to SpeedtestClient for managing LP sessions - Extract prepare_sphinx_fragments() helper to reduce code duplication between send_data_with_surbs() and send_data_via_lp() - Add send_data_via_lp() for sending Sphinx packets through LP's UDP data plane (port 51264) The LP session is kept alive after TCP handshake closes, allowing subsequent wrap_data() calls for UDP transmission without re-handshaking. * random formatting * replaced all instances of bincode::serialize and bincode::deserialize with explicit lp_bincode_serialiser() within the LP * additional formatting * removed source of possible panic from nym-kkt invalid KEM mapping will now return an Err rather than panicking * integration test for LP entry registration This includes creation of mocks of various gateway-related components, such as the PeerController * changed ClientHelloData serialisation the old variant using bincode did not produce constant-length output in some cases * Fixed generation of receiver index removes the possible clash with the boostrap id * Integration test for nested LP registration - move `LpTransport` trait definition to shared `nym-lp-transport` crate - make transport layer within `LpConnectionHandler` generic with respect to the forwarding target. it must, however, use the same type as the incoming client connection - extracted explicit `LpConnectionHandler::establish_exit_stream` to more easily modify it in the future to fully protect the channel and disallow using untrusted egress points - fix additional log-string interpolation nits * resolved clippy issues pointed out by clippy 1.91 * added LP discovery into self-described endpoint: - removed changes to the node bonding within the contract - introduced '/api/v1/lewes-protocol' route within nym-node http api - added 'lewes_protocol' field to 'NymNodeData' inside of NymNodeDescription - refactored LpConfig to allow separate bind and announce addresses and used more strict typing * chore: allow unwrap/expect within kkt benchmarking code * chore: downgraded sha2 dep for cosmwasm compatibility * clippy * marking simd calls as unsafe * fixed calls to '_mm_testz_si128' * additional clippy fixes --------- Co-authored-by: Georgio Nicolas <me@georgio.xyz> Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com>
20 KiB
LP (Lewes Protocol) Security Considerations
Threat Model
Attacker Capabilities
Network Attacker (Dolev-Yao Model):
- ✅ Can observe all network traffic
- ✅ Can inject, modify, drop, or replay packets
- ✅ Can perform active MITM attacks
- ✅ Cannot break cryptographic primitives (ChaCha20, Poly1305, X25519)
- ✅ Cannot forge digital signatures (BLS12-381)
Gateway Compromise:
- ✅ Attacker gains full access to gateway server
- ✅ Can read all gateway state (keys, credentials, database)
- ✅ Can impersonate gateway to clients
- ❌ Cannot decrypt past sessions (forward secrecy)
- ❌ Cannot impersonate clients without their keys
Client Compromise:
- ✅ Attacker gains access to client device
- ✅ Can read client LP private key
- ✅ Can impersonate client to gateways
- ❌ Cannot decrypt other clients' sessions
Security Goals
Confidentiality:
- Registration requests encrypted end-to-end
- E-cash credentials protected from eavesdropping
- WireGuard keys transmitted securely
Integrity:
- All messages authenticated with Poly1305 MAC
- Tampering detected and rejected
- Replay attacks prevented
Authentication:
- Mutual authentication via Noise XKpsk3
- Gateway proves possession of LP private key
- Client proves possession of LP private key + PSK
Forward Secrecy:
- Compromise of long-term keys doesn't reveal past sessions
- Ephemeral keys provide PFS
- Session keys destroyed after use
Non-Goals:
- Network anonymity: LP reveals client IP to gateway (use mixnet for anonymity)
- Traffic analysis resistance: Packet timing visible to network observer
- Deniability: Parties can prove who they communicated with
Cryptographic Design
Noise Protocol XKpsk3
Pattern:
XKpsk3:
<- s
...
-> e
<- e, ee, s, es
-> s, se, psk
Security Properties:
| Property | Provided | Rationale |
|---|---|---|
| Confidentiality (forward) | ✅ Strong | Ephemeral keys + PSK |
| Confidentiality (backward) | ✅ Weak | PSK compromise affects future |
| Authentication (initiator) | ✅ Strong | Static key + PSK |
| Authentication (responder) | ✅ Strong | Static key known upfront |
| Identity hiding (initiator) | ✅ Yes | Static key encrypted |
| Identity hiding (responder) | ❌ No | Static key in handshake msg 2 |
Why XKpsk3:
- Known responder identity: Client knows gateway's LP public key from descriptor
- Mutual authentication: Both sides prove identity
- PSK binding: Links session to out-of-band PSK (prevents MITM with compromised static key alone)
- Forward secrecy: Ephemeral keys provide PFS even if static keys leaked
Alternative patterns considered:
- IKpsk2: No forward secrecy (rejected)
- XXpsk3: More round trips, unknown identities (not needed)
- NKpsk0: No client authentication (rejected)
PSK Derivation Security
Formula:
shared_secret = X25519(client_lp_private, gateway_lp_public)
psk = Blake3_derive_key("nym-lp-psk-v1", shared_secret, salt)
Security Analysis:
-
ECDH Security: Based on Curve25519 hardness (128-bit security)
- Resistant to quantum attacks up to Grover's algorithm (64-bit post-quantum)
- Well-studied, no known vulnerabilities
-
Blake3 KDF Security:
- Output indistinguishable from random (PRF security)
- Domain separation via context string prevents cross-protocol attacks
- Collision resistance: 128 bits (birthday bound on 256-bit hash)
-
Salt Freshness:
- Timestamp component prevents long-term PSK reuse
- Nonce component provides per-session uniqueness
- Both transmitted in ClientHello (integrity protected by timestamp validation + Noise handshake)
Attack Scenarios:
| Attack | Feasibility | Mitigation |
|---|---|---|
| Brute force PSK | ❌ Infeasible | 2^128 operations (Curve25519 DL) |
| Quantum attack on ECDH | ⚠️ Future threat | Shor's algorithm breaks X25519 in polynomial time |
| Salt replay | ❌ Prevented | Timestamp validation (30s window) |
| Cross-protocol PSK reuse | ❌ Prevented | Domain separation ("nym-lp-psk-v1") |
Quantum Resistance:
LP is not quantum-resistant due to X25519 use. Future upgrade path:
// Hybrid PQ-KEM (future)
let classical_secret = X25519(client_priv, gateway_pub);
let pq_secret = Kyber768::encaps(gateway_pq_pub);
let psk = Blake3_derive_key(
"nym-lp-psk-v2-pq",
classical_secret || pq_secret,
salt
);
Replay Protection Analysis
Algorithm: Sliding Window with Bitmap
Window size: 1024 packets
Bitmap: [u64; 16] = 1024 bits
For counter C:
- Accept if C >= next (new packet)
- Reject if C + 1024 < next (too old)
- Reject if bitmap[C % 1024] == 1 (duplicate)
- Otherwise accept and mark
Security Properties:
-
Replay Window: 1024 packets
- Sufficient for expected reordering in TCP+KCP
- Small enough to limit replay attack surface
-
Memory Efficiency: 128 bytes bitmap
- Tracks 1024 unique counters
- O(1) lookup and insertion
-
Overflow Handling: Wraps at u64::MAX
- Properly handles counter wraparound
- Unlikely to occur (2^64 packets = trillions)
Attack Scenarios:
| Attack | Feasibility | Mitigation |
|---|---|---|
| Replay within window | ❌ Prevented | Bitmap tracking |
| Replay outside window | ❌ Prevented | Window boundary check |
| Counter overflow | ⚠️ Theoretical | Wraparound handling + 2^64 limit |
| Timing attack | ❌ Mitigated | Branchless execution |
Timing Attack Resistance:
// Constant-time check (branchless)
pub fn will_accept_branchless(&self, counter: u64) -> ReplayResult<()> {
let is_growing = counter >= self.next;
let too_far_back = /* calculated */;
let duplicate = self.check_bit_branchless(counter);
// Single branch at end (constant-time up to this point)
let result = if is_growing { Ok(()) }
else if too_far_back { Err(OutOfWindow) }
else if duplicate { Err(Duplicate) }
else { Ok(()) };
result.unwrap()
}
SIMD Optimizations:
- AVX2, SSE2, NEON: SIMD clears are constant-time
- Scalar fallback: Also constant-time (no data-dependent branches)
- No timing channels revealed through replay check
Denial of Service (DoS) Protection
Connection-Level DoS
Attack: Flood gateway with TCP connections
Mitigations:
-
Max connections limit (default: 10,000):
if active_connections >= max_connections { return; // Drop new connection }- Prevents memory exhaustion (~5 KB per connection)
- Configurable based on gateway capacity
-
TCP SYN cookies (kernel-level):
sysctl -w net.ipv4.tcp_syncookies=1- Prevents SYN flood attacks
- No state allocated until 3-way handshake completes
-
Connection rate limiting (iptables):
iptables -A INPUT -p tcp --dport 41264 -m state --state NEW \ -m recent --update --seconds 60 --hitcount 100 -j DROP- Limits new connections per IP
- 100 connections/minute threshold
Residual Risk:
- ⚠️ No per-IP limit in application: Current implementation only has global limit
- Recommendation: Add per-IP tracking:
let connections_from_ip = ip_tracker.get(remote_addr.ip()); if connections_from_ip >= per_ip_limit { return; // Reject }
Handshake-Level DoS
Attack: Start handshakes but never complete them
Mitigations:
-
Handshake timeout: Noise state machine times out
- Implementation: Tokio task timeout (implicit)
- Recommended: Explicit 15-second timeout
-
State cleanup: Connection dropped if handshake fails
if handshake_fails { drop(connection); // Frees memory immediately } -
No resource allocation before handshake:
- Replay validator created only after handshake
- Minimal memory usage during handshake (~200 bytes)
Attack Scenarios:
| Attack | Resource Consumed | Mitigation |
|---|---|---|
| Half-open connections | TCP state (~4 KB) | SYN cookies |
| Incomplete handshakes | Noise state (~200 B) | Timeout + cleanup |
| Slow clients | Connection slot | Timeout + max connections |
Timestamp-Based DoS
Attack: Replay old ClientHello messages
Mitigation:
let timestamp_age = now - client_hello.timestamp;
if timestamp_age > 30_seconds {
return Err(TimestampTooOld);
}
if timestamp_age < -30_seconds {
return Err(TimestampFromFuture);
}
Properties:
- 30-second window limits replay attack surface
- Clock skew tolerance: ±30 seconds (reasonable for NTP)
- Metrics track rejections:
lp_timestamp_validation_rejected
Residual Risk:
- ⚠️ 30-second window allows replay of ClientHello within window
- Mitigation: Replay protection on post-handshake messages
Credential Verification DoS
Attack: Flood gateway with fake credentials
Mitigations:
-
Fast rejection path:
// Check signature before database lookup if !verify_bls_signature(&credential) { return Err(InvalidSignature); // Fast path } // Only then check database -
Database indexing:
CREATE INDEX idx_nullifiers ON spent_credentials(nullifier);- O(log n) nullifier lookup instead of O(n)
-
Rate limiting (future):
- Limit credential verification attempts per IP
- Exponential backoff for repeated failures
Performance Impact:
- BLS signature verification: ~5ms per credential
- Database lookup: ~1ms (with index)
- Total: ~6ms per invalid credential
Attack Cost:
- Attacker must generate BLS signatures (computationally expensive)
- Invalid signatures rejected before database query
- Real cost is in valid-looking but fake credentials (still requires crypto)
Threat Scenarios
Scenario 1: Passive Eavesdropper
Attacker: Network observer (ISP, hostile network)
Capabilities:
- Observe all LP traffic (including ClientHello)
- Analyze packet sizes, timing, patterns
Protections:
- ✅ ClientHello metadata visible but not sensitive (timestamp, nonce)
- ✅ Noise handshake encrypts all subsequent messages
- ✅ Registration request fully encrypted (credential not visible)
- ✅ ChaCha20-Poly1305 provides IND-CCA2 security
Leakage:
- ⚠️ Client IP address visible (inherent to TCP)
- ⚠️ Packet timing reveals registration events
- ⚠️ Connection to known gateway suggests Nym usage
Recommendation: Use LP for fast registration, mixnet for anonymity-critical operations.
Scenario 2: Active MITM
Attacker: On-path adversary (malicious router, hostile WiFi)
Capabilities:
- Intercept, modify, drop, inject packets
- Cannot break cryptography
Protections:
- ✅ Noise XKpsk3 mutual authentication prevents impersonation
- ✅ Client verifies gateway's LP static public key
- ✅ Gateway verifies client via PSK derivation
- ✅ Any packet modification detected via Poly1305 MAC
Attack Attempts:
-
Impersonate Gateway:
- Attacker doesn't have gateway's LP private key
- Cannot complete handshake (Noise fails at
esmix) - Client rejects connection
-
Impersonate Client:
- Attacker doesn't know client's LP private key
- Cannot derive correct PSK
- Noise fails at
pskmix in message 3 - Gateway rejects connection
-
Modify Messages:
- Poly1305 MAC fails
- Noise decryption fails
- Connection aborted
Residual Risk:
- ⚠️ DoS possible (drop packets, connection killed)
- ✅ Cannot learn registration data or credentials
Scenario 3: Gateway Compromise
Attacker: Full access to gateway server
Capabilities:
- Read all gateway state (keys, database, memory)
- Modify gateway behavior
- Impersonate gateway to clients
Impact:
-
Current Sessions: Compromised
- Attacker can decrypt ongoing registration requests
- Can steal credentials from current sessions
-
Past Sessions: Protected (forward secrecy)
- Ephemeral keys already destroyed
- Cannot decrypt recorded traffic
-
Future Sessions: Compromised until key rotation
- Attacker can impersonate gateway
- Can steal credentials from new registrations
Mitigations:
-
Key Rotation:
# Generate new LP keypair ./nym-node generate-lp-keypair # Update gateway descriptor (automatic on restart)- Invalidates attacker's stolen keys
- Clients fetch new public key from descriptor
-
Monitoring:
- Detect anomalous credential verification patterns
- Alert on unusual database access
- Monitor for key file modifications
-
Defense in Depth:
- E-cash credentials have limited value (time-bound, nullifiers)
- WireGuard keys rotatable by client
- No long-term sensitive data stored
Credential Reuse Prevention:
- Nullifier stored in database
- Nullifier = Hash(credential_data)
- Even with database access, attacker cannot create new credentials
- Can only steal credentials submitted during compromise window
Scenario 4: Replay Attack
Attacker: Records past LP sessions, replays later
Attack Attempts:
-
Replay ClientHello:
- Timestamp validation rejects messages > 30s old
- Nonce in salt changes per session
- Cannot reuse old ClientHello
-
Replay Handshake Messages:
- Noise uses ephemeral keys (fresh each session)
- Replaying old handshake messages fails (wrong ephemeral key)
- Handshake fails, no session established
-
Replay Post-Handshake Packets:
- Counter-based replay protection
- Bitmap tracks last 1024 packets
- Duplicate counters rejected
- Cannot replay old encrypted messages
-
Replay Entire Session:
- Different ephemeral keys each time
- Cannot replay connection to gateway
- Even if gateway state reset, timestamp rejects old ClientHello
Success Probability: Negligible (< 2^-128)
Scenario 5: Quantum Adversary (Future)
Attacker: Quantum computer with Shor's algorithm
Capabilities:
- Break X25519 ECDH in polynomial time
- Recover LP static private keys from public keys
- Does NOT break symmetric crypto (ChaCha20, Blake3)
Impact:
-
Recorded Traffic: Vulnerable
- Attacker records all LP traffic now
- Breaks X25519 later with quantum computer
- Recovers PSKs from recorded ClientHellos
- Decrypts recorded sessions
-
Real-Time Interception: Full compromise
- Can impersonate gateway (knows private key)
- Can decrypt all traffic
- Complete MITM attack
Mitigations (Future):
-
Hybrid PQ-KEM:
// Use both classical and post-quantum KEM let classical = X25519(client_priv, gateway_pub); let pq = Kyber768::encaps(gateway_pq_pub); let psk = Blake3(classical || pq, salt); -
Post-Quantum Noise:
- Noise specification supports PQ KEMs
- Can upgrade to Kyber, NTRU, or SIKE
- Requires protocol version 2
Timeline:
- Quantum threat: ~10-20 years away
- PQ upgrade: Can be deployed when threat becomes real
- Backward compatibility: Support both classical and PQ
Security Recommendations
For Gateway Operators
High Priority:
-
Enable all DoS protections:
[lp] max_connections = 10000 # Adjust based on capacity timestamp_tolerance_secs = 30 # Don't increase unnecessarily -
Secure key storage:
chmod 600 ~/.nym/gateways/<id>/keys/lp_x25519.pem # Encrypt disk if possible -
Monitor metrics:
- Alert on high
lp_handshakes_failed - Alert on unusual
lp_timestamp_validation_rejected - Track
lp_credential_verification_failedpatterns
- Alert on high
-
Keep database secure:
- Regular backups
- Index on
nullifiercolumn - Periodic cleanup of old nullifiers
Medium Priority:
-
Implement per-IP rate limiting (future):
const MAX_CONNECTIONS_PER_IP: usize = 10; -
Regular key rotation:
- Rotate LP keypair every 6-12 months
- Coordinate with network updates
-
Firewall hardening:
# Only allow LP port ufw default deny incoming ufw allow 41264/tcp
For Client Developers
High Priority:
-
Verify gateway LP public key:
// Fetch from trusted source (network descriptor) let gateway_lp_pubkey = fetch_gateway_descriptor(gateway_id) .await? .lp_public_key; // Pin for future connections save_pinned_key(gateway_id, gateway_lp_pubkey); -
Handle errors securely:
match registration_result { Err(LpError::Replay(_)) => { // DO NOT retry immediately (might be replay attack) log::warn!("Replay detected, waiting before retry"); tokio::time::sleep(Duration::from_secs(60)).await; } Err(e) => { // Other errors safe to retry } } -
Use fresh credentials:
- Don't reuse credentials across registrations
- Check credential expiry before attempting registration
Medium Priority:
-
Implement connection timeout:
tokio::time::timeout( Duration::from_secs(30), registration_client.register_lp(...) ).await? -
Secure local key storage:
- Use OS keychain for LP private keys
- Don't log or expose keys
For Network Operators
High Priority:
-
Deploy monitoring infrastructure:
- Prometheus + Grafana for metrics
- Alerting on security-relevant metrics
- Correlation of events across gateways
-
Incident response plan:
- Procedure for gateway compromise
- Key rotation workflow
- Client notification mechanism
-
Regular security audits:
- External audit of Noise implementation
- Penetration testing of LP endpoints
- Review of credential verification logic
Medium Priority:
- Threat intelligence:
- Monitor for known attacks on Noise protocol
- Track quantum computing advances
- Plan PQ migration timeline
Compliance Considerations
Data Protection (GDPR, etc.)
Personal Data Collected:
- Client IP address (connection metadata)
- Credential nullifiers (pseudonymous identifiers)
- Timestamps (connection events)
Data Retention:
- IP addresses: Not stored beyond connection duration
- Nullifiers: Stored until credential expiry + grace period
- Logs: Configurable retention (default: 7 days)
Privacy Protections:
- Nullifiers pseudonymous (not linkable to real identity)
- No PII collected or stored
- Credentials use blind signatures (gateway doesn't learn identity)
Security Compliance
SOC 2 / ISO 27001 Requirements:
-
Access Control:
- LP keys protected (file permissions)
- Database access restricted
- Principle of least privilege
-
Encryption in Transit:
- Noise protocol provides end-to-end encryption
- TLS for metrics endpoint (if exposed)
-
Logging and Monitoring:
- Security events logged
- Metrics for anomaly detection
- Audit trail for credential usage
-
Incident Response:
- Key rotation procedure
- Backup and recovery
- Communication plan
Audit Checklist
Before production deployment:
- Noise implementation reviewed by cryptographer
- Replay protection tested with edge cases (overflow, concurrency)
- DoS limits tested (connection flood, credential spam)
- Timing attack resistance verified (replay check, credential verification)
- Key storage secured (file permissions, encryption at rest)
- Monitoring and alerting configured
- Incident response plan documented
- Penetration testing performed
- Code review completed
- Dependencies audited (cargo-audit, cargo-deny)
References
Security Specifications
- Noise Protocol Framework: https://noiseprotocol.org/
- XKpsk3 Analysis: https://noiseexplorer.com/patterns/XKpsk3/
- Curve25519: https://cr.yp.to/ecdh.html
- ChaCha20-Poly1305: RFC 8439
- Blake3: https://github.com/BLAKE3-team/BLAKE3-specs
Security Audits
- Noise implementation audit (pending)
- Cryptographic review (pending)
- Penetration test report (pending)
Known Vulnerabilities
None currently identified. This section will be updated as issues are discovered.
Responsible Disclosure
If you discover a security vulnerability in LP:
- DO NOT publish vulnerability details publicly
- Email security@nymtech.net with:
- Description of vulnerability
- Steps to reproduce
- Potential impact
- Suggested mitigation (if any)
- Allow 90 days for patch development before public disclosure
- Coordinate disclosure timeline with Nym team
Bug Bounty: Check https://nymtech.net/security for current bounty program.