Loading src/quic.cpp +31 −0 Changes for src/quic.cpp: 31 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -290,6 +290,20 @@ ssize_t quic::sendPacket(const uint8_t* data, size_t len) { QUIC_DBG("sendPacket: _Socket < 0, dropping %zu bytes", len); return -1; } // RFC 9000 §8.1 anti-amplification limit: until the peer's address is // validated, never send more than 3x what's been received from it. // Known consequence (not something this checks tries to work around): // a large enough handshake flight (e.g. an oversized certificate // chain) may need more than one round trip to complete under strict // enforcement — see _address_validated's comment in socket.h. if (!_address_validated && _bytes_sent_unvalidated + len > 3 * _bytes_received_unvalidated) { QUIC_DBG("sendPacket: anti-amplification limit reached, dropping %zu bytes " "(sent=%lu recv=%lu)", len, (unsigned long)_bytes_sent_unvalidated, (unsigned long)_bytes_received_unvalidated); return -1; } QUIC_DBG("sendPacket: len=%zu parent=%p _Socket=%d", len, (void*)_parent, _Socket); for (int attempt = 0; attempt < 5; ++attempt) { Loading @@ -308,6 +322,7 @@ ssize_t quic::sendPacket(const uint8_t* data, size_t len) { QUIC_DBG("sendPacket: sent=%zu", sent); if (sent > 0) { _last_activity = std::chrono::steady_clock::now(); if (!_address_validated) _bytes_sent_unvalidated += sent; } return static_cast<ssize_t>(sent); } catch (NetException& e) { Loading Loading @@ -1946,6 +1961,11 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) { // own DCID field) is exactly right here. child_ptr->_retry_scid = dcid; } // A child is only ever created after validateToken() already proved // address ownership (see the Retry gate above) — RFC 9000 §8.1 lists // "the client returns a valid... token" as a validation trigger in its // own right, independent of Retry vs NEW_TOKEN. child_ptr->_address_validated = true; child_ptr->_cert_map = _cert_map; // Copy certificate configuration child_ptr->_parent = this; // Link to parent for routing child_ptr->_stream_callback = _stream_callback; // Copy stream callback Loading Loading @@ -2097,6 +2117,12 @@ void quic::processIncomingPacket(const uint8_t* data, size_t len) { if (len < 1) return; QUIC_DBG("processIncomingPacket: len=%zu first_byte=0x%02x", len, data[0]); // Anti-amplification accounting (RFC 9000 §8.1) — see sendPacket()'s // enforcement and _address_validated's comment in socket.h. Counts the // whole received datagram, matching how sendPacket() counts whole // sent datagrams; once validated, this becomes a no-op. if (!_address_validated) _bytes_received_unvalidated += len; // Process coalesced packets by parsing each one's length and processing size_t offset = 0; while (offset < len) { Loading Loading @@ -2422,6 +2448,11 @@ void quic::processHandshakePacket(const uint8_t* data, size_t len) { } QUIC_DBG("processHandshakePacket: decrypt OK pn=%lu payload=%zu", (unsigned long)pn, payload.size()); // RFC 9000 §8.1: successfully processing a Handshake-space packet is // itself a validation trigger, independent of Retry/NEW_TOKEN — only // the genuine peer could have derived Handshake keys to produce this. _address_validated = true; if (pn > _handshake_pn_recv) { _handshake_pn_recv = pn; Loading src/socket.h +17 −0 Changes for src/socket.h: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1021,6 +1021,23 @@ namespace netplus { // computed over. std::vector<uint8_t> _initial_crypto_frame; // Anti-amplification limit (RFC 9000 §8.1): until the peer's // address is validated, this endpoint must never send more than // 3x the bytes it has received from that address — otherwise it // could be used to amplify traffic toward a spoofed victim. Under // this library's always-Retry server policy, _address_validated is // set true at child-connection creation (a child is only ever // created once a valid token has already proven address // ownership), so the gate is open from birth for every connection // today — that's correct, not dead code: it's what makes a future // "make Retry conditional" policy safe without further changes, // and it still guards Initial/Handshake-space traffic in general // (e.g. also flips true on successfully processing a Handshake // packet, RFC 9000 §8.1's other validation trigger). bool _address_validated = false; uint64_t _bytes_sent_unvalidated = 0; uint64_t _bytes_received_unvalidated = 0; // Packet numbers (per packet number space) uint64_t _initial_pn_send = 0; uint64_t _initial_pn_recv = 0; Loading Loading
src/quic.cpp +31 −0 Changes for src/quic.cpp: 31 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -290,6 +290,20 @@ ssize_t quic::sendPacket(const uint8_t* data, size_t len) { QUIC_DBG("sendPacket: _Socket < 0, dropping %zu bytes", len); return -1; } // RFC 9000 §8.1 anti-amplification limit: until the peer's address is // validated, never send more than 3x what's been received from it. // Known consequence (not something this checks tries to work around): // a large enough handshake flight (e.g. an oversized certificate // chain) may need more than one round trip to complete under strict // enforcement — see _address_validated's comment in socket.h. if (!_address_validated && _bytes_sent_unvalidated + len > 3 * _bytes_received_unvalidated) { QUIC_DBG("sendPacket: anti-amplification limit reached, dropping %zu bytes " "(sent=%lu recv=%lu)", len, (unsigned long)_bytes_sent_unvalidated, (unsigned long)_bytes_received_unvalidated); return -1; } QUIC_DBG("sendPacket: len=%zu parent=%p _Socket=%d", len, (void*)_parent, _Socket); for (int attempt = 0; attempt < 5; ++attempt) { Loading @@ -308,6 +322,7 @@ ssize_t quic::sendPacket(const uint8_t* data, size_t len) { QUIC_DBG("sendPacket: sent=%zu", sent); if (sent > 0) { _last_activity = std::chrono::steady_clock::now(); if (!_address_validated) _bytes_sent_unvalidated += sent; } return static_cast<ssize_t>(sent); } catch (NetException& e) { Loading Loading @@ -1946,6 +1961,11 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) { // own DCID field) is exactly right here. child_ptr->_retry_scid = dcid; } // A child is only ever created after validateToken() already proved // address ownership (see the Retry gate above) — RFC 9000 §8.1 lists // "the client returns a valid... token" as a validation trigger in its // own right, independent of Retry vs NEW_TOKEN. child_ptr->_address_validated = true; child_ptr->_cert_map = _cert_map; // Copy certificate configuration child_ptr->_parent = this; // Link to parent for routing child_ptr->_stream_callback = _stream_callback; // Copy stream callback Loading Loading @@ -2097,6 +2117,12 @@ void quic::processIncomingPacket(const uint8_t* data, size_t len) { if (len < 1) return; QUIC_DBG("processIncomingPacket: len=%zu first_byte=0x%02x", len, data[0]); // Anti-amplification accounting (RFC 9000 §8.1) — see sendPacket()'s // enforcement and _address_validated's comment in socket.h. Counts the // whole received datagram, matching how sendPacket() counts whole // sent datagrams; once validated, this becomes a no-op. if (!_address_validated) _bytes_received_unvalidated += len; // Process coalesced packets by parsing each one's length and processing size_t offset = 0; while (offset < len) { Loading Loading @@ -2422,6 +2448,11 @@ void quic::processHandshakePacket(const uint8_t* data, size_t len) { } QUIC_DBG("processHandshakePacket: decrypt OK pn=%lu payload=%zu", (unsigned long)pn, payload.size()); // RFC 9000 §8.1: successfully processing a Handshake-space packet is // itself a validation trigger, independent of Retry/NEW_TOKEN — only // the genuine peer could have derived Handshake keys to produce this. _address_validated = true; if (pn > _handshake_pn_recv) { _handshake_pn_recv = pn; Loading
src/socket.h +17 −0 Changes for src/socket.h: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1021,6 +1021,23 @@ namespace netplus { // computed over. std::vector<uint8_t> _initial_crypto_frame; // Anti-amplification limit (RFC 9000 §8.1): until the peer's // address is validated, this endpoint must never send more than // 3x the bytes it has received from that address — otherwise it // could be used to amplify traffic toward a spoofed victim. Under // this library's always-Retry server policy, _address_validated is // set true at child-connection creation (a child is only ever // created once a valid token has already proven address // ownership), so the gate is open from birth for every connection // today — that's correct, not dead code: it's what makes a future // "make Retry conditional" policy safe without further changes, // and it still guards Initial/Handshake-space traffic in general // (e.g. also flips true on successfully processing a Handshake // packet, RFC 9000 §8.1's other validation trigger). bool _address_validated = false; uint64_t _bytes_sent_unvalidated = 0; uint64_t _bytes_received_unvalidated = 0; // Packet numbers (per packet number space) uint64_t _initial_pn_send = 0; uint64_t _initial_pn_recv = 0; Loading