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

test

parent 215f3cb4
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -2718,8 +2718,6 @@ namespace netplus {
            const uint8_t  outer_type = rec[0];
            const uint16_t ver        = (uint16_t(rec[1]) << 8) | uint16_t(rec[2]);

            std::vector<uint8_t> frag(rec.begin() + 5, rec.end());

            // ------------------------------------------------------------
            // TLS 1.2 record handling (CBC in your code)
            // ------------------------------------------------------------
@@ -2736,6 +2734,7 @@ namespace netplus {
                if (!aes_recv)
                    throwSSL(NetException::Error, "aes_recv missing");

                std::vector<uint8_t> frag(rec.begin() + 5, rec.end());
                std::vector<uint8_t> plain = decryptTLS12Record(outer_type, ver, frag);

                if (plain.empty())
@@ -2778,10 +2777,14 @@ namespace netplus {

                // For application traffic, handshake_keys=false.
                // (Handshake traffic would be processed elsewhere, not in recvData())
                // Decrypts straight out of `rec` (ciphertext+tag start at
                // offset 5) instead of first copying that region into a
                // separate `frag` vector — one fewer up-to-16KB copy per
                // received application-data record.
                tls13_recv_record(
                    outer_type,
                    ver,
                    frag.data(), frag.size(),
                    rec.data() + 5, rec.size() - 5,
                    inner_plain,
                    inner_type,
                    /*handshake_keys=*/false
@@ -4139,22 +4142,27 @@ namespace netplus {
        const uint8_t* ct = data;
        const uint8_t* tag = data + enc_len;

        std::vector<uint8_t> plain(enc_len);
        if (!cipher->aes_gcm_decrypt(nonce, aad, 5, ct, enc_len, tag, plain.data())) {
        // Decrypt straight into out_plain's own storage instead of a
        // separate temporary vector that then gets move-assigned into it —
        // avoids one redundant vector object per received record. `ct` and
        // `out_plain.data()` are different buffers here (standard
        // non-in-place AEAD decrypt), so no aliasing concern.
        out_plain.resize(enc_len);
        if (!cipher->aes_gcm_decrypt(nonce, aad, 5, ct, enc_len, tag, out_plain.data())) {
            out_plain.clear();
            return false;
        }

        seq++;

        // Strip padding and get inner type
        while (!plain.empty() && plain.back() == 0) {
            plain.pop_back();
        while (!out_plain.empty() && out_plain.back() == 0) {
            out_plain.pop_back();
        }
        if (plain.empty()) return false;
        if (out_plain.empty()) return false;

        out_inner_type = plain.back();
        plain.pop_back();
        out_plain = std::move(plain);
        out_inner_type = out_plain.back();
        out_plain.pop_back();

        return true;
    }