[edge] Listeners: QC's probes kept as regression tests (smuggling and desync with pipelining, a TLS handshake that never starts, an HTTP/2 header block that never ends) with their Python probes in tests/support/probes

This commit is contained in:
2026-11-22 18:50:36 +01:00
parent b492ccf5f9
commit 6ce6bfdb79
3 changed files with 315 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# QC phase 4: an HTTP/2 header block that never ends: valid HPACK, a literal x-slow header whose 4000-byte
# value arrives one byte per CONTINUATION frame every 0.5 s, after a proper SETTINGS exchange.
# h2slow.py <host> <port> <limit s> [sni] prints "closed after Ns" or "STILL OPEN after Ns"
import socket, ssl, sys, time
host, port, limit = sys.argv[1], int(sys.argv[2]), float(sys.argv[3])
sni = sys.argv[4] if len(sys.argv) > 4 else "app.test"
ctx = ssl.create_default_context(); ctx.check_hostname = False; ctx.verify_mode = ssl.CERT_NONE
ctx.set_alpn_protocols(["h2"])
t = ctx.wrap_socket(socket.create_connection((host, port)), server_hostname=sni)
def frame(ty, flags, sid, payload): return len(payload).to_bytes(3, "big") + bytes([ty, flags]) + sid.to_bytes(4, "big") + payload
seen = []
def parse(d):
i = 0
while i + 9 <= len(d):
ln = int.from_bytes(d[i:i+3], "big"); seen.append((d[i+3], d[i+4], d[i+9:i+9+ln][:8].hex())); i += 9 + ln
# 1. preface + SETTINGS; read the server's SETTINGS and ACK it before any header block.
t.sendall(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + frame(4, 0, 0, b""))
t.settimeout(2)
try:
parse(t.recv(65536))
except socket.timeout:
pass
t.sendall(frame(4, 1, 0, b""))
# 2. HEADERS without END_HEADERS: valid HPACK; a literal x-slow header whose 4000-byte value
# then arrives one byte per CONTINUATION frame, every 0.5 s. Nothing else is sent meanwhile.
block = b"\x82\x87\x84" + b"\x41" + bytes([len(sni)]) + sni.encode()
block += b"\x00\x06x-slow" + b"\x7f" + bytes([(3873 % 128) | 0x80, 3873 // 128])
t.sendall(frame(1, 1, 1, block))
start = time.time(); t.settimeout(0.5)
def el(): return f"{time.time()-start:.1f}s"
while time.time() - start < limit:
try:
d = t.recv(65536)
if not d:
print(f"h2 {port}: closed after {el()}; frames from server {seen}"); break
parse(d)
except socket.timeout:
pass
except OSError as e:
print(f"h2 {port}: closed after {el()} ({e}); frames {seen}"); break
try:
t.sendall(frame(9, 0, 1, b"a"))
except OSError as e:
print(f"h2 {port}: closed after {el()} ({e}); frames {seen}"); break
else:
print(f"h2 {port}: STILL OPEN after {limit:.0f}s; frames {seen[:6]}")
+44
View File
@@ -0,0 +1,44 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# QC phase 4: slow-client probes against a TLS listener, by hand-written bytes (no HTTP library).
# slow.py <host> <port> idle <limit s> [sni] a TCP connection that never sends a ClientHello
# slow.py <host> <port> h2 <limit s> [sni] an h2 HEADERS block continued by one CONTINUATION frame every 0.5 s
# Prints "closed after Ns" or "STILL OPEN after Ns". Used by crates/edge/tests/listeners.rs and scripts/conformance.sh.
import socket, ssl, sys, time
host, port, mode, limit = sys.argv[1], int(sys.argv[2]), sys.argv[3], float(sys.argv[4])
sni = sys.argv[5] if len(sys.argv) > 5 else "app.test"
s = socket.create_connection((host, port))
start = time.time()
def el(): return f"{time.time()-start:.1f}s"
if mode == "idle":
# TCP open, no TLS ClientHello ever sent
s.settimeout(limit)
try:
d = s.recv(1)
print(f"idle {port}: closed after {el()} ({d!r})")
except socket.timeout:
print(f"idle {port}: STILL OPEN after {limit:.0f}s")
except OSError as e:
print(f"idle {port}: closed after {el()} ({e})")
elif mode == "h2":
ctx = ssl.create_default_context(); ctx.check_hostname = False; ctx.verify_mode = ssl.CERT_NONE
ctx.set_alpn_protocols(["h2"])
t = ctx.wrap_socket(s, server_hostname=sni)
def frame(ty, flags, sid, payload): return len(payload).to_bytes(3, "big") + bytes([ty, flags]) + sid.to_bytes(4, "big") + payload
# preface, SETTINGS, HEADERS (END_STREAM, no END_HEADERS), then a CONTINUATION byte every 0.5 s
t.sendall(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + frame(4, 0, 0, b"") + frame(1, 1, 1, b"\x82"))
start = time.time(); t.settimeout(0.5)
while time.time() - start < limit:
try:
t.sendall(frame(9, 0, 1, b"\x82"))
d = t.recv(4096)
if not d:
print(f"h2 {port} alpn={t.selected_alpn_protocol()}: closed after {el()}"); break
except socket.timeout:
pass
except OSError as e:
print(f"h2 {port} alpn={t.selected_alpn_protocol()}: closed after {el()} ({e})"); break
else:
print(f"h2 {port} alpn={t.selected_alpn_protocol()}: STILL OPEN after {limit:.0f}s")