HTTPS and TLS 1.3 Handshake: Keys, Certificates, and RTT in Practice
HTTPS and TLS 1.3 Handshake: Keys, Certificates, and RTT in Practice
Search
Ask the AI

HTTPS and TLS 1.3 Handshake: Keys, Certificates, and RTT in Practice

The HTTPS handshake solves two problems: authenticating the server at the other end, and agreeing on a key known only to the communicating parties over a public connection. The parties then use the negotiated key to encrypt HTTP data.

1. The Architecture of TLS 1.3: 1-RTT and State Machine Overhaul

For a common certificate-authenticated TLS 1.3 handshake without HelloRetryRequest, the client can send ordinary application data about one network RTT after ClientHello, excluding DNS, TCP setup and computation. A key_share can accompany it. After ServerHello, the server sends encrypted EncryptedExtensions, Certificate, CertificateVerify and Finished. PSK resumption can omit certificates; PSK-only and 0-RTT have different forward-secrecy conditions. OpenSSL’s statem_clnt.c, statem_srvr.c and TLS_ST_SW_SRVR_HELLO are version-specific implementation states.

TLS 1.3 message flights in a one round-trip teaching model
With modeled RTT set to 36 ms, the client sends the application request at exactly 36 ms, optimizing the physical limit of latency.

2. Advanced State Machine & HKDF Visualization

The original diagram below retains a shorthand key schedule. Its HKDF-Extract(0, ECDHE Shared Secret) omits the derived salt: TLS 1.3 derives a secret from Early Secret and uses it as the Handshake Secret salt. Master Secret comes from another HKDF-Extract, followed by labelled transcript-bound traffic-secret derivation. Use the full schedule in RFC 8446 §7.1 for implementation. The companion figure’s 36 ms is a fixed model without computation, retries or prior TCP setup, not a physical latency limit.


sequenceDiagram
    autonumber
    participant Client
    participant Server
    
    Client->>Server: ClientHello + Key Share (X25519) + ALPN
    Note right of Server: statem_srvr.c: tls_process_client_hello()
HKDF-Extract(0, ECDHE Shared Secret)
HKDF-Expand(Handshake Secret) Server->>Client: ServerHello + Key Share Server->>Client: {EncryptedExtensions + Certificate + CertVerify + Finished} Note left of Client: statem_clnt.c: tls_process_server_hello()
Derive keys, Verify Signature, Verify Finished MAC Client->>Server: {Finished} + [Application Data (HTTP Request)] Note right of Server: HKDF-Expand(Master Secret) -> Application Traffic Keys Server->>Client: [Application Data (HTTP Response)]

3. Mathematical Rigor: ECDLP and AES-GCM Polynomials

TLS 1.3 can negotiate groups including X25519 and AEAD suites including AES-GCM and ChaCha20-Poly1305. The following examples explain Curve25519 and AES-GCM; they are not mandatory selections for every connection.

Elliptic Curve Discrete Logarithm Problem (ECDLP)

The key exchange leverages the Curve25519 Montgomery curve defined by the equation over a prime field \(\mathbb{F}_p\):

\[ v^2 = u^3 + 486662u^2 + u \pmod{2^{255}-19} \]

Under the chosen security parameters and implementation assumptions, recovering private scalar \( d \) from base point \( G \) and public key \( P = dG \) is considered computationally hard. The point-level relation is \( S = d_{client} P_{server} = d_{client} d_{server} G = d_{server} P_{client} \). Actual X25519 operates on encoded u coordinates with specified scalar handling, then feeds the TLS key schedule. Constant-time code reduces relevant timing leakage; a Montgomery-ladder name alone does not establish protection from every side channel.

Galois/Counter Mode (GCM) Mathematics

Once keys are established, AES-GCM encrypts the application records. The authentication tag in GCM is computed using a universal hash function GHASH over the Galois field \( \text{GF}(2^{128}) \). The field is defined by the irreducible polynomial:

\[ P(x) = x^{128} + x^7 + x^2 + x + 1 \]

The field elements are 128-bit blocks. GCM’s GHASH processes padded additional authenticated data, ciphertext and length blocks with hash subkey \( H \); the final tag also combines the encrypted initial counter block. Carry-less multiplication such as vpclmulqdq can accelerate GHASH. It belongs to a separate instruction extension, not the AES-NI instructions themselves.

4. Production Engineering: OpenSSL and Hardware Acceleration

Connection rate alone, including the original 100k+ connections/sec example, does not identify the bottleneck. OpenSSL selects optimized implementations according to its build and CPU capabilities; the original evp_cipher shorthand does not specify a public EVP API or exact path. Flags such as aes and pclmulqdq support corresponding optimizations, while avx512f is not required for TLS or AES-GCM. Expose only hardware-supported capabilities.

