Skip to content

Commit fbb4cfe

Browse files
committed
PYTHON-5040 Verify trusted-ca.pem extensions; clarify strict-mode wording
Addresses Copilot review feedback: - gen-certs.py's verify() now checks trusted-ca.pem for critical basicConstraints/keyUsage and absence of AKI/SAN, matching the checks already done for ca.pem, so a future regen that drops these extensions fails loudly instead of silently breaking CA-bundle tests. - README.md reworded to remove the apparent contradiction between the "Certificate details" and "Background" sections about which Python version enables X509_STRICT mode vs. which tightens it further.
1 parent aeee11c commit fbb4cfe

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

test/certificates/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ No AKI or SKI. Adding AKI triggers SecTrust OCSP checks; our CA has no OCSP resp
2424
fail with `CSSMERR_TP_CERT_SUSPENDED`. See Background below.
2525

2626
**KMS certs** — presented by KMS mock servers, verified by Python's ssl module (OpenSSL).
27-
Carry both AKI (keyid form) and SKI. Python 3.13 requires AKI on non-root certs; Python 3.14
28-
sets `X509_V_FLAG_X509_STRICT` in `ssl.create_default_context()`, which additionally requires SKI
29-
and critical `keyUsage` on CA certs.
27+
Carry both AKI (keyid form) and SKI. Python 3.13 enables `X509_V_FLAG_X509_STRICT` in
28+
`ssl.create_default_context()`, which requires AKI on non-root certs; by Python 3.14 (which bundles
29+
a newer OpenSSL) the same strict mode additionally requires SKI on non-root certs and critical
30+
`keyUsage` on CA certs. See Background below for the full version history.
3031

3132
| File | Subject | Signed by | Extensions | Purpose |
3233
|---|---|---|---|---|

test/certificates/gen-certs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,28 @@ def verify() -> int:
372372
if errors == prev_errors:
373373
print(" ca.pem: OK (has basicConstraints critical, keyUsage critical, SKI; no AKI/SAN)")
374374

375+
# Trusted CA (separate root used only by CA-bundle tests) must have critical basicConstraints
376+
# and critical keyUsage; must NOT have AKI or SAN.
377+
trusted_ca_text = cert_text(SCRIPT_DIR / "trusted-ca.pem")
378+
prev_errors = errors
379+
if "Basic Constraints: critical" not in trusted_ca_text:
380+
print(" trusted-ca.pem: ERROR — basicConstraints not critical", file=sys.stderr)
381+
errors += 1
382+
if "Key Usage: critical" not in trusted_ca_text:
383+
print(" trusted-ca.pem: ERROR — missing critical keyUsage", file=sys.stderr)
384+
errors += 1
385+
for ext in ("Authority Key Identifier", "Subject Alternative Name"):
386+
if ext in trusted_ca_text:
387+
print(
388+
f" trusted-ca.pem: ERROR — has {ext} (unexpected on a bare CA-bundle cert)",
389+
file=sys.stderr,
390+
)
391+
errors += 1
392+
if errors == prev_errors:
393+
print(
394+
" trusted-ca.pem: OK (has basicConstraints critical, keyUsage critical; no AKI/SAN)"
395+
)
396+
375397
# MongoDB certs must NOT have AKI.
376398
for name in ("server.pem", "client.pem"):
377399
text = cert_text(SCRIPT_DIR / name)

0 commit comments

Comments
 (0)