forked from mtusi2026/mtusi2026lab7
fix(security): scope row locks and add explicit expiry recovery
This commit is contained in:
@@ -102,3 +102,55 @@ def test_operator_leaf_install_preserves_pem_and_matching_pair(
|
||||
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
context.load_cert_chain(current / "cert.pem", current / "key.pem")
|
||||
assert (current / "key.pem").stat().st_mode & 0o777 == 0o600
|
||||
|
||||
|
||||
def test_bootstrap_renews_when_replacement_ca_has_the_same_subject(
|
||||
tmp_path, monkeypatch
|
||||
):
|
||||
from cryptography import x509
|
||||
|
||||
from scripts import bootstrap_security as bootstrap
|
||||
|
||||
monkeypatch.setattr(bootstrap, "OPERATOR", tmp_path / "operator")
|
||||
monkeypatch.setattr(bootstrap, "SECRET", tmp_path / "secrets")
|
||||
monkeypatch.setattr(bootstrap, "TRUST", tmp_path / "trust")
|
||||
bootstrap.generate()
|
||||
original = (bootstrap.OPERATOR / "service-secrets.json").read_bytes()
|
||||
_, old_ca = bootstrap.ca()
|
||||
new_key, new_ca = bootstrap.make_root()
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
|
||||
builder = (
|
||||
x509.CertificateBuilder()
|
||||
.subject_name(old_ca.subject)
|
||||
.issuer_name(old_ca.subject)
|
||||
.public_key(new_key.public_key())
|
||||
.serial_number(x509.random_serial_number())
|
||||
.not_valid_before(new_ca.not_valid_before_utc)
|
||||
.not_valid_after(new_ca.not_valid_after_utc)
|
||||
)
|
||||
for extension in new_ca.extensions:
|
||||
builder = builder.add_extension(extension.value, extension.critical)
|
||||
new_ca = builder.sign(new_key, hashes.SHA256())
|
||||
assert old_ca.subject == new_ca.subject
|
||||
bootstrap.write_private(
|
||||
bootstrap.OPERATOR / "ca-key.pem", bootstrap.key_bytes(new_key)
|
||||
)
|
||||
bootstrap.write_private(
|
||||
bootstrap.OPERATOR / "ca.pem", bootstrap.public(new_ca)
|
||||
)
|
||||
bootstrap.write_private(
|
||||
bootstrap.TRUST / "ca.pem", bootstrap.public(new_ca), mode=0o644
|
||||
)
|
||||
bootstrap.generate()
|
||||
for directory in [
|
||||
bootstrap.SECRET / "bootstrap/api",
|
||||
bootstrap.OPERATOR / "client",
|
||||
]:
|
||||
leaf = x509.load_pem_x509_certificate(
|
||||
(directory / "cert.pem").read_bytes()
|
||||
)
|
||||
leaf.verify_directly_issued_by(new_ca)
|
||||
assert (
|
||||
bootstrap.OPERATOR / "service-secrets.json"
|
||||
).read_bytes() == original
|
||||
|
||||
Reference in New Issue
Block a user