Loading src/quic.cpp +48 −0 Changes for src/quic.cpp: 48 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4892,6 +4892,20 @@ void quic::processServerHello(const std::vector<uint8_t>& msg) { // ============================================================================ void quic::parseTransportParameters(const uint8_t* data, size_t len) { // Peer's claimed original_destination_connection_id (0x00) and // retry_source_connection_id (0x10) — only meaningful coming from a // server, cross-checked against what we actually observed once parsing // finishes (RFC 9000 §7.3). initial_source_connection_id (0x0f) is // parsed for completeness but not currently cross-checked — that // would need correlating against the SCID actually seen on the wire // for each role, which isn't otherwise tracked yet; the Retry-specific // checks below are what defends against off-path Retry/version // injection, which is what this feature is actually for. std::vector<uint8_t> peer_original_dcid; bool has_peer_original_dcid = false; std::vector<uint8_t> peer_retry_scid; bool has_peer_retry_scid = false; size_t offset = 0; while (offset < len) { size_t bytes; Loading Loading @@ -4979,12 +4993,46 @@ void quic::parseTransportParameters(const uint8_t* data, size_t len) { } break; } case 0x00: { // original_destination_connection_id peer_original_dcid.assign(data + offset, data + offset + param_len); has_peer_original_dcid = true; break; } case 0x10: { // retry_source_connection_id peer_retry_scid.assign(data + offset, data + offset + param_len); has_peer_retry_scid = true; break; } default: // Skip unknown parameters break; } offset += param_len; } // RFC 9000 §7.3: a client MUST validate these against what it actually // observed — an off-path attacker forging a Retry can't also complete // the TLS handshake using keys tied to the true original DCID, but this // catches a mismatch explicitly and early rather than relying on that // alone. Servers don't receive either parameter from a real client // (only servers send them), so this only ever runs client-side. if (!_is_server) { bool mismatch = false; if (!has_peer_original_dcid || peer_original_dcid != _original_dcid) { mismatch = true; } if (_retry_received && (!has_peer_retry_scid || peer_retry_scid != _retry_scid)) { mismatch = true; } if (mismatch) { std::vector<uint8_t> close_frame = buildConnectionCloseFrame( 0x08 /* TRANSPORT_PARAMETER_ERROR */, "connection ID transport parameter mismatch"); std::vector<uint8_t> packet = buildHandshakePacket(close_frame); applyHeaderProtection(packet, EncryptionLevel::Handshake, _hs_keys.send); sendPacket(packet.data(), packet.size()); _conn_state.store(ConnectionState::Draining); } } } // ============================================================================ Loading Loading
src/quic.cpp +48 −0 Changes for src/quic.cpp: 48 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4892,6 +4892,20 @@ void quic::processServerHello(const std::vector<uint8_t>& msg) { // ============================================================================ void quic::parseTransportParameters(const uint8_t* data, size_t len) { // Peer's claimed original_destination_connection_id (0x00) and // retry_source_connection_id (0x10) — only meaningful coming from a // server, cross-checked against what we actually observed once parsing // finishes (RFC 9000 §7.3). initial_source_connection_id (0x0f) is // parsed for completeness but not currently cross-checked — that // would need correlating against the SCID actually seen on the wire // for each role, which isn't otherwise tracked yet; the Retry-specific // checks below are what defends against off-path Retry/version // injection, which is what this feature is actually for. std::vector<uint8_t> peer_original_dcid; bool has_peer_original_dcid = false; std::vector<uint8_t> peer_retry_scid; bool has_peer_retry_scid = false; size_t offset = 0; while (offset < len) { size_t bytes; Loading Loading @@ -4979,12 +4993,46 @@ void quic::parseTransportParameters(const uint8_t* data, size_t len) { } break; } case 0x00: { // original_destination_connection_id peer_original_dcid.assign(data + offset, data + offset + param_len); has_peer_original_dcid = true; break; } case 0x10: { // retry_source_connection_id peer_retry_scid.assign(data + offset, data + offset + param_len); has_peer_retry_scid = true; break; } default: // Skip unknown parameters break; } offset += param_len; } // RFC 9000 §7.3: a client MUST validate these against what it actually // observed — an off-path attacker forging a Retry can't also complete // the TLS handshake using keys tied to the true original DCID, but this // catches a mismatch explicitly and early rather than relying on that // alone. Servers don't receive either parameter from a real client // (only servers send them), so this only ever runs client-side. if (!_is_server) { bool mismatch = false; if (!has_peer_original_dcid || peer_original_dcid != _original_dcid) { mismatch = true; } if (_retry_received && (!has_peer_retry_scid || peer_retry_scid != _retry_scid)) { mismatch = true; } if (mismatch) { std::vector<uint8_t> close_frame = buildConnectionCloseFrame( 0x08 /* TRANSPORT_PARAMETER_ERROR */, "connection ID transport parameter mismatch"); std::vector<uint8_t> packet = buildHandshakePacket(close_frame); applyHeaderProtection(packet, EncryptionLevel::Handshake, _hs_keys.send); sendPacket(packet.data(), packet.size()); _conn_state.store(ConnectionState::Draining); } } } // ============================================================================ Loading