Certificate signing through EVP_DigestSign can use a compatible QAT Engine/Provider integration. Asynchronous behavior depends on versions, algorithms, builds and application event-loop support; it is not the default of every OpenSSL/Nginx deployment. ECDSA signing uses scalar operations rather than solving the ECDLP.

5. Advanced Tooling: eBPF Traffic Interception

Packet captures still show TCP timing, retransmissions, plaintext ClientHello/ServerHello and some negotiation information. TLS 1.3 encrypts later handshake content. Uprobes can provide library-state observations alongside packet evidence; they answer different questions.

The retained BCC fragment below times one entry/return invocation of SSL_do_handshake. A nonblocking handshake may return WANT_READ/WANT_WRITE and invoke it repeatedly; measuring the whole handshake requires per-SSL/connection state. Loading, attachment and histogram-reading code are also omitted.

#include <uapi/linux/ptrace.h>
BPF_HASH(start, u32);
BPF_HISTOGRAM(dist);

int probe_ssl_handshake_start(struct pt_regs *ctx) {
    u32 pid = bpf_get_current_pid_tgid();
    u64 ts = bpf_ktime_get_ns();
    start.update(&pid, &ts);
    return 0;
}

int probe_ssl_handshake_return(struct pt_regs *ctx) {
    u32 pid = bpf_get_current_pid_tgid();
    u64 *tsp = start.lookup(&pid);
    if (tsp != 0) {
        u64 delta = bpf_ktime_get_ns() - *tsp;
        dist.increment(bpf_log2l(delta / 1000000)); // Log2 histogram in ms
        start.delete(&pid);
    }
    return 0;
}

A uprobe attaches at a probeable location in libssl.so; its BPF handler runs in the kernel rather than being injected as BPF code into the library text. The fragment keys a single call by thread ID. Log2 millisecond bins approximate a distribution, not an exact full-handshake p99. Probing and packet capture both have overhead that should be assessed for the observation.

6. Post-mortem: Side-Channel Attack Mitigations

TLS 1.3 removes static RSA key transport (PKCS#1 v1.5) and MAC-then-Encrypt CBC record encryption, avoiding the old mechanisms used by Bleichenbacher and Lucky Thirteen attacks. Cache side channels such as Flush+Reload still require implementation checks. Implementations still need correct certificates, key/nonce handling and side-channel behavior. Constant-time branching and memory access are implementation properties; neither a protocol version nor a ladder algorithm alone establishes a leak-free system.

7. TLS Handshake Troubleshooting Matrix

TLS 1.3 symptoms such as slow HTTPS, certificate errors, and intermittent handshake failures may come from DNS, TCP, certificate chains, key exchange, ALPN, hardware acceleration, or application retries. The matrix below lists observable evidence for distinguishing encryption-layer issues from lower-layer failures.

Symptom Evidence to collect Inspect first Safety boundary
First HTTPS request is slow TLS version, handshake RTT, session resumption state, and certificate-chain size. Whether resumption is lost or the certificate chain is too large. Do not downgrade to obsolete protocols to save a round trip.
Certificate validation fails SNI, SAN, certificate validity, intermediate certificates, and OCSP/CRL state. Whether the chain is complete and the hostname matches the certificate. Do not “fix” clients by disabling certificate validation.
Handshake P99 is unstable eBPF/uProbe handshake histogram, CPU flags, and OpenSSL version. Missing AES-NI/QAT support or blocked event loops. Do not mistake crypto CPU cost for insufficient bandwidth.
0-RTT behavior is unexpected Early-data setting, idempotency check, replay protection, and server logs. Whether the request is suitable for early data and replay controls fired. Non-idempotent writes should not accept 0-RTT.

FAQ

Does the certificate encrypt application records?

An X.509 certificate binds identity to a public key through its issuer’s signature, using a supported algorithm such as ECDSA over P-256. In certificate-authenticated TLS 1.3, the server separately uses the corresponding private key for CertificateVerify over a context-bound handshake transcript, proving private-key possession. Application records use symmetric AEAD keys from the key schedule. Assess forward secrecy separately for ECDHE, PSK-only and early data.

Why not implement TLS from scratch?

Production TLS includes protocol state, certificate validation, the key schedule, randomness, records and platform side channels. Use maintained OpenSSL, BoringSSL or Rustls versions and check their supported features and updates. Hardware acceleration is a performance choice, not a prerequisite for every secure implementation.

References

Leave a Reply

Scroll down