From 56d7501703813c54b50f59fd3ba8ffbe0e221fe1 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:18:56 +0300 Subject: [PATCH 1/3] test(seedtls): give the test CA a key usage extension The served-TLS test builds its own CA with a bare `openssl req -x509`, which carries basicConstraints but no keyUsage. Python 3.13 and newer put VERIFY_X509_STRICT in ssl.create_default_context(), and OpenSSL then rejects that CA with "CA cert does not include key usage extension". wait_peer swallows the error, so the test only reported gateway-certificate-not-served after 30 seconds. It started failing when ubuntu-latest moved to Ubuntu 26.04 with Python 3.14. Make the fixture look like a publicly issued chain: keyUsage on the CA, and basicConstraints, keyUsage and an authority key identifier on the leaf. The test now also sets VERIFY_X509_STRICT itself, so it checks the same thing on older interpreters. renew.py is unchanged and verification is not weakened. Co-Authored-By: Claude Fable 5.2 --- internal/seedtls/testdata/test_tls.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/seedtls/testdata/test_tls.py b/internal/seedtls/testdata/test_tls.py index 50ab4d1..6dc1425 100644 --- a/internal/seedtls/testdata/test_tls.py +++ b/internal/seedtls/testdata/test_tls.py @@ -29,9 +29,13 @@ def setUpClass(cls): cls.root = Path(cls.tmp.name) def openssl(*args): subprocess.run(['openssl', *args], cwd=cls.root, check=True, capture_output=True) - openssl('req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-subj', '/CN=Test CA', '-days', '10', '-keyout', 'ca.key', '-out', 'ca.crt') + # Python 3.13+ verifies with VERIFY_X509_STRICT by default, which rejects + # a CA without keyUsage and a leaf without an authority key identifier. + # Publicly trusted chains carry both; state them instead of relying on + # what this OpenSSL CLI happens to add. + openssl('req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-subj', '/CN=Test CA', '-days', '10', '-addext', 'keyUsage=critical,keyCertSign,cRLSign', '-keyout', 'ca.key', '-out', 'ca.crt') openssl('req', '-newkey', 'rsa:2048', '-nodes', '-subj', '/CN=seed.example.org', '-keyout', 'leaf.key', '-out', 'leaf.csr') - (cls.root/'san').write_text('subjectAltName=DNS:seed.example.org,IP:8.8.8.8\nextendedKeyUsage=serverAuth\n') + (cls.root/'san').write_text('subjectAltName=DNS:seed.example.org,IP:8.8.8.8\nextendedKeyUsage=serverAuth\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nauthorityKeyIdentifier=keyid:always\n') openssl('x509', '-req', '-in', 'leaf.csr', '-CA', 'ca.crt', '-CAkey', 'ca.key', '-CAcreateserial', '-days', '5', '-extfile', 'san', '-out', 'leaf.crt') (cls.root/'trust').mkdir() (cls.root/'trust/ca.crt').write_bytes((cls.root/'ca.crt').read_bytes()) @@ -75,7 +79,13 @@ def server(): thread.start() real_connect = socket.create_connection real_context = ssl.create_default_context - with mock.patch.object(renew.socket, 'create_connection', side_effect=lambda *_a, **_kw: real_connect(address, timeout=5)), mock.patch.object(renew.ssl, 'create_default_context', side_effect=lambda: real_context(cafile=str(self.root/'ca.crt'))): + def strict_context(): + # Strict on every interpreter, so the fixture cannot pass on an + # older Python and fail on the next runner image. + trusted = real_context(cafile=str(self.root/'ca.crt')) + trusted.verify_flags |= ssl.VERIFY_X509_STRICT + return trusted + with mock.patch.object(renew.socket, 'create_connection', side_effect=lambda *_a, **_kw: real_connect(address, timeout=5)), mock.patch.object(renew.ssl, 'create_default_context', side_effect=strict_context): cfg = {'hostname': 'seed.example.org', 'address': '8.8.8.8'} renew.wait_peer(cfg, renew.leaf_der((self.root/'leaf.crt').read_bytes())) thread.join(6) From f86bcbfbc6f2c42464c4785e8ae13a37b9c53665 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:39:59 +0300 Subject: [PATCH 2/3] test(seedtls): stop the test listener sending session tickets With the CA accepted, the served-TLS test still failed on the current runner image: renew.peer closes the connection as soon as it has the peer certificate, the listener's TLS 1.3 handshake was still writing session tickets and raised BrokenPipeError, and the listener thread closed the socket before the IP identity could connect. wait_peer then retried against a closed port until gateway-certificate-not-served. The listener only has to present the leaf twice, so it sends no tickets. The client side, renew.peer, is unchanged. Co-Authored-By: Claude Fable 5.2 --- internal/seedtls/testdata/test_tls.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/seedtls/testdata/test_tls.py b/internal/seedtls/testdata/test_tls.py index 6dc1425..38eac49 100644 --- a/internal/seedtls/testdata/test_tls.py +++ b/internal/seedtls/testdata/test_tls.py @@ -59,6 +59,10 @@ def test_real_chain_hostname_ip_and_key(self): def test_real_served_tls_validates_both_identities(self): context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.load_cert_chain(str(self.root/'leaf.crt'), str(self.root/'leaf.key')) + # renew.peer hangs up as soon as it has the certificate. A TLS 1.3 server + # that is still sending session tickets then fails its own handshake + # with EPIPE, and this listener would close before the IP identity. + context.num_tickets = 0 listener = socket.socket() listener.bind(('127.0.0.1', 0)) listener.listen(4) From 2e836d92c42af72a1b2282b832a0af68d15e342c Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:54:35 +0300 Subject: [PATCH 3/3] test(seedtls): say where the listener's EPIPE is raised On the runner image (Python 3.14.4, OpenSSL 3.5.5) the BrokenPipeError comes out of the listener's recv after a completed handshake, not out of the handshake itself. Comment only. Co-Authored-By: Claude Fable 5.2 --- internal/seedtls/testdata/test_tls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/seedtls/testdata/test_tls.py b/internal/seedtls/testdata/test_tls.py index 38eac49..cd20ca1 100644 --- a/internal/seedtls/testdata/test_tls.py +++ b/internal/seedtls/testdata/test_tls.py @@ -60,8 +60,8 @@ def test_real_served_tls_validates_both_identities(self): context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.load_cert_chain(str(self.root/'leaf.crt'), str(self.root/'leaf.key')) # renew.peer hangs up as soon as it has the certificate. A TLS 1.3 server - # that is still sending session tickets then fails its own handshake - # with EPIPE, and this listener would close before the IP identity. + # still has session tickets to send then and gets EPIPE (from recv on + # the CI image), and this listener would close before the IP identity. context.num_tickets = 0 listener = socket.socket() listener.bind(('127.0.0.1', 0))