Implement lab 7 security and mTLS

This commit is contained in:
2026-11-26 16:55:53 +03:00
parent 20afc2c790
commit ab7b467957
54 changed files with 3240 additions and 25 deletions
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
"""Small operator-facing negative checks for the level-4 defense."""
import ssl, socket, urllib.request
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
CA = ROOT / "certs/ca.crt"
def main():
ctx = ssl.create_default_context(cafile=str(CA))
with urllib.request.urlopen("https://localhost:8443/health/ready", context=ctx, timeout=5) as r:
assert r.status in (200, 503)
raw = socket.create_connection(("127.0.0.1", 8443), 3)
try:
raw.sendall(b"GET /health/ready HTTP/1.1\r\nHost: localhost\r\n\r\n")
data = raw.recv(128)
assert not data.startswith(b"HTTP/1.1 200")
finally:
raw.close()
print("PASS: trusted HTTPS works and plaintext external access is rejected")
if __name__ == "__main__":
main()