forked from mtusi2026/mtusi2026lab7
lab7: исправления по независимому ревью
This commit is contained in:
+25
-2
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import secrets
|
||||
import ssl
|
||||
import time
|
||||
@@ -156,7 +157,7 @@ subjectAltName={san}
|
||||
restarted_listener = False
|
||||
for role in ('operator', 'openbao'):
|
||||
certificate = self.env.identity(role) / 'tls.crt'
|
||||
valid = self.env.run(['openssl', 'x509', '-checkend', '30', '-noout',
|
||||
valid = self.env.run(['openssl', 'x509', '-checkend', '300', '-noout',
|
||||
'-in', str(certificate)], check=False).returncode == 0
|
||||
if valid:
|
||||
continue
|
||||
@@ -331,6 +332,19 @@ authorityKeyIdentifier=keyid,issuer
|
||||
next_renewal = time.time() + max(1, (expiry - time.time()) / 2)
|
||||
time.sleep(interval)
|
||||
|
||||
def crl_contains_serial(self, bundle: str, normalized: str) -> bool:
|
||||
wanted = normalized.lstrip('0').lower()
|
||||
for block in re.findall(r'-----BEGIN X509 CRL-----.*?-----END X509 CRL-----', bundle, re.S):
|
||||
output = self.env.run(['openssl', 'crl', '-noout', '-text'], data=block,
|
||||
check=False).stdout
|
||||
for line in output.splitlines():
|
||||
if 'Serial Number:' not in line:
|
||||
continue
|
||||
value = line.split(':', 1)[1].strip().replace(':', '').lower().lstrip('0')
|
||||
if value == wanted:
|
||||
return True
|
||||
return False
|
||||
|
||||
def revoke(self, role: str, serial: str) -> dict:
|
||||
normalized = serial.replace(':', '').replace('-', '').lower()
|
||||
if not normalized or any(ch not in '0123456789abcdef' for ch in normalized):
|
||||
@@ -344,7 +358,10 @@ authorityKeyIdentifier=keyid,issuer
|
||||
# exposes rotation as GET /pki/crl/rotate (POST is 405 here).
|
||||
client.request('GET', 'pki/crl/rotate', token=token)
|
||||
self.sync_crls(client, token)
|
||||
return {'role': role, 'revoked_serial': normalized, 'crls_updated': True, 'crl_rotated': True}
|
||||
if not self.crl_contains_serial(self.cached_crls(), normalized):
|
||||
raise OperationError('published CRL does not contain the revoked serial')
|
||||
return {'role': role, 'revoked_serial': normalized, 'crls_updated': True,
|
||||
'crl_rotated': True, 'crl_contains_serial': True}
|
||||
|
||||
def prepare_rollover(self) -> dict:
|
||||
if self.state.get('next_root'):
|
||||
@@ -405,6 +422,12 @@ authorityKeyIdentifier=keyid,issuer
|
||||
continue
|
||||
if self.certificate_name(current / 'tls.crt', 'issuer') not in active_issuers:
|
||||
raise OperationError('retire blocked: leaf is not from the active issuer: ' + role)
|
||||
verified = self.env.run(['openssl', 'verify',
|
||||
'-CAfile', str(root_dir / 'ca.crt'),
|
||||
'-untrusted', str(root_dir / 'intermediate.crt'),
|
||||
str(current / 'tls.crt')], check=False)
|
||||
if verified.returncode:
|
||||
raise OperationError('retire blocked: leaf chain does not verify: ' + role)
|
||||
client = BaoClient(self.env)
|
||||
token = client.login()
|
||||
self.state['trust_roots'] = [self.state['active_root']]
|
||||
|
||||
Reference in New Issue
Block a user