Commit 7d83aa3c authored by jan.koester's avatar jan.koester
Browse files

test

parent e00f3a6e
Loading
Loading
Loading
Loading
+40 −1
Changes for src/quic.cpp: 40 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3699,13 +3699,24 @@ void quic::processFrame(const uint8_t* data, size_t len, size_t& offset, bool& a

        case 0x07:  // NEW_TOKEN
            {
                // RFC 9000 §19.7: only a server ever sends this; a server
                // receiving one from a client is a protocol violation.
                if (_is_server) {
                    abortFrameParsing(len, offset, 0x0A /* PROTOCOL_VIOLATION */,
                                       "server received NEW_TOKEN");
                    return;
                }
                uint64_t token_len;
                if (!readVarInt(token_len)) return;
                if (token_len > len - offset) {
                    abortFrameParsing(len, offset, 0x01, "NEW_TOKEN length exceeds packet");
                    return;
                }
                offset += token_len;  // Skip token data
                // Retained for getStoredToken() — an application can pull
                // this out and feed it into a future connection's
                // setToken() to skip Retry on that later attempt.
                _received_new_token.assign(&data[offset], &data[offset] + token_len);
                offset += token_len;
            }
            break;

@@ -5357,12 +5368,40 @@ void quic::sendHandshakeDone() {
        sendPacket(packet.data(), packet.size());
    }

    // Let this client skip Retry on a future reconnect (RFC 9000 §8.1.3) —
    // it already proved address ownership for *this* connection.
    sendNewTokenFrame();

    // If ALPN is HTTP/3, send the mandatory control streams (RFC 9114 §6.2.1)
    if (_selected_alpn == "h3" || _selected_alpn == "h3-29") {
        sendHttp3ControlStreams();
    }
}

// ============================================================================
// QUIC: Send NEW_TOKEN frame (Server only, RFC 9000 §8.1.3)
// ============================================================================

void quic::sendNewTokenFrame() {
    if (!_is_server) return;

    std::vector<uint8_t> token = generateToken(false, {}, _Addr, _AddrLen);
    if (token.empty()) return; // unsupported peer address family

    std::vector<uint8_t> frame;
    frame.push_back(0x07); // NEW_TOKEN frame type
    uint8_t len_buf[8];
    size_t len_size = encodeVarInt(token.size(), len_buf);
    frame.insert(frame.end(), len_buf, len_buf + len_size);
    frame.insert(frame.end(), token.begin(), token.end());

    std::vector<uint8_t> packet = buildShortHeaderPacket(frame);
    applyHeaderProtection(packet, EncryptionLevel::Application, _app_keys.send);
    if (_Socket >= 0) {
        sendPacket(packet.data(), packet.size());
    }
}

// ============================================================================
// HTTP/3: Send mandatory control streams (RFC 9114 §6.2.1)
// ============================================================================