Files
RustPython/extra_tests/snippets/stdlib_ssl.py
T
Jeong, YunWon 531cf2b378 ssl: unify handshake, transport and shutdown state (#8656)
* ssl: accept ClientHello before selecting the SNI context

Replace the provisional server connection and replay flags with explicit handshake states. Retain fatal alerts across nonblocking retries and preserve fragmented input on timeout. Enable the three SNI alert regressions.

Assisted-by: Codex:GPT-5

* ssl: share socket and MemoryBIO transport progress

Queue drained TLS records before fallible output and use one handshake record loop for both transports.

Assisted-by: Codex:GPT-5

* ssl: unify shutdown and fatal alert lifecycle

Track close-notify progress in TlsState, preserve pending alerts across retries, and share record-boundary shutdown for sockets and MemoryBIO. Retain rustls errors until Python exception conversion.

Assisted-by: Codex:GPT-5

* ssl: emit the full peer certificate dict

Use the same certificate dict helper for getpeercert() and
Certificate.get_info() so OCSP, caIssuers, and CRL URLs are present.
Clear CHANNEL_BINDING_TYPES on the rustls backend, and add a MemoryBIO
leftover-plaintext snippet.

Assisted-by: Claude
2026-09-06 07:54:59 +09:00

47 lines
1.2 KiB
Python

import pathlib
import ssl
CERT = (
pathlib.Path(__file__).resolve().parent.parent.parent
/ "Lib"
/ "test"
/ "certdata"
/ "keycert.pem"
)
TAIL = b"tail"
server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
server_context.load_cert_chain(str(CERT))
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client_context.check_hostname = False
client_context.verify_mode = ssl.CERT_NONE
server_context.maximum_version = client_context.maximum_version = ssl.TLSVersion.TLSv1_2
client_in, client_out = ssl.MemoryBIO(), ssl.MemoryBIO()
server_in, server_out = ssl.MemoryBIO(), ssl.MemoryBIO()
client = client_context.wrap_bio(client_in, client_out)
server = server_context.wrap_bio(server_in, server_out, server_side=True)
for _ in range(5):
try:
client.do_handshake()
except ssl.SSLWantReadError:
pass
server_in.write(client_out.read())
try:
server.do_handshake()
except ssl.SSLWantReadError:
pass
client_in.write(server_out.read())
client.do_handshake()
server.do_handshake()
try:
server.unwrap()
except ssl.SSLWantReadError:
pass
client_in.write(server_out.read() + TAIL)
client.unwrap()
assert client_in.read() == TAIL