Commit 04873698 authored by jan.koester's avatar jan.koester
Browse files

test

parent 3d60937d
Loading
Loading
Loading
Loading
+42 −2
Changes for src/socket.h: 42 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -894,8 +894,35 @@ namespace netplus {
		void processApplicationPacketsBatch(
			const std::vector<std::pair<const uint8_t*, size_t>>& packets);

		// Retry token validation
		bool validateRetryToken(const std::vector<uint8_t>& token);
		// Retry/NEW_TOKEN address-validation tokens (RFC 9000 §8.1). Both
		// token kinds share one AEAD-sealed wire format and this one
		// generate/validate pair — see generateToken()'s definition for the
		// exact layout. `original_dcid` is only meaningful when `is_retry`:
		// it's the client's *original* (pre-Retry) DCID, needed so Initial
		// key derivation and the original_destination_connection_id
		// transport parameter stay correct across the Retry round trip
		// (RFC 9001 §5.2 derives Initial keys from the client's *first*
		// Initial packet's DCID, which is not the same as the DCID field of
		// the retried Initial that carries this token).
		struct ParsedToken {
			bool valid = false;
			bool is_retry = false;
			std::vector<uint8_t> original_dcid;
		};
		std::vector<uint8_t> generateToken(bool is_retry, const std::vector<uint8_t>& original_dcid,
		                                    const sockaddr_storage& peer_addr, socklen_t peer_len) const;
		ParsedToken validateToken(const std::vector<uint8_t>& token,
		                          const sockaddr_storage& peer_addr, socklen_t peer_len) const;

		// RFC 9001 §5.8 Retry Integrity Tag: fixed, RFC-specified key/nonce
		// (public, not secret — authenticates packet *format*, not origin;
		// real protection comes from the token above plus the transport
		// parameter cross-check). Computed identically on both ends
		// (server building a Retry, client verifying one), so this needs no
		// connection state beyond what's passed in.
		static std::array<uint8_t, 16> computeRetryIntegrityTag(
			const std::vector<uint8_t>& original_dcid,
			const uint8_t* header_and_token, size_t header_and_token_len);

		// TLS 1.3 handshake integration
		void processClientHello(const std::vector<uint8_t>& data);
@@ -1064,6 +1091,19 @@ namespace netplus {
		std::map<std::string, ssl::CertificateBundle> _cert_map;
		ssl::CertificateBundle* _selected_cert = nullptr;

		// Secret backing Retry/NEW_TOKEN address-validation tokens (RFC
		// 9000 §8.1) — 32 random bytes, generated once per listener at
		// construction. Lives only on the listener; child connections
		// reach it via _parent (same `_parent ? _parent : this` idiom
		// pumpIncoming() already uses), since a child needs it to issue a
		// NEW_TOKEN after its own handshake completes, and the listener
		// needs it in accept() to build/validate tokens before any child
		// exists yet. No rotation: a process restart invalidates
		// outstanding tokens, which just costs affected clients one extra
		// Retry round trip — acceptable, and simpler than the alternative
		// of persisting/rotating a secret across restarts.
		std::vector<uint8_t> _token_secret;

		// Mutex for this connection's own state (recursive: musl returns
		// EDEADLK on double-lock by same thread, which happens when
		// processFrame callbacks re-enter locking functions like