forked from mtusi2026/mtusi2026lab7
ЛР 7: реализация мессенджера и сценарии проверки
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user