Выполнить лабораторную 7 по безопасности мессенджера
Application HTTPS smoke / smoke (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
2026-12-04 23:51:24 +03:00
parent 20afc2c790
commit 65bbf3224a
86 changed files with 6376 additions and 144 deletions
+36
View File
@@ -0,0 +1,36 @@
"""TLS settings shared by application roles. Every network client verifies its peer."""
import os
import ssl
from pathlib import Path
TLS = Path("/run/identity")
CA = str(TLS / "ca.crt")
CERT = str(TLS / "service.crt")
KEY = str(TLS / "service.key")
def client_context(identity=True):
context = ssl.create_default_context(cafile=CA)
context.minimum_version = ssl.TLSVersion.TLSv1_2
if identity:
context.load_cert_chain(CERT, KEY)
return context
def server_context():
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)
context.load_verify_locations(CA)
context.verify_mode = ssl.CERT_REQUIRED
return context
def accept_ingress(peer):
allowed = (TLS / "ingress-serials").read_text().split()
return ("URI", "spiffe://lab7/ingress") in peer.get("subjectAltName", ()) and peer["serialNumber"] in allowed
def database_url():
return os.environ["DATABASE_URL"]