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

test

parent 944536f4
Loading
Loading
Loading
Loading
+41 −14
Changes for src/quic.cpp: 41 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -7071,10 +7071,18 @@ void quic::sendNewSessionTicket() {
    nst.insert(nst.end(), ticket.begin(), ticket.end());

    // extensions<0..2^16-2>: early_data (0x002a) { uint32 max_early_data_size; }
    //
    // RFC 9001 4.6.1: over QUIC this field MUST be sent as 0xffffffff. The
    // real 0-RTT byte cap (kMaxEarlyDataSize, used for the ticket's internal
    // anti-replay/admission bookkeeping above) is instead conveyed to the
    // client via the initial_max_data transport parameter. A conformant
    // QUIC-TLS peer treats any other wire value here as a fatal
    // PROTOCOL_VIOLATION during the handshake.
    static constexpr uint32_t kWireMaxEarlyDataSize = 0xffffffff;
    std::vector<uint8_t> extensions;
    extensions.push_back(0x00); extensions.push_back(0x2a);
    extensions.push_back(0x00); extensions.push_back(0x04);
    for (int i = 3; i >= 0; --i) extensions.push_back(static_cast<uint8_t>(kMaxEarlyDataSize >> (8 * i)));
    for (int i = 3; i >= 0; --i) extensions.push_back(static_cast<uint8_t>(kWireMaxEarlyDataSize >> (8 * i)));
    nst.push_back(static_cast<uint8_t>(extensions.size() >> 8));
    nst.push_back(static_cast<uint8_t>(extensions.size()));
    nst.insert(nst.end(), extensions.begin(), extensions.end());
@@ -8691,14 +8699,6 @@ void quic::sendServerHandshakeFlight() {
        const bool use_sha384_cv = prefer_sha384 && _sigalg_rsa_pss_sha384;
        std::vector<uint8_t> cv_body;

        if (use_sha384_cv) {
            cv_body.push_back(0x08);
            cv_body.push_back(0x05);  // rsa_pss_rsae_sha384
        } else {
            cv_body.push_back(0x08);
            cv_body.push_back(0x04);  // rsa_pss_rsae_sha256
        }

        // Build content to sign: 64 spaces + context + 0x00 + transcript hash
        // The transcript hash MUST use the negotiated cipher suite's hash
        // function (RFC 8446 §4.4.1), independent of which RSA-PSS variant
@@ -8721,14 +8721,41 @@ void quic::sendServerHandshakeFlight() {
            sha384_hash(_tls_transcript) : sha256_hash(_tls_transcript);
        sign_content.insert(sign_content.end(), cv_transcript_hash.begin(), cv_transcript_hash.end());
        
        // Use appropriate RSA-PSS signing based on cipher suite
        // Sign with whichever key type this cert bundle actually has. RSA-PSS
        // when rsa_key is populated (mirrors tls::tls13_build_certificate_verify's
        // TCP/H2 path); ECDSA P-256 when it's an EC identity instead. Signing
        // unconditionally via rsa_key regardless of key type was a bug: an
        // EC-keyed cert bundle left rsa_key default-constructed (falsy), so
        // this would sign with an empty key and produce a CertificateVerify
        // no conformant client can verify -- an immediate handshake failure.
        std::vector<uint8_t> signature;
        if (_selected_cert->rsa_key) {
            if (use_sha384_cv) {
            signature = rsa_pss_sha384::sign(
                _selected_cert->rsa_key, sign_content);
                cv_body.push_back(0x08); cv_body.push_back(0x05);  // rsa_pss_rsae_sha384
                signature = rsa_pss_sha384::sign(_selected_cert->rsa_key, sign_content);
            } else {
                cv_body.push_back(0x08); cv_body.push_back(0x04);  // rsa_pss_rsae_sha256
                signature = rsa_pss_sha256::sign(_selected_cert->rsa_key, sign_content);
            }
        } else if (_selected_cert->has_ec_key) {
            // sign_content already embeds the cipher-suite-hash-length
            // transcript hash (see comment above) -- ecdsa_secp256r1_sha256's
            // own SHA-256 is just the primitive's internal message hash,
            // applied on top of that blob like RSA-PSS's hash is above, not a
            // reason to rebuild sign_content with a different transcript hash.
            cv_body.push_back(0x04); cv_body.push_back(0x03);  // ecdsa_secp256r1_sha256
            std::vector<uint8_t> ec_priv(_selected_cert->ecPrivateKey,
                                          _selected_cert->ecPrivateKey + 32);
            signature = tls::sign_ecdsa_sha256(sign_content, ec_priv);
        } else {
            signature = rsa_pss_sha256::sign(
                _selected_cert->rsa_key, sign_content);
            NetException e;
            e[NetException::Error] << "quic::sendServerHandshakeFlight: no usable private key (neither RSA nor EC) in selected certificate bundle";
            throw e;
        }
        if (signature.empty()) {
            NetException e;
            e[NetException::Error] << "quic::sendServerHandshakeFlight: CertificateVerify signing produced an empty signature";
            throw e;
        }

        // Signature length and data