TLS 1.3 Handshake Security Testing: 0-RTT, Session Tickets, and ALPN
TLS 1.3 removed a lot of attack surface compared to 1.2: no more RSA key exchange, no CBC mode, no compression, no renegotiation. But it introduced new features — 0-RTT early data, session tickets, and stricter ALPN — each of which has its own security properties that need testing. A TLS implementation that passes openssl s_client isn't necessarily secure; you need to probe the protocol-level behaviors that standard connection testing misses.
This post focuses specifically on testing TLS 1.3's new features: the 1-RTT vs 0-RTT handshake flows, replay attack prevention in 0-RTT, session ticket validation, ALPN negotiation edge cases, and downgrade attack resistance.
TLS 1.3 Handshake Flow: What's Different
In TLS 1.2, the handshake was 2 round-trips before application data. TLS 1.3 cuts this to 1 round-trip (1-RTT) for new connections, and optionally 0 round-trips (0-RTT) for resumed connections using a pre-shared key (PSK) from a previous session.
The 0-RTT path looks like this:
- Client sends
ClientHello+ early data in the first flight - Server processes early data before completing the handshake
- Handshake completes, server sends
EndOfEarlyDatasentinel
The risk: early data is not forward-secret and is vulnerable to replay. An attacker can capture a 0-RTT ClientHello+early data and replay it to a different server instance, or even the same server after a restart.
Setting Up tlsfuzzer
tlsfuzzer is a Python-based TLS fuzzing and testing framework. It lets you construct custom TLS handshakes at the message level.
git clone https://github.com/tlsfuzzer/tlsfuzzer.git
cd tlsfuzzer
pip install -r requirements.txt
pip install tlslite-ngtlsfuzzer scripts are in scripts/. Each script tests a specific protocol behavior.
Testing 1-RTT Handshake
Start with a basic TLS 1.3 1-RTT handshake to confirm your server negotiates correctly:
python scripts/test-TLSv1_3-draft-18.py \
-h your-server.example.com \
-p 443 \
--no-ssl2 \
--no-ssl3 \
--no-tls1 \
--no-tls1_1 \
--no-tls1_2For programmatic 1-RTT testing with tlslite-ng directly:
from tlslite import TLSConnection
from tlslite.constants import TLS_1_3_DRAFT, CipherSuite
import socket
def test_tls13_1rtt_handshake(host: str, port: int = 443):
"""Verify server completes TLS 1.3 1-RTT handshake and negotiates correct cipher."""
sock = socket.create_connection((host, port), timeout=10)
conn = TLSConnection(sock)
settings = conn.handshakeClientCert.__defaults__ # Pull default settings
# Force TLS 1.3 only
from tlslite import HandshakeSettings
hs = HandshakeSettings()
hs.minVersion = (3, 4)
hs.maxVersion = (3, 4)
conn.handshakeClientCert(settings=hs)
assert conn.version == (3, 4), f"Expected TLS 1.3, got {conn.version}"
assert conn.session.cipherSuite in [
CipherSuite.TLS_AES_128_GCM_SHA256,
CipherSuite.TLS_AES_256_GCM_SHA384,
CipherSuite.TLS_CHACHA20_POLY1305_SHA256,
], f"Unexpected cipher: {conn.session.cipherSuite}"
conn.close()
sock.close()
print(f"1-RTT handshake: OK, cipher={hex(conn.session.cipherSuite)}")Testing 0-RTT Early Data
0-RTT testing requires two connections: the first to establish a session and get a ticket, the second to use it for 0-RTT.
from tlsfuzzer.runner import Runner
from tlsfuzzer.messages import Connect, ClientHelloGenerator, \
ClientKeyExchangeGenerator, ChangeCipherSpecGenerator, \
FinishedGenerator, ApplicationDataGenerator, AlertGenerator
from tlslite.constants import ContentType, HandshakeType
def test_0rtt_accepted(host: str, port: int):
"""Server must accept valid 0-RTT early data from a known session."""
# Phase 1: Establish session, get ticket
# Phase 2: Send 0-RTT data, verify server accepts it
# This is done via tlsfuzzer's Runner + conversation DSL
pass # See tlsfuzzer/scripts/test-TLSv1_3-0rtt.py for full implementationRun the built-in 0-RTT test script against your server:
python scripts/test-TLSv1_3-0rtt.py \
-h your-server.example.com \
-p 443 \
-k path/to/server.key \
-c path/to/server.crtReplay Attack Prevention Testing
This is the most critical 0-RTT test. RFC 8446 §8 specifies that servers MUST implement replay protection for 0-RTT data. Common mechanisms: single-use tickets, a replay cache, or both.
The test: capture a valid 0-RTT ClientHello and replay it. The server must reject the replayed early data (it can either reject the entire 0-RTT or fall back to 1-RTT).
# tlsfuzzer has a dedicated replay test
python scripts/test-TLSv1_3-0rtt-replay.py \
-h your-server.example.com \
-p 443What to look for in the test output:
EarlyDataIndicationmust not appear in the second handshake- If the server accepts the 0-RTT ticket on replay, that's a critical vulnerability
- Legitimate outcome: server falls back to 1-RTT (sends
early_dataextension withmax_early_data_size=0)
For Nginx with TLS 1.3 0-RTT:
ssl_early_data on;
# REQUIRED: Pass 0-RTT status header to upstream to prevent replay
proxy_set_header Early-Data $ssl_early_data;Test that your application layer respects this header — state-changing requests (POST, DELETE) must reject Early-Data: 1:
import requests
def test_application_rejects_early_data_for_mutations():
"""Application must reject state-changing requests sent as 0-RTT."""
headers = {"Early-Data": "1"}
response = requests.post(
"https://your-server.example.com/api/transfer",
headers=headers,
json={"amount": 100},
)
# Server should return 425 Too Early (RFC 8470)
assert response.status_code == 425, (
f"Expected 425 Too Early, got {response.status_code}. "
"POST with Early-Data header must be rejected."
)Session Ticket Lifetime Validation
TLS 1.3 session tickets are short-lived by design. RFC 8446 recommends tickets expire after 7 days max, and tickets must not be reused (no ticket reuse = no replay surface).
# Test that expired tickets are rejected
python scripts/test-TLSv1_3-session-resumption.py \
-h your-server.example.com \
-p 443 \
--ticket-lifetime 0 # Force expired ticketTest ticket freshness with OpenSSL:
# Capture session ticket
openssl s_client \
-connect your-server.example.com:443 \
-tls1_3 \
-sess_out /tmp/session.pem \
-ign_eof < /dev/null
# Inspect ticket lifetime
openssl sess_id -in /tmp/session.pem -text | grep -E "Timeout|Ticket"
# Attempt resumption after timeout
sleep $((ticket_lifetime + 1))
openssl s_client \
-connect your-server.example.com:443 \
-tls1_3 \
-sess_in /tmp/session.pem \
-ign_eof < /dev/null 2>&1 | grep -E "Reused|New"A correctly configured server returns New, TLSv1.3 (new handshake) when the ticket has expired, not Reused.
ALPN Negotiation Testing
ALPN (Application-Layer Protocol Negotiation) lets the client advertise supported protocols (h2, http/1.1, h3) in the ClientHello, and the server picks one. Misconfigurations here can cause protocol confusion vulnerabilities.
import ssl
import socket
def test_alpn_negotiation(host: str, port: int, offered: list[str], expected: str):
"""Server must select the correct ALPN protocol."""
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.minimum_version = ssl.TLSVersion.TLSv1_3
ctx.set_alpn_protocols(offered)
ctx.load_verify_locations("/etc/ssl/cert.pem")
with socket.create_connection((host, port)) as sock:
with ctx.wrap_socket(sock, server_hostname=host) as ssock:
negotiated = ssock.selected_alpn_protocol()
assert negotiated == expected, (
f"ALPN: offered {offered}, expected {expected!r}, got {negotiated!r}"
)
def run_alpn_tests(host: str):
# Server must prefer h2 over http/1.1
test_alpn_negotiation(host, 443, ["h2", "http/1.1"], "h2")
# Server must fall back to http/1.1 if h2 not offered
test_alpn_negotiation(host, 443, ["http/1.1"], "http/1.1")
# Server must handle unknown protocol gracefully
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.minimum_version = ssl.TLSVersion.TLSv1_3
ctx.set_alpn_protocols(["unknown-proto/1.0"])
ctx.load_verify_locations("/etc/ssl/cert.pem")
try:
with socket.create_connection((host, 443)) as sock:
with ctx.wrap_socket(sock, server_hostname=host) as ssock:
negotiated = ssock.selected_alpn_protocol()
# Either reject (handshake_failure) or return None/fallback
# Must NOT return "unknown-proto/1.0"
assert negotiated != "unknown-proto/1.0"
except ssl.SSLError as e:
# Acceptable — server rejected unknown ALPN
assert "handshake_failure" in str(e) or "alert" in str(e).lower()Downgrade Attack Prevention
TLS 1.3 includes downgrade protection via a sentinel value in the ServerHello random field. If a TLS 1.3 server responds to a TLS 1.2 ClientHello, it MUST include the downgrade sentinel 44 4F 57 4E 47 52 44 01 in the last 8 bytes of its random value. A TLS 1.3 client detecting this sentinel during a TLS 1.2 handshake must abort.
Test this with tlsfuzzer:
# Attempt to downgrade a TLS 1.3 server to TLS 1.2
python scripts/test-downgrade-protection.py \
-h your-server.example.com \
-p 443
# Attempt TLS 1.1 downgrade (must fail)
python scripts/test-tls-downgrade-to-tls11.py \
-h your-server.example.com \
-p 443Also test with direct OpenSSL:
# All of these should fail with handshake_failure or protocol_version alert
for version in -ssl3 -tls1 -tls1_1 -tls1_2; do
echo -n "Testing $version: "
result=$(openssl s_client \
-connect your-server.example.com:443 \
$version \
-ign_eof 2>&1 < /dev/null | grep -E "^(CONNECTED|alert|error)")
echo "$result"
doneExpected: TLS 1.2 may succeed if your server supports it, but SSL 3/TLS 1.0/TLS 1.1 must return alert handshake failure or no protocols available.
TLS-Anvil for Conformance Testing
TLS-Anvil is a Java-based test suite that runs 1000+ TLS conformance tests against a target server. It's more thorough than manual scripting for protocol conformance.
# Run TLS-Anvil against your server
docker run --rm \
-v $(pwd)/results:/output \
ghcr.io/tls-anvil/tls-anvil:latest \
-t server \
-connect your-server.example.com:443 \
--output /output
# Review failures
cat results/tls-anvil-report.json | jq '.tests[] | select(.result == "FAILED")'Key test categories to check in the output:
TLS13-0RTT— 0-RTT early data handlingTLS13-SessionTicket— ticket lifetime and rotationTLS13-Downgrade— sentinel validationTLS13-ALPN— protocol negotiation correctness
Scapy for Raw Packet-Level Testing
For testing at the raw packet level — useful when you need to construct malformed handshakes or test middlebox behavior:
from scapy.all import *
from scapy.layers.tls.all import *
from scapy.layers.tls.handshake import TLSClientHello
from scapy.layers.tls.extensions import TLS_Ext_SupportedVersion_CH
def test_tls13_client_hello_missing_supported_versions():
"""
Server must reject a TLS 1.3 ClientHello without supported_versions extension.
RFC 8446 §4.2.1: TLS 1.3 servers MUST negotiate via supported_versions only.
"""
# Build a ClientHello that claims max_version=0x0304 in legacy field
# but omits the supported_versions extension — server must reject
pkt = IP(dst="your-server.example.com") / TCP(dport=443) / \
TLS() / TLSClientHello(
version=0x0303, # TLS 1.2 legacy field
# No supported_versions extension
)
# Send and analyze response
response = sr1(pkt, timeout=2, verbose=False)
if response:
# Should receive an alert, not a ServerHello
assert TLSAlert in response or response.haslayer(TLSAlert), \
"Server accepted invalid ClientHello without supported_versions"What to Add to Your CI Pipeline
For every TLS 1.3 endpoint in production, run these in CI:
- Basic 1-RTT handshake —
openssl s_client -tls1_3succeeds - Downgrade rejection —
openssl s_client -tls1_1fails - ALPN correctness — negotiated protocol matches expected
- 0-RTT replay — if you enable 0-RTT, run
test-TLSv1_3-0rtt-replay.py - Session ticket expiry — tickets expire within your configured lifetime
- TLS-Anvil full suite — weekly, not every commit (it's slow)
The goal isn't to retest OpenSSL. The goal is to verify that your configuration, your application layer, and your infrastructure behave correctly for the protocol features you've enabled. Especially 0-RTT — if you turn it on without testing replay prevention, you've introduced a vulnerability.