omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / tls / test / rev / gen_rev.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # gen_rev.py: test oracle and fixture generator for om/tls/rev.om (not part of the product). |
| 4 | # Writes vectors/pki/*.der (certificates, OCSP responses, CRLs, python cryptography 41.0.7) and |
| 5 | # vectors/cases.txt (driver.om records). Keys are fixed scalars, so certificates and keys are stable; |
| 6 | # ECDSA signatures differ per run. NOW = 2026-10-27T00:00:00Z. |
| 7 | import calendar, datetime as dt, hashlib, os, sys |
| 8 | from cryptography import x509 |
| 9 | from cryptography.x509 import ocsp |
| 10 | from cryptography.x509.oid import NameOID, ExtendedKeyUsageOID |
| 11 | from cryptography.hazmat.primitives import hashes, serialization |
| 12 | from cryptography.hazmat.primitives.asymmetric import ec |
| 13 | |
| 14 | OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "vectors") |
| 15 | PKI = os.path.join(OUT, "pki") |
| 16 | os.makedirs(PKI, exist_ok=True) |
| 17 | NOW = dt.datetime(2026, 10, 27) |
| 18 | NOWU = calendar.timegm(NOW.timetuple()) |
| 19 | H = dt.timedelta(hours=1) |
| 20 | D = dt.timedelta(days=1) |
| 21 | NB = dt.datetime(2026, 1, 1) |
| 22 | NA = dt.datetime(2027, 1, 1) |
| 23 | DP = "http://crl.example.test/iss.crl" |
| 24 | DPX = "http://crl.example.test/other.crl" |
| 25 | |
| 26 | |
| 27 | def key(n): |
| 28 | return ec.derive_private_key(0x5EED0000 + n, ec.SECP256R1()) |
| 29 | |
| 30 | |
| 31 | def name(cn): |
| 32 | return x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, cn)]) |
| 33 | |
| 34 | |
| 35 | def der(obj): |
| 36 | return obj.public_bytes(serialization.Encoding.DER) |
| 37 | |
| 38 | |
| 39 | def save(fn, data): |
| 40 | with open(os.path.join(PKI, fn), "wb") as f: |
| 41 | f.write(data) |
| 42 | return "pki/" + fn |
| 43 | |
| 44 | |
| 45 | def ku(cert_sign=False, crl_sign=False, ds=True): |
| 46 | return x509.KeyUsage(ds, False, False, False, False, cert_sign, crl_sign, False, False) |
| 47 | |
| 48 | |
| 49 | def cert(cn, k, issuer_cn, ik, serial, ca=False, kus=None, eku=None, dp=None, tlsf=False, |
| 50 | nb=NB, na=NA, san=False): |
| 51 | b = (x509.CertificateBuilder().subject_name(name(cn)).issuer_name(name(issuer_cn)) |
| 52 | .public_key(k.public_key()).serial_number(serial).not_valid_before(nb).not_valid_after(na) |
| 53 | .add_extension(x509.BasicConstraints(ca=ca, path_length=0 if ca and issuer_cn != cn else None), |
| 54 | critical=True)) |
| 55 | if kus is not None: |
| 56 | b = b.add_extension(kus, critical=True) |
| 57 | if eku is not None: |
| 58 | b = b.add_extension(x509.ExtendedKeyUsage(eku), critical=False) |
| 59 | if dp is not None: |
| 60 | b = b.add_extension(x509.CRLDistributionPoints([x509.DistributionPoint( |
| 61 | [x509.UniformResourceIdentifier(dp)], None, None, None)]), critical=False) |
| 62 | if tlsf: |
| 63 | b = b.add_extension(x509.TLSFeature([x509.TLSFeatureType.status_request]), critical=False) |
| 64 | if san: |
| 65 | b = b.add_extension(x509.SubjectAlternativeName([x509.DNSName("www.example.test")]), |
| 66 | critical=False) |
| 67 | return b.sign(ik, hashes.SHA256()) |
| 68 | |
| 69 | |
| 70 | kR, kI, kB, kL, kO = key(1), key(2), key(3), key(4), key(5) |
| 71 | root = cert("Rev Test Root", kR, "Rev Test Root", kR, 1, ca=True, kus=ku(True, True, False), |
| 72 | na=dt.datetime(2036, 1, 1)) |
| 73 | iss = cert("Rev Test Issuer", kI, "Rev Test Root", kR, 2, ca=True, kus=ku(True, True, True)) |
| 74 | issB = cert("Rev Test Issuer B", kB, "Rev Test Root", kR, 3, ca=True, kus=ku(True, False, True)) |
| 75 | SAUTH = [ExtendedKeyUsageOID.SERVER_AUTH] |
| 76 | leaf = cert("www.example.test", kL, "Rev Test Issuer", kI, 0x1001, kus=ku(), eku=SAUTH, dp=DP, san=True) |
| 77 | leafMS = cert("www.example.test", kL, "Rev Test Issuer", kI, 0x1002, kus=ku(), eku=SAUTH, dp=DP, |
| 78 | tlsf=True, san=True) |
| 79 | leafND = cert("www.example.test", kL, "Rev Test Issuer", kI, 0x1003, kus=ku(), eku=SAUTH, san=True) |
| 80 | BIG = (1 << 158) + 0x8F12345 |
| 81 | leafBig = cert("www.example.test", kL, "Rev Test Issuer", kI, BIG, kus=ku(), eku=SAUTH, dp=DP, san=True) |
| 82 | leafB = cert("www.example.test", kL, "Rev Test Issuer B", kB, 0x2001, kus=ku(), eku=SAUTH, san=True) |
| 83 | OSIGN = [ExtendedKeyUsageOID.OCSP_SIGNING] |
| 84 | resp = cert("Rev OCSP Responder", kO, "Rev Test Issuer", kI, 0x3001, kus=ku(), eku=OSIGN) |
| 85 | respNE = cert("Rev OCSP Responder", kO, "Rev Test Issuer", kI, 0x3002, kus=ku()) |
| 86 | respRoot = cert("Rev OCSP Responder", kO, "Rev Test Root", kR, 0x3003, kus=ku(), eku=OSIGN) |
| 87 | respExp = cert("Rev OCSP Responder", kO, "Rev Test Issuer", kI, 0x3004, kus=ku(), eku=OSIGN, |
| 88 | na=dt.datetime(2026, 6, 1)) |
| 89 | |
| 90 | F = {} |
| 91 | for n, c in [("root", root), ("iss", iss), ("issB", issB), ("leaf", leaf), ("leafMS", leafMS), |
| 92 | ("leafND", leafND), ("leafBig", leafBig), ("leafB", leafB), ("resp", resp), |
| 93 | ("respNE", respNE), ("respRoot", respRoot), ("respExp", respExp)]: |
| 94 | F[n] = save(n + ".der", der(c)) |
| 95 | with open(os.path.join(PKI, "store.pem"), "wb") as f: |
| 96 | f.write(root.public_bytes(serialization.Encoding.PEM)) |
| 97 | |
| 98 | |
| 99 | def ocspr(fn, subj=leaf, status=ocsp.OCSPCertStatus.GOOD, tu=NOW - H, nu=NOW + 3 * D, alg=hashes.SHA1(), |
| 100 | signer=iss, sk=kI, enc=ocsp.OCSPResponderEncoding.NAME, certs=None, ext=None, issuer=iss): |
| 101 | b = ocsp.OCSPResponseBuilder().add_response( |
| 102 | cert=subj, issuer=issuer, algorithm=alg, cert_status=status, this_update=tu, next_update=nu, |
| 103 | revocation_time=NOW - 10 * D if status == ocsp.OCSPCertStatus.REVOKED else None, |
| 104 | revocation_reason=x509.ReasonFlags.key_compromise if status == ocsp.OCSPCertStatus.REVOKED else None) |
| 105 | b = b.responder_id(enc, signer) |
| 106 | if certs: |
| 107 | b = b.certificates(certs) |
| 108 | if ext is not None: |
| 109 | b = b.add_extension(ext[0], critical=ext[1]) |
| 110 | r = b.sign(sk, hashes.SHA256()) |
| 111 | return save(fn, r.public_bytes(serialization.Encoding.DER)) |
| 112 | |
| 113 | |
| 114 | def flip_last(path, delta=1): |
| 115 | p = os.path.join(OUT, path) |
| 116 | d = bytearray(open(p, "rb").read()) |
| 117 | d[-1] ^= delta |
| 118 | open(p, "wb").write(bytes(d)) |
| 119 | return path |
| 120 | |
| 121 | |
| 122 | GOOD, REVOKED, UNKNOWN = ocsp.OCSPCertStatus.GOOD, ocsp.OCSPCertStatus.REVOKED, ocsp.OCSPCertStatus.UNKNOWN |
| 123 | S = {} |
| 124 | S["good"] = ocspr("o_good.der") |
| 125 | S["good_bykey"] = ocspr("o_good_bykey.der", enc=ocsp.OCSPResponderEncoding.HASH) |
| 126 | S["good_sha256"] = ocspr("o_good_sha256.der", alg=hashes.SHA256()) |
| 127 | S["good_nonce"] = ocspr("o_good_nonce.der", ext=(x509.OCSPNonce(b"0123456789abcdef"), False)) |
| 128 | S["crit_nonce"] = ocspr("o_crit_nonce.der", ext=(x509.OCSPNonce(b"0123456789abcdef"), True)) |
| 129 | S["revoked"] = ocspr("o_revoked.der", status=REVOKED) |
| 130 | S["revoked_stale"] = ocspr("o_revoked_stale.der", status=REVOKED, tu=NOW - 5 * D, nu=NOW - D) |
| 131 | S["unknown"] = ocspr("o_unknown.der", status=UNKNOWN) |
| 132 | S["stale"] = ocspr("o_stale.der", tu=NOW - 5 * D, nu=NOW - H) |
| 133 | S["stale_edge"] = ocspr("o_stale_edge.der", tu=NOW - 5 * D, nu=NOW) |
| 134 | S["future"] = ocspr("o_future.der", tu=NOW + 301 * dt.timedelta(seconds=1)) |
| 135 | S["skew_ok"] = ocspr("o_skew_ok.der", tu=NOW + 300 * dt.timedelta(seconds=1)) |
| 136 | S["no_next"] = ocspr("o_no_next.der", nu=None) |
| 137 | S["other_serial"] = ocspr("o_other_serial.der", subj=leafND) |
| 138 | S["other_issuer"] = ocspr("o_other_issuer.der", subj=leafB, issuer=issB, signer=issB, sk=kB) |
| 139 | S["bad_sig"] = flip_last(ocspr("o_bad_sig.der")) |
| 140 | issR = cert("Rev Test Issuer", kR, "Rev Test Root", kR, 9, ca=True, kus=ku(True, True, True)) |
| 141 | S["wrong_key"] = ocspr("o_wrong_key.der", signer=issR, sk=kR) |
| 142 | S["deleg"] = ocspr("o_deleg.der", signer=resp, sk=kO, certs=[resp]) |
| 143 | S["deleg_bykey"] = ocspr("o_deleg_bykey.der", signer=resp, sk=kO, certs=[resp], |
| 144 | enc=ocsp.OCSPResponderEncoding.HASH) |
| 145 | S["deleg_revoked"] = ocspr("o_deleg_revoked.der", status=REVOKED, signer=resp, sk=kO, certs=[resp]) |
| 146 | S["deleg_noeku"] = ocspr("o_deleg_noeku.der", signer=respNE, sk=kO, certs=[respNE]) |
| 147 | S["deleg_root"] = ocspr("o_deleg_root.der", signer=respRoot, sk=kO, certs=[respRoot]) |
| 148 | S["deleg_expired"] = ocspr("o_deleg_expired.der", signer=respExp, sk=kO, certs=[respExp]) |
| 149 | S["deleg_nocert"] = ocspr("o_deleg_nocert.der", signer=resp, sk=kO) |
| 150 | S["ms_good"] = ocspr("o_ms_good.der", subj=leafMS) |
| 151 | S["big_good"] = ocspr("o_big_good.der", subj=leafBig) |
| 152 | S["big_revoked"] = ocspr("o_big_revoked.der", subj=leafBig, status=REVOKED) |
| 153 | S["trylater"] = save("o_trylater.der", ocsp.OCSPResponseBuilder.build_unsuccessful( |
| 154 | ocsp.OCSPResponseStatus.TRY_LATER).public_bytes(serialization.Encoding.DER)) |
| 155 | S["unauth"] = save("o_unauth.der", ocsp.OCSPResponseBuilder.build_unsuccessful( |
| 156 | ocsp.OCSPResponseStatus.UNAUTHORIZED).public_bytes(serialization.Encoding.DER)) |
| 157 | S["garbage"] = save("o_garbage.der", b"\x30\x03\x0a\x01\x00") |
| 158 | |
| 159 | |
| 160 | def crl(fn, serials=(0x1004, 0x1005), lu=NOW - H, nu=NOW + 7 * D, ik=kI, iname="Rev Test Issuer", |
| 161 | idp=None, delta=False, entry_ext=None, nonext=False): |
| 162 | b = (x509.CertificateRevocationListBuilder().issuer_name(name(iname)).last_update(lu)) |
| 163 | if nu is not None: |
| 164 | b = b.next_update(nu) |
| 165 | for s in serials: |
| 166 | rb = x509.RevokedCertificateBuilder().serial_number(s).revocation_date(NOW - 2 * D) |
| 167 | if entry_ext is not None: |
| 168 | rb = rb.add_extension(entry_ext[0], critical=entry_ext[1]) |
| 169 | b = b.add_revoked_certificate(rb.build()) |
| 170 | if not nonext: |
| 171 | b = b.add_extension(x509.CRLNumber(7), critical=False) |
| 172 | if idp is not None: |
| 173 | b = b.add_extension(idp, critical=True) |
| 174 | if delta: |
| 175 | b = b.add_extension(x509.DeltaCRLIndicator(6), critical=True) |
| 176 | return save(fn, b.sign(ik, hashes.SHA256()).public_bytes(serialization.Encoding.DER)) |
| 177 | |
| 178 | |
| 179 | def idp(uri=DP, users=False, cas=False): |
| 180 | return x509.IssuingDistributionPoint([x509.UniformResourceIdentifier(uri)], None, users, cas, None, |
| 181 | False, False) |
| 182 | |
| 183 | |
| 184 | C = {} |
| 185 | C["revoked"] = crl("c_revoked.der", serials=(0x1004, 0x1001, 0x1005)) |
| 186 | C["clean"] = crl("c_clean.der") |
| 187 | C["empty"] = crl("c_empty.der", serials=()) |
| 188 | C["v1"] = crl("c_v1.der", serials=(0x1001,), nonext=True) |
| 189 | C["stale"] = crl("c_stale.der", lu=NOW - 9 * D, nu=NOW - D) |
| 190 | C["future"] = crl("c_future.der", lu=NOW + D) |
| 191 | C["wrong_name"] = crl("c_wrong_name.der", iname="Rev Test Other") |
| 192 | C["root_signed"] = crl("c_root_signed.der", ik=kR, iname="Rev Test Root", serials=(0x1001,)) |
| 193 | C["bad_sig"] = flip_last(crl("c_bad_sig.der", serials=(0x1001,))) |
| 194 | C["idp_match"] = crl("c_idp_match.der", idp=idp()) |
| 195 | C["idp_match_rev"] = crl("c_idp_match_rev.der", idp=idp(users=True), serials=(0x1001,)) |
| 196 | C["idp_other"] = crl("c_idp_other.der", idp=idp(DPX)) |
| 197 | C["idp_onlyca"] = crl("c_idp_onlyca.der", idp=idp(cas=True)) |
| 198 | C["delta"] = crl("c_delta.der", delta=True) |
| 199 | C["entry_reason"] = crl("c_entry_reason.der", serials=(0x1001,), |
| 200 | entry_ext=(x509.CRLReason(x509.ReasonFlags.key_compromise), False)) |
| 201 | C["entry_ci"] = crl("c_entry_ci.der", serials=(0x1001,), |
| 202 | entry_ext=(x509.CertificateIssuer([x509.DNSName("other.test")]), True)) |
| 203 | C["big"] = crl("c_big.der", serials=(0x1001, BIG)) |
| 204 | C["issB"] = crl("c_issB.der", ik=kB, iname="Rev Test Issuer B", serials=(0x2001,)) |
| 205 | |
| 206 | L, I, LM, LN, LG, LB = F["leaf"], F["iss"], F["leafMS"], F["leafND"], F["leafBig"], F["leafB"] |
| 207 | OK = "X509_OK" |
| 208 | cases = [ |
| 209 | ("O", "ocsp_good", OK, L, I, S["good"], "-"), |
| 210 | ("O", "ocsp_good_bykey", OK, L, I, S["good_bykey"], "-"), |
| 211 | ("O", "ocsp_good_sha256_certid", OK, L, I, S["good_sha256"], "-"), |
| 212 | ("O", "ocsp_good_nonce_ext", OK, L, I, S["good_nonce"], "-"), |
| 213 | ("O", "ocsp_critical_nonce", "X509_ERR_CRITICAL_EXT", L, I, S["crit_nonce"], "-"), |
| 214 | ("O", "ocsp_revoked", "REV_ERR_REVOKED", L, I, S["revoked"], "-"), |
| 215 | ("O", "ocsp_revoked_beats_stale", "REV_ERR_REVOKED", L, I, S["revoked_stale"], "-"), |
| 216 | ("O", "ocsp_unknown", "REV_ERR_STATUS_UNKNOWN", L, I, S["unknown"], "-"), |
| 217 | ("O", "ocsp_stale", "REV_ERR_STALE", L, I, S["stale"], "-"), |
| 218 | ("O", "ocsp_next_update_equals_now", "REV_ERR_STALE", L, I, S["stale_edge"], "-"), |
| 219 | ("O", "ocsp_future_301s", "REV_ERR_STALE", L, I, S["future"], "-"), |
| 220 | ("O", "ocsp_future_300s_skew", OK, L, I, S["skew_ok"], "-"), |
| 221 | ("O", "ocsp_no_next_update", "REV_ERR_STALE", L, I, S["no_next"], "-"), |
| 222 | ("O", "ocsp_other_serial", "REV_ERR_STATUS_UNKNOWN", L, I, S["other_serial"], "-"), |
| 223 | ("O", "ocsp_other_issuer", "REV_ERR_RESPONDER", L, I, S["other_issuer"], "-"), |
| 224 | ("O", "ocsp_bad_sig", "X509_ERR_BAD_SIGNATURE", L, I, S["bad_sig"], "-"), |
| 225 | ("O", "ocsp_wrong_key", "X509_ERR_BAD_SIGNATURE", L, I, S["wrong_key"], "-"), |
| 226 | ("O", "ocsp_delegated", OK, L, I, S["deleg"], "-"), |
| 227 | ("O", "ocsp_delegated_bykey", OK, L, I, S["deleg_bykey"], "-"), |
| 228 | ("O", "ocsp_delegated_revoked", "REV_ERR_REVOKED", L, I, S["deleg_revoked"], "-"), |
| 229 | ("O", "ocsp_delegated_no_eku", "REV_ERR_RESPONDER", L, I, S["deleg_noeku"], "-"), |
| 230 | ("O", "ocsp_delegated_by_root", "REV_ERR_RESPONDER", L, I, S["deleg_root"], "-"), |
| 231 | ("O", "ocsp_delegated_expired", "REV_ERR_RESPONDER", L, I, S["deleg_expired"], "-"), |
| 232 | ("O", "ocsp_delegated_cert_missing", "REV_ERR_RESPONDER", L, I, S["deleg_nocert"], "-"), |
| 233 | ("O", "ocsp_try_later", "REV_ERR_OCSP_STATUS", L, I, S["trylater"], "-"), |
| 234 | ("O", "ocsp_unauthorized", "REV_ERR_OCSP_STATUS", L, I, S["unauth"], "-"), |
| 235 | ("O", "ocsp_garbage", "X509_ERR_MALFORMED", L, I, S["garbage"], "-"), |
| 236 | ("O", "ocsp_big_serial_good", OK, LG, I, S["big_good"], "-"), |
| 237 | ("O", "ocsp_big_serial_revoked", "REV_ERR_REVOKED", LG, I, S["big_revoked"], "-"), |
| 238 | ("O", "ocsp_staple_for_other_leaf", "REV_ERR_STATUS_UNKNOWN", LG, I, S["good"], "-"), |
| 239 | ("O", "must_staple_missing", "REV_ERR_NO_STAPLE", LM, I, "-", "-"), |
| 240 | ("O", "must_staple_missing_crl_clean", "REV_ERR_NO_STAPLE", LM, I, "-", C["clean"]), |
| 241 | ("O", "must_staple_good", OK, LM, I, S["ms_good"], "-"), |
| 242 | ("O", "must_staple_wrong_staple", "REV_ERR_STATUS_UNKNOWN", LM, I, S["good"], "-"), |
| 243 | ("O", "no_staple_no_crl_soft", OK, L, I, "-", "-"), |
| 244 | ("O", "crl_revoked", "REV_ERR_REVOKED", L, I, "-", C["revoked"]), |
| 245 | ("O", "crl_clean", OK, L, I, "-", C["clean"]), |
| 246 | ("O", "crl_empty_list", OK, L, I, "-", C["empty"]), |
| 247 | ("O", "crl_v1_listed", "REV_ERR_REVOKED", L, I, "-", C["v1"]), |
| 248 | ("O", "crl_stale", "REV_ERR_STALE", L, I, "-", C["stale"]), |
| 249 | ("O", "crl_future", "REV_ERR_STALE", L, I, "-", C["future"]), |
| 250 | ("O", "crl_wrong_issuer_name", "REV_ERR_CRL_SCOPE", L, I, "-", C["wrong_name"]), |
| 251 | ("O", "crl_signed_by_root", "X509_ERR_BAD_SIGNATURE", L, I, "-", C["root_signed"]), |
| 252 | ("O", "crl_bad_sig", "X509_ERR_BAD_SIGNATURE", L, I, "-", C["bad_sig"]), |
| 253 | ("O", "crl_idp_match_clean", OK, L, I, "-", C["idp_match"]), |
| 254 | ("O", "crl_idp_match_revoked", "REV_ERR_REVOKED", L, I, "-", C["idp_match_rev"]), |
| 255 | ("O", "crl_idp_other_dp", "REV_ERR_CRL_SCOPE", L, I, "-", C["idp_other"]), |
| 256 | ("O", "crl_idp_leaf_without_dp", "REV_ERR_CRL_SCOPE", LN, I, "-", C["idp_match"]), |
| 257 | ("O", "crl_idp_only_ca", "REV_ERR_CRL_SCOPE", L, I, "-", C["idp_onlyca"]), |
| 258 | ("O", "crl_delta", "REV_ERR_CRL_SCOPE", L, I, "-", C["delta"]), |
| 259 | ("O", "crl_entry_reason", "REV_ERR_REVOKED", L, I, "-", C["entry_reason"]), |
| 260 | ("O", "crl_entry_cert_issuer", "REV_ERR_CRL_SCOPE", L, I, "-", C["entry_ci"]), |
| 261 | ("O", "crl_big_serial_revoked", "REV_ERR_REVOKED", LG, I, "-", C["big"]), |
| 262 | ("O", "crl_big_serial_other", OK, LN, I, "-", C["big"]), |
| 263 | ("O", "crl_issuer_without_crlsign", "X509_ERR_KEY_USAGE", LB, F["issB"], "-", C["issB"]), |
| 264 | ("O", "staple_good_crl_revoked", "REV_ERR_REVOKED", L, I, S["good"], C["revoked"]), |
| 265 | ("O", "staple_revoked_crl_clean", "REV_ERR_REVOKED", L, I, S["revoked"], C["clean"]), |
| 266 | ] |
| 267 | |
| 268 | # Real Let's Encrypt CRL: real/ye2-74.crl (http://ye2.c.lencr.org/74.crl, thisUpdate |
| 269 | # 2026-10-26T23:03:21Z, 1575 entries) and its real issuer real/ye2.der |
| 270 | # (https://letsencrypt.org/certs/gen-y/int-ye2.der). The leaves are synthetic: issuer Name copied |
| 271 | # from YE2, the CRL's distribution point, a listed serial (or an unlisted one), signed by a test key |
| 272 | # (rev.om does not check the leaf signature; x509_chain_verify does that before it). |
| 273 | ye2 = x509.load_der_x509_certificate(open(os.path.join(OUT, "real", "ye2.der"), "rb").read()) |
| 274 | |
| 275 | |
| 276 | def leye2(fn, serial, dp): |
| 277 | c = (x509.CertificateBuilder().subject_name(name("www.example.test")).issuer_name(ye2.subject) |
| 278 | .public_key(kL.public_key()).serial_number(serial).not_valid_before(NB).not_valid_after(NA) |
| 279 | .add_extension(x509.BasicConstraints(ca=False, path_length=None), critical=True) |
| 280 | .add_extension(x509.CRLDistributionPoints([x509.DistributionPoint( |
| 281 | [x509.UniformResourceIdentifier(dp)], None, None, None)]), critical=False) |
| 282 | .sign(kI, hashes.SHA256())) |
| 283 | return save(fn, der(c)) |
| 284 | |
| 285 | |
| 286 | YE = "real/ye2.der" |
| 287 | YC = "real/ye2-74.crl" |
| 288 | cases += [ |
| 289 | ("O", "le_crl_listed_serial", "REV_ERR_REVOKED", |
| 290 | leye2("leYE2rev.der", 0x050A72B7AE90C2E1C61BB7D1568032F79549, "http://ye2.c.lencr.org/74.crl"), |
| 291 | YE, "-", YC), |
| 292 | ("O", "le_crl_unlisted_serial", OK, |
| 293 | leye2("leYE2ok.der", 0x050A72B7AE90C2E1C61BB7D1568032F7954A, "http://ye2.c.lencr.org/74.crl"), |
| 294 | YE, "-", YC), |
| 295 | ("O", "le_crl_other_shard", "REV_ERR_CRL_SCOPE", |
| 296 | leye2("leYE2shard.der", 0x050A72B7AE90C2E1C61BB7D1568032F79549, "http://ye2.c.lencr.org/75.crl"), |
| 297 | YE, "-", YC), |
| 298 | ("O", "le_crl_wrong_issuer_key", "X509_ERR_BAD_SIGNATURE", "pki/leYE2rev.der", I, "-", YC), |
| 299 | ] |
| 300 | lines = ["# om/tls/rev.om test cases (driver.om records; generated by ../gen_rev.py, do not edit).", |
| 301 | "# NOW = %d = 2026-10-27T00:00:00Z. Test certificates valid 2026-01-01 .. 2027-01-01." % NOWU] |
| 302 | for c in cases: |
| 303 | lines.append("O %s %s %d %s %s %s %s" % (c[1], c[2], NOWU, c[3], c[4], c[5], c[6])) |
| 304 | lines.append("O now_after_9999 X509_ERR_MALFORMED 253402300800 %s %s %s -" % (L, I, S["good"])) |
| 305 | lines.append("O le_crl_after_next_update REV_ERR_REVOKED %d pki/leYE2rev.der %s - %s" % ( |
| 306 | calendar.timegm(dt.datetime(2026, 11, 5).timetuple()), YE, YC)) |
| 307 | lines.append("O le_crl_before_this_update REV_ERR_REVOKED %d pki/leYE2rev.der %s - %s" % ( |
| 308 | calendar.timegm(dt.datetime(2026, 10, 26, 22).timetuple()), YE, YC)) |
| 309 | lines.append("O le_crl_unlisted_after_next_update REV_ERR_STALE %d pki/leYE2ok.der %s - %s" % ( |
| 310 | calendar.timegm(dt.datetime(2026, 11, 5).timetuple()), YE, YC)) |
| 311 | lines.append("G fuzz_le_crl 200 %d pki/leYE2rev.der %s %s" % (NOWU, YE, YC)) |
| 312 | for n, w, f in [("mustst_leaf", "1", LM), ("mustst_plain", "0", L), ("mustst_issuer", "0", I)]: |
| 313 | lines.append("U %s %s %s" % (n, w, f)) |
| 314 | lines.append("I issuer_from_list %s pki/store.pem %s %s" % (I, L, I)) |
| 315 | lines.append("I issuer_after_unrelated %s pki/store.pem %s %s %s" % (I, L, F["issB"], I)) |
| 316 | lines.append("I issuer_absent - pki/store.pem %s %s" % (L, F["issB"])) |
| 317 | lines.append("I issuer_from_store %s pki/store.pem %s" % (F["root"], I)) |
| 318 | for m in [b"", b"abc", b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
| 319 | bytes(range(256)) * 3]: |
| 320 | lines.append("H sha1_len%d %s %s" % (len(m), m.hex() or "-", hashlib.sha1(m).hexdigest())) |
| 321 | lines.append("A sha1_million_a 1000000 97 %s" % hashlib.sha1(b"a" * 1000000).hexdigest()) |
| 322 | for code, nm in enumerate(["REV_ERR_REVOKED", "REV_ERR_STATUS_UNKNOWN", "REV_ERR_STALE", |
| 323 | "REV_ERR_NO_STAPLE", "REV_ERR_RESPONDER", "REV_ERR_OCSP_STATUS", |
| 324 | "REV_ERR_CRL_SCOPE"]): |
| 325 | lines.append("E errname_%d %s %d" % (32 + code, nm, 32 + code)) |
| 326 | lines.append("E errname_6 X509_ERR_BAD_SIGNATURE 6") |
| 327 | lines.append("E errname_39 - 39") |
| 328 | lines.append("F fuzz_staple_good 400 %d %s %s %s" % (NOWU, L, I, S["good"])) |
| 329 | lines.append("F fuzz_staple_deleg 400 %d %s %s %s" % (NOWU, L, I, S["deleg"])) |
| 330 | lines.append("G fuzz_crl_revoked 400 %d %s %s %s" % (NOWU, L, I, C["revoked"])) |
| 331 | with open(os.path.join(OUT, "cases.txt"), "w") as f: |
| 332 | f.write("\n".join(lines) + "\n") |
| 333 | print("gen_rev: %d records" % (len(lines) - 2)) |