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

test

parent b50a81eb
Loading
Loading
Loading
Loading
+14 −3
Changes for src/quic.cpp: 14 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2509,10 +2509,14 @@ std::vector<uint8_t> quic::buildInitialPacket(const std::vector<uint8_t>& payloa
    header.push_back(static_cast<uint8_t>(_local_cid.size()));
    header.insert(header.end(), _local_cid.begin(), _local_cid.end());
    
    // Token length (0 for client Initial, may be non-zero after Retry)
    // Token: empty for a server's own Initial and for a client's very
    // first attempt; non-empty when _pending_token was set via setToken()
    // (a retained NEW_TOKEN from a prior connection) or by
    // processRetryPacket() (echoing what a Retry just gave us).
    uint8_t tok_len_buf[8];
    size_t tok_len_size = encodeVarInt(0, tok_len_buf);  // No token
    size_t tok_len_size = encodeVarInt(_pending_token.size(), tok_len_buf);
    header.insert(header.end(), tok_len_buf, tok_len_buf + tok_len_size);
    header.insert(header.end(), _pending_token.begin(), _pending_token.end());
    
    // Calculate total length (PN + payload + AEAD tag)
    size_t total_len = pn_len + payload.size() + 16;  // 16-byte AEAD tag
@@ -2684,7 +2688,14 @@ void quic::connect(const std::string& addr, int port, bool nonblock) {
        crypto_frame.push_back(0x00);  // PADDING frame
    }

    // Build Initial packet
    // Retained so processRetryPacket()'s resend (if a Retry arrives) can
    // reuse these exact bytes instead of rebuilding the ClientHello — see
    // _initial_crypto_frame's comment in socket.h.
    _initial_crypto_frame = crypto_frame;

    // Build Initial packet. _pending_token is empty unless the caller
    // supplied one via setToken() before connect() (a token retained from a
    // previous connection's NEW_TOKEN, letting this attempt skip Retry).
    std::vector<uint8_t> packet = buildInitialPacket(crypto_frame);

    // Apply header protection
+21 −0
Changes for src/socket.h: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -968,8 +968,29 @@ namespace netplus {
		std::vector<uint8_t> _local_cid;
		std::vector<uint8_t> _remote_cid;
		std::vector<uint8_t> _original_dcid;
		// Retry-exchange CID, meaning depends on role: client-side, the
		// SCID it read off the actual Retry packet (kept to cross-check
		// against the server's later-echoed retry_source_connection_id
		// transport parameter, RFC 9000 §7.3); server-side (child
		// connection), the DCID field of the retried Initial that created
		// it — which is exactly the SCID this server put on its own Retry
		// packet, since the client always echoes whatever CID it was last
		// told to use as destination. Used to build that same transport
		// parameter server-side. Empty when no Retry occurred.
		std::vector<uint8_t> _retry_scid;

		// Client-only Retry/NEW_TOKEN state.
		std::vector<uint8_t> _pending_token;      // echoed in the next Initial's token field
		std::vector<uint8_t> _received_new_token; // last NEW_TOKEN frame payload, for getStoredToken()
		bool _retry_received = false;             // RFC 9000 §17.2.5.2: discard a second Retry
		// Padded CRYPTO-frame bytes from the very first Initial, retained
		// so a post-Retry resend can reuse them verbatim instead of
		// rebuilding the ClientHello — rebuilding would re-append to
		// _tls_transcript and regenerate the client random/ECDHE keypair,
		// corrupting the transcript hash the eventual Finished message is
		// computed over.
		std::vector<uint8_t> _initial_crypto_frame;

		// Packet numbers (per packet number space)
		uint64_t _initial_pn_send = 0;
		uint64_t _initial_pn_recv = 0;