parent:
4f9fbfd716661e42b7cf2b9f9c44cd9aa9ff450d
nmyk <nick@nmyk.io>
2026-11-14T22:05:13-05:00
add openssl test
diff --git a/DESIGN.md b/DESIGN.md
index f10dd4bc60d98d7e8eba2c74cdbac1f8be07f12b..0e083e89beaa9af7dd1e2c775da68a587412bd99 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -103,6 +103,8 @@ **Strict check.** Plain RFC processing forgives mistakes by deleting code. After policy processing, the interpreter also verifies that certs 2..n assert `anyPolicy` and cert 1 does not, that every explicitly asserted policy in cert *i* is a node at depth *i*, that every mapping in cert *i* produced an edge, and that the program's distinct node ids are exactly 1..N with no gaps. A failure is a ratification error naming the orphaned OID. This turns silent data loss into a compile-style error.
**Denial-of-service guard.** Policy processing has caused real DoS bugs, e.g. Go's CVE-2026-32281 (inefficient policy validation, fixed in Go 1.25.9 / 1.26.2). The graph form keeps work linear in mappings, and the interpreter caps nodes (`--max-nodes`, default 1,000,000), checking the cap as each node is made rather than after. A cap on nodes is not a cap on time, so each cert's work is also kept linear in its level: parents are indexed by the policies they expect, nodes by policy for mappings, and pruning stops at the first level where nothing died. The worst case the cap allows is cheap to reach: every atom above the bottom is copied down once per cert, so a 400 KB file with 6,000 top-level atoms beside one 200-deep form asks for 1.2 million nodes. It is refused in under two seconds.
+**OpenSSL.** OpenSSL is not a full validator for GOVERNMENT. Since CVE-2023-0464 it refuses any policy tree over 1,000 nodes (`OPENSSL_POLICY_TREE_NODES_MAX`, fixed when OpenSSL is built), reporting it as a failed allocation in its policy check. It still builds RFC 5280's tree, which unfolds shared nodes, and every atom above the bottom is copied down once per cert, so a program's tree grows roughly as depth times width: a 31-deep `(+ 1 (+ 1 ...))` fits in 961 nodes, a 32-deep one needs 1,024, and six levels of shared doubling that are a few dozen graph nodes unfold past the limit. Every test program and example fits. Past the limit, a program is still lawful to GOVERNMENT, whose graph budget is a million nodes; OpenSSL just cannot check it.
+
## OID encoding
Every node OID is `GOV.<namespace>.<node-id>.<payload…>`. For a builtin the payload is one arc, its fixed code from the builtin table. For every other node it is the Unicode code points of the node's text, one arc each (so ASCII `A` is arc 65).
@@ -409,7 +411,7 @@ | Round trip | Go test over every `testdata` file | `gov2lisp(lisp2gov(src))` equals the normalized source, comments included |
| Ratification | Go table test that mutates a valid chain | Flipped signature byte, reordered certs, dropped mapping, orphaned policy, mapping in cert n, `anyPolicy` missing from a cert 2..n or asserted in cert 1, a list node with no elements, unknown critical extension; each expects a specific error |
| Civic | Go table test | Runs before, inside and after a `--not-before`/`--not-after` window; repeal of each depth; scheduled repeal; stale CRL; CRL signed by the wrong key; `--anchor` pin across a re-ratified version; notes over 200 characters; default-key warning |
| Golden | `lisp2gov/testdata/golden.gov` and `golden.crl`, from `golden.gov.lisp` | Byte equality with every option fixed (seed, author, dates), so any change to the encoding fails, reported as the block and DER byte where it starts; the program uses every literal kind, a split note, a dotted pair and a shared node, and must also run. `go test ./lisp2gov -update` accepts a deliberate change |
-| External oracle (optional) | `openssl verify -policy_check -explicit_policy -policy 2.5.29.32.0`, plus `-crl_check` | OpenSSL accepts every valid program, rejects broken ones, and agrees on repeals. Without `-policy 2.5.29.32.0` OpenSSL treats the acceptable set as empty |
+| External oracle (optional) | `lisp2gov/openssl_test.go`: `openssl verify -x509_strict -policy_check -explicit_policy -policy 2.5.29.32.0 -policy_print`, plus `-crl_check_all` with repeal CRLs | OpenSSL accepts every test program and example, shared and not, and reports the same top-level policies; it refuses each broken program (tampered, missing depth, foreign anchor, out of force) and each repealed one. Three known disagreements are pinned: scheduled repeals, a list issued after the check time, and OpenSSL's 1,000-node tree limit (see OpenSSL below). Skipped without OpenSSL; `$GOVERNMENT_OPENSSL` picks the binary, since macOS's `openssl` is LibreSSL. Without `-policy 2.5.29.32.0` OpenSSL treats the acceptable set as empty |
Ratification tests are Go rather than Lisp because a Lisp source cannot express a broken certificate.
@@ -433,10 +435,10 @@ - Revoking any cert of the chain breaks it, so revoking one cert repeals the whole program.
- Per RFC 5280, a cert's revocation is published by its issuer. `government repeal` always revokes depth 1, so its CRL is signed by the anchor, with the author's own key: the author strikes down what they ratified.
- `government repeal prog.gov --reason superseded -o repeal.crl` writes that CRL. It needs the program's signing key (see Authorship). The reason is any RFC 5280 CRLReason, e.g. `superseded` or `cessationOfOperation`.
- The checker accepts a CRL from any cert of the chain, as RFC 5280 path validation does, so a hand-made CRL for depth *i*, signed by cert *i−1*, repeals the program too. Every CA cert therefore gets `cRLSign` as well as `keyCertSign`.
-- `government run --crl repeal.crl prog.gov` loads one or more CRL PEM blocks (the flag repeats; `verify`, `tree` and `decompile` take it too). For each CRL it checks that its issuer is a cert of this program (else `E-FOREIGN`), its signature (`RevocationList.CheckSignatureFrom`, else `E-TAMPERED`), and that the check time is not past `nextUpdate`. A check time before `thisUpdate` is allowed: each entry's revocation time already says when the repeal applies, so a newer list can still answer whether the program was in force at an earlier `--at`.
+- `government run --crl repeal.crl prog.gov` loads one or more CRL PEM blocks (the flag repeats; `verify`, `tree` and `decompile` take it too). For each CRL it checks that its issuer is a cert of this program (else `E-FOREIGN`), its signature (`RevocationList.CheckSignatureFrom`, else `E-TAMPERED`), and that the check time is not past `nextUpdate`. A check time before `thisUpdate` is allowed: each entry's revocation time already says when the repeal applies, so a newer list can still answer whether the program was in force at an earlier `--at`. OpenSSL disagrees: it refuses a list that is not yet valid.
- A path cert listed with a revocation time at or before the check time fails: `E-REPEALED: depth 1 repealed 2027-03-01 (superseded)`.
- A CRL past its `nextUpdate` is `E-STALE-REPEALS`. This is a deliberate GOVERNMENT rule: an outdated repeal list fails closed.
-- A future revocation time gives a scheduled repeal. RFC 5280 treats that field as when revocation occurred, so honoring a future time is a GOVERNMENT-specific reading, noted as such.
+- A future revocation time gives a scheduled repeal. RFC 5280 treats that field as when revocation occurred, so honoring a future time is a GOVERNMENT-specific reading, noted as such. OpenSSL ignores the time: a listed cert is revoked, so it refuses a scheduled repeal at once.
- CRLs are always external files. A `.gov` file may still contain only certificates.
### Notes
diff --git a/PLAN.md b/PLAN.md
index 58081db102a996d4e7662939e774b2092c3c98c5..d5d2311d03e2a9db71f7a304cd785154cade0496 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -228,6 +228,6 @@ - Build: generated programs 200 deep (201 certs) and 1,000 arguments wide; `--max-nodes` tests; one checked-in golden `.gov` compared byte for byte.
- Learn: why reproducible output is a security property (anyone can rebuild and compare), and how golden files catch unintended format changes.
- Done when: stress tests finish in under a few seconds, and the golden test fails if any byte of the encoding changes.
39. **OpenSSL as an oracle** (optional, skipped when `openssl` is absent)
- - Build: run `openssl verify -policy_check -explicit_policy -policy 2.5.29.32.0 -x509_strict` (and `-crl_check` with repeal CRLs) on compiled programs and on deliberately broken ones. Without `-policy 2.5.29.32.0`, OpenSSL treats the acceptable set as empty and rejects everything; its `-policy_print` shows only top-level policies, so compare accept/reject decisions, not trees.
+ - Build: run `openssl verify -policy_check -explicit_policy -policy 2.5.29.32.0 -x509_strict` (and `-crl_check_all` with repeal CRLs, plus an empty CRL from every other issuer, which OpenSSL then requires) on compiled programs and on deliberately broken ones. Without `-policy 2.5.29.32.0`, OpenSSL treats the acceptable set as empty and rejects everything; its `-policy_print` shows only top-level policies, so compare accept/reject decisions, not trees.
- Learn: differential testing against an independent implementation; where implementations disagree on edge cases.
- - Done when: OpenSSL accepts every valid program, prints the same set of policies at each depth, and rejects each repealed program. **Milestone: done.**
+ - Done when: OpenSSL accepts every test program and example and prints the same top-level policies (the only ones it prints), rejects each broken and repealed program, and the places it disagrees are pinned by tests: scheduled repeals, a list issued after the check time, and its 1,000-node policy tree limit. **Milestone: done.**
diff --git a/lisp2gov/openssl_test.go b/lisp2gov/openssl_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..8b0bbca97024deac1e8cbffdb6e70ee94cfedf8d
--- /dev/null
+++ b/lisp2gov/openssl_test.go
@@ -0,0 +1,371 @@
+package lisp2gov
+
+import (
+ "bytes"
+ "cmp"
+ "crypto/rand"
+ "crypto/x509"
+ "encoding/pem"
+ "math/big"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "slices"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ "government/program"
+)
+
+// OpenSSL is an independent implementation of the same RFC 5280 path
+// validation, so it should agree with GOVERNMENT on which programs are
+// lawful. These tests compare decisions, not trees: openssl verify prints
+// only the top-level policies. They are skipped when openssl is absent.
+//
+// They also pin down where the two disagree, each for a stated reason, so
+// a change on either side shows up here.
+//
+// $GOVERNMENT_OPENSSL names the binary to use, for a machine whose openssl
+// is something else: macOS ships LibreSSL as openssl, and older LibreSSL
+// cannot verify Ed25519 certificates at all.
+
+var opensslBinary = cmp.Or(os.Getenv("GOVERNMENT_OPENSSL"), "openssl")
+
+func needOpenSSL(t *testing.T) {
+ t.Helper()
+ if _, err := exec.LookPath(opensslBinary); err != nil {
+ t.Skipf("%s not installed", opensslBinary)
+ }
+ out, err := exec.Command(opensslBinary, "version").Output()
+ if err != nil {
+ t.Skipf("%s version: %v", opensslBinary, err)
+ }
+ version := strings.TrimSpace(string(out))
+ if !strings.HasPrefix(version, "OpenSSL ") {
+ t.Skipf("%s is %s, not OpenSSL; set GOVERNMENT_OPENSSL to an OpenSSL binary", opensslBinary, version)
+ }
+ t.Log(version)
+}
+
+type verdict struct {
+ ok bool
+ out string
+}
+
+// opensslVerify runs openssl verify on a chain with the inputs DESIGN.md
+// fixes for GOVERNMENT: explicit policy, anyPolicy as the acceptable set,
+// strict X.509 checks. The anchor is the only trusted cert, the last cert
+// is the one verified, and the rest are untrusted intermediates. With
+// CRLs, every cert in the path is checked, so each issuer needs one.
+func opensslVerify(t *testing.T, anchor *x509.Certificate, path []*x509.Certificate, at time.Time, crls [][]byte) verdict {
+ t.Helper()
+ dir := t.TempDir()
+ write := func(name string, ders ...[]byte) string {
+ var b bytes.Buffer
+ for _, der := range ders {
+ pem.Encode(&b, &pem.Block{Type: "CERTIFICATE", Bytes: der})
+ }
+ p := filepath.Join(dir, name)
+ if err := os.WriteFile(p, b.Bytes(), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ return p
+ }
+ args := []string{"verify", "-x509_strict", "-policy_check", "-explicit_policy",
+ "-policy", "2.5.29.32.0", "-policy_print", "-verify_depth", "1000",
+ "-attime", strconv.FormatInt(at.Unix(), 10),
+ "-CAfile", write("anchor.pem", anchor.Raw)}
+ if len(path) > 1 {
+ var mid [][]byte
+ for _, c := range path[:len(path)-1] {
+ mid = append(mid, c.Raw)
+ }
+ args = append(args, "-untrusted", write("chain.pem", mid...))
+ }
+ if len(crls) > 0 {
+ p := filepath.Join(dir, "crls.pem")
+ if err := os.WriteFile(p, bytes.Join(crls, nil), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ args = append(args, "-crl_check_all", "-CRLfile", p)
+ }
+ args = append(args, write("leaf.pem", path[len(path)-1].Raw))
+ out, err := exec.Command(opensslBinary, args...).CombinedOutput()
+ return verdict{ok: err == nil, out: string(out)}
+}
+
+// authorityPolicies is the policy set openssl verify -policy_print reports:
+// the policies of the first level of its tree, GOVERNMENT's top-level forms.
+func authorityPolicies(out string) []string {
+ _, after, _ := strings.Cut(out, "Authority Policies:")
+ section, _, _ := strings.Cut(after, "User Policies:")
+ var oids []string
+ for _, line := range strings.Split(section, "\n") {
+ if oid, ok := strings.CutPrefix(strings.TrimSpace(line), "Policy: "); ok {
+ oids = append(oids, oid)
+ }
+ }
+ slices.Sort(oids)
+ return oids
+}
+
+func topLevelPolicies(cert1 *x509.Certificate) []string {
+ var oids []string
+ for _, p := range cert1.Policies {
+ oids = append(oids, p.String())
+ }
+ slices.Sort(oids)
+ return oids
+}
+
+func ours(data []byte, at time.Time, crls [][]byte) error {
+ _, err := program.Load(data, program.Options{At: at, CRLs: crls})
+ return err
+}
+
+// TestOpenSSLAcceptsEveryProgram: every test program and example, shared
+// and not, passes OpenSSL's path validation, and OpenSSL finds the same
+// top-level policies the first cert lists.
+func TestOpenSSLAcceptsEveryProgram(t *testing.T) {
+ needOpenSSL(t)
+ paths, _ := filepath.Glob("../testdata/*.gov.lisp")
+ examples, _ := filepath.Glob("../examples/*.gov.lisp")
+ paths = append(append(paths, examples...), "testdata/golden.gov.lisp")
+ at := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
+ for _, path := range paths {
+ src, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, noShare := range []bool{false, true} {
+ name := strings.TrimSuffix(filepath.Base(path), ".gov.lisp")
+ if noShare {
+ name += "/no-share"
+ }
+ t.Run(name, func(t *testing.T) {
+ opts := goldenOpts
+ opts.Name, opts.NoShare = name, noShare
+ data, err := Compile(string(src), opts)
+ if err != nil {
+ t.Fatal(err)
+ }
+ certs := parsePEM(t, data)
+ if err := ours(data, at, nil); err != nil {
+ t.Fatalf("GOVERNMENT refuses it: %v", err)
+ }
+ v := opensslVerify(t, certs[0], certs[1:], at, nil)
+ if !v.ok {
+ t.Fatalf("OpenSSL refuses it:\n%s", v.out)
+ }
+ if got, want := authorityPolicies(v.out), topLevelPolicies(certs[1]); !slices.Equal(got, want) {
+ t.Errorf("OpenSSL's top-level policies %v, want %v", got, want)
+ }
+ })
+ }
+ }
+}
+
+// TestOpenSSLRejectsBrokenPrograms: the mutations GOVERNMENT refuses,
+// OpenSSL refuses too.
+func TestOpenSSLRejectsBrokenPrograms(t *testing.T) {
+ needOpenSSL(t)
+ data, err := Compile("(define sq (lambda (n) (* n n)))\n(sq (+ 1 2))", goldenOpts)
+ if err != nil {
+ t.Fatal(err)
+ }
+ certs := parsePEM(t, data)
+ inForce := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
+ other := [32]byte{'o', 't', 'h', 'e', 'r'}
+ foreignData, err := Compile("1", Options{Seed: &other})
+ if err != nil {
+ t.Fatal(err)
+ }
+ foreign := parsePEM(t, foreignData)
+
+ flipped := slices.Clone(certs)
+ raw := bytes.Clone(certs[2].Raw)
+ raw[len(raw)-2] ^= 1 // inside the signature
+ if flipped[2], err = x509.ParseCertificate(raw); err != nil {
+ t.Fatal(err)
+ }
+
+ tests := []struct {
+ name string
+ anchor *x509.Certificate
+ path []*x509.Certificate
+ at time.Time
+ code string // GOVERNMENT's refusal
+ openssl string // OpenSSL's
+ }{
+ {"flipped signature byte", certs[0], flipped[1:], inForce, "E-TAMPERED", "certificate signature failure"},
+ {"missing depth", certs[0], append(slices.Clone(certs[1:2]), certs[3:]...), inForce, "E-CHAIN", "unable to get local issuer certificate"},
+ {"another author's anchor", foreign[0], certs[1:], inForce, "E-FOREIGN", "unable to get local issuer certificate"},
+ {"before it takes effect", certs[0], certs[1:], goldenOpts.NotBefore.Add(-time.Second), "E-NOT-IN-FORCE", "certificate is not yet valid"},
+ {"after it expires", certs[0], certs[1:], goldenOpts.NotAfter.Add(time.Second), "E-LAPSED", "certificate has expired"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ // GOVERNMENT gets the same chain as one file, and is pinned to
+ // the anchor OpenSSL trusts.
+ var file []byte
+ for _, c := range append([]*x509.Certificate{certs[0]}, tt.path...) {
+ file = append(file, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: c.Raw})...)
+ }
+ _, err := program.Load(file, program.Options{At: tt.at, Pin: pinOf(t, tt.anchor)})
+ if err == nil || !strings.Contains(err.Error(), tt.code) {
+ t.Errorf("GOVERNMENT: %v, want %s", err, tt.code)
+ }
+ if v := opensslVerify(t, tt.anchor, tt.path, tt.at, nil); v.ok || !strings.Contains(v.out, tt.openssl) {
+ t.Errorf("OpenSSL: ok %v, want %q:\n%s", v.ok, tt.openssl, v.out)
+ }
+ })
+ }
+}
+
+func pinOf(t *testing.T, anchor *x509.Certificate) []byte {
+ t.Helper()
+ return anchor.RawSubjectPublicKeyInfo
+}
+
+// emptyCRL is a CRL from the cert at depth that revokes nothing. With
+// -crl_check_all OpenSSL wants one from every issuer in the path before
+// it will accept, where GOVERNMENT checks only the lists it is given.
+func emptyCRL(t *testing.T, certs []*x509.Certificate, depth int, seed [32]byte, last, next time.Time) []byte {
+ t.Helper()
+ der, err := x509.CreateRevocationList(rand.Reader, &x509.RevocationList{
+ Number: big.NewInt(last.Unix()), ThisUpdate: last, NextUpdate: next,
+ }, certs[depth], keyForDepth(seed, depth))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return pem.EncodeToMemory(&pem.Block{Type: "X509 CRL", Bytes: der})
+}
+
+// TestOpenSSLRepeals compares repeal decisions, including the two places
+// GOVERNMENT departs from RFC 5280 on purpose (DESIGN.md, Repeal).
+func TestOpenSSLRepeals(t *testing.T) {
+ needOpenSSL(t)
+ data, err := Compile("(+ 1 (* 2 3))", goldenOpts)
+ if err != nil {
+ t.Fatal(err)
+ }
+ certs := parsePEM(t, data)
+ n := len(certs) - 1
+ jan, mar, jun := time.Date(2030, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2030, 3, 1, 0, 0, 0, 0, time.UTC), time.Date(2030, 6, 1, 0, 0, 0, 0, time.UTC)
+ never := time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC)
+
+ // The issuers below the anchor publish nothing to repeal. OpenSSL needs
+ // their (empty) lists all the same.
+ var quiet [][]byte
+ for d := 1; d < n; d++ {
+ quiet = append(quiet, emptyCRL(t, certs, d, goldenSeed, jan, never))
+ }
+ repeal := func(at, last, next time.Time) [][]byte {
+ crl, err := Repeal(certs, RepealOptions{Seed: &goldenSeed, Reason: 4, At: at, LastUpdate: last, NextUpdate: next})
+ if err != nil {
+ t.Fatal(err)
+ }
+ return append([][]byte{crl}, quiet...)
+ }
+ noRepeal := append([][]byte{emptyCRL(t, certs, 0, goldenSeed, jan, never)}, quiet...)
+
+ tests := []struct {
+ name string
+ crls [][]byte
+ at time.Time
+ ours, openssl string // "" means accepted
+ }{
+ {"nothing repealed", noRepeal, mar, "", ""},
+ {"repealed", repeal(jan, jan, never), mar, "E-REPEALED", "certificate revoked"},
+ {"repeal list gone stale", repeal(jan, jan, mar), jun, "E-STALE-REPEALS", "CRL has expired"},
+
+ // Disagreement 1: GOVERNMENT reads a future revocation time as a
+ // scheduled repeal. RFC 5280 says the field is when revocation
+ // occurred, and OpenSSL ignores it: listed means revoked.
+ {"scheduled, before its date", repeal(jun, jan, never), mar, "", "certificate revoked"},
+ {"scheduled, after its date", repeal(jun, jan, never), jun.Add(time.Hour), "E-REPEALED", "certificate revoked"},
+
+ // Disagreement 2: GOVERNMENT has no lower bound on a list's
+ // thisUpdate, so a newer list can answer for an earlier time.
+ // OpenSSL refuses a list issued after the time it is asked about.
+ {"list issued after the check time", repeal(jun, jun, never), mar, "", "CRL is not yet valid"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ours(data, tt.at, tt.crls)
+ switch {
+ case tt.ours == "" && err != nil:
+ t.Errorf("GOVERNMENT refuses: %v", err)
+ case tt.ours != "" && (err == nil || !strings.Contains(err.Error(), tt.ours)):
+ t.Errorf("GOVERNMENT: %v, want %s", err, tt.ours)
+ }
+ v := opensslVerify(t, certs[0], certs[1:], tt.at, tt.crls)
+ switch {
+ case tt.openssl == "" && !v.ok:
+ t.Errorf("OpenSSL refuses:\n%s", v.out)
+ case tt.openssl != "" && (v.ok || !strings.Contains(v.out, tt.openssl)):
+ t.Errorf("OpenSSL: ok %v, want %q:\n%s", v.ok, tt.openssl, v.out)
+ }
+ })
+ }
+}
+
+// TestOpenSSLTreeLimit is the third disagreement, and the largest. Since
+// CVE-2023-0464, OpenSSL refuses any policy tree over 1,000 nodes, a limit
+// fixed when OpenSSL is built. It still builds RFC 5280's tree, which
+// unfolds shared nodes, and every atom above the bottom is copied down
+// once per cert, so a program's tree grows roughly as depth times width.
+// GOVERNMENT's graph holds a million. Past the limit OpenSSL is no oracle.
+//
+// Under the limit OpenSSL must accept. Over it, it may refuse, but only
+// for the size of its tree; a build without the limit accepts, and the
+// test logs that.
+func TestOpenSSLTreeLimit(t *testing.T) {
+ needOpenSSL(t)
+ doubling := func(k int) string {
+ e := "1"
+ for range k {
+ e = "(+ (* 1 " + e + ") (- " + e + " 0))"
+ }
+ return e
+ }
+ deep := func(d int) string {
+ return strings.Repeat("(+ 1 ", d-1) + "0" + strings.Repeat(")", d-1)
+ }
+ at := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
+ tests := []struct {
+ name, src string
+ underLimit bool
+ }{
+ {"31 deep, 961 nodes", deep(31), true},
+ {"32 deep, 1,024 nodes", deep(32), false},
+ {"200 deep", deep(200), false},
+ {"4 levels of shared doubling", doubling(4), true},
+ {"6 levels of shared doubling, small as a graph", doubling(6), false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ data, err := Compile(tt.src, goldenOpts)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := ours(data, at, nil); err != nil {
+ t.Fatalf("GOVERNMENT refuses: %v", err)
+ }
+ certs := parsePEM(t, data)
+ v := opensslVerify(t, certs[0], certs[1:], at, nil)
+ switch {
+ case v.ok && !tt.underLimit:
+ t.Log("OpenSSL accepts it: this build has no 1,000-node policy tree limit")
+ case !v.ok && tt.underLimit:
+ t.Errorf("OpenSSL refuses a program under its limit:\n%.300s", v.out)
+ case !v.ok && !strings.Contains(v.out, "check_policy"):
+ // OpenSSL reports the limit as a failed allocation in its
+ // policy check; anything else is a real disagreement.
+ t.Errorf("OpenSSL refused for a reason other than its tree limit:\n%.300s", v.out)
+ }
+ })
+ }
+}