lab7: безопасность, mTLS, OpenBao и PKI lifecycle

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 10:58:07 +03:00
parent 3d216fbd50
commit 3441f2269a
183 changed files with 216667 additions and 3165 deletions
+7 -6
View File
@@ -2,7 +2,7 @@
"""Negative attachment scenarios required by lab4 level 4.
Run against a live stand:
python3 student-tests/attachments_negative.py --base-url http://localhost:8080
python3 student-tests/attachments_negative.py --base-url https://localhost:8443
"""
import hashlib
import struct
@@ -15,8 +15,10 @@ from pathlib import Path
from urllib.parse import quote
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
from client import Client, Failure, arguments, check, run # noqa: E402
from lab7_http import BASE_URL, CA_FILE, open_url # noqa: E402
FIXTURE = Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png'
@@ -53,7 +55,7 @@ def crafted_png_extra(width, height, raster, pre_idat=(), bit_depth=8, color_typ
def main():
args = arguments('Attachment negative scenarios (lab4)')
client = Client(args.base_url, args.ca_file)
client = Client(args.base_url or BASE_URL, args.ca_file or CA_FILE)
alice, bob, eve, chat = client.bootstrap()
fixture = FIXTURE.read_bytes()
@@ -212,13 +214,12 @@ def main():
# Object keys are server-generated; anonymous direct access must be denied.
key = 'attachments/' + chat['id'] + '/' + own['id'] + '/original'
request = urllib.request.Request('http://127.0.0.1:8333/messenger-attachments/' + key, method='GET')
request = urllib.request.Request('https://localhost:8333/messenger-attachments/' + key, method='GET')
try:
urllib.request.urlopen(request, timeout=5)
with open_url(request, timeout=5, ca_file=args.ca_file or CA_FILE):
raise Failure('anonymous S3 GET unexpectedly succeeded')
except urllib.error.HTTPError as error:
check(error.code == 403, 'anonymous S3 GET must be 403, got ' + str(error.code))
else:
raise Failure('anonymous S3 GET unexpectedly succeeded')
print('anonymous direct S3 GET: 403')
check(hashlib.sha256(content).hexdigest() == own['sha256'], 'fixture checksum mismatch')