ЛР 7: реализация мессенджера и сценарии проверки

This commit is contained in:
Russiankryt
2026-12-03 17:20:53 +03:00
parent 20afc2c790
commit 3dd0587e7d
57 changed files with 3470 additions and 55 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Require a trusted certificate and an exact DNS SAN from the allowlist."""
import ssl
def listener(cert, key, ca, mutual):
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.minimum_version = ssl.TLSVersion.TLSv1_2
context.options |= ssl.OP_NO_TICKET
context.load_cert_chain(cert, key)
if mutual:
context.load_verify_locations(ca)
context.verify_mode = ssl.CERT_REQUIRED
return context
def allowed(ssl_socket, identities):
if not ssl_socket:
return False
certificate = ssl_socket.getpeercert()
if not certificate:
return False
sans = {value for kind, value in certificate.get("subjectAltName", ()) if kind == "DNS"}
return len(sans) == 1 and sans <= identities