Implement lab 7 TLS trust boundary

This commit is contained in:
2026-11-20 19:20:13 +03:00
parent 20afc2c790
commit 1416ea25e2
36 changed files with 1482 additions and 60 deletions
+18
View File
@@ -0,0 +1,18 @@
"""Small security acceptance check for the local TLS boundary."""
import ssl
import urllib.request
import urllib.error
from pathlib import Path
root = Path(__file__).resolve().parents[1]
context = ssl.create_default_context(cafile=root / 'certs' / 'ca.crt')
with urllib.request.urlopen('https://127.0.0.1:8443/health/live', context=context, timeout=5) as response:
assert response.status == 200
try:
with urllib.request.urlopen('https://127.0.0.1:8443/health/live', context=ssl.create_default_context(), timeout=5):
raise AssertionError('untrusted certificate was accepted')
except (ssl.SSLCertVerificationError, urllib.error.URLError) as error:
if isinstance(error, urllib.error.URLError) and not isinstance(error.reason, ssl.SSLCertVerificationError):
raise
pass
print('PASS: trusted local TLS works and an untrusted certificate is rejected.')