| |
/ \ / \
/ \ / \
(_____) (_____)
| | _ _ _ | |
| O |_| |_| |_| |_| O |
|- | | - |
| | GOVERNMENT | |
| - | _ | |
| | - _^_ | |
| _| //|\\ - | |
| | ///|\\\ | -|
|- |_ ||||||| | |
| | ||||||| |- |
|___|___|||||||___|___|
( (
\ \
) )
| |
( (
\ \
GOVERNMENT is a Lisp whose programs are written as X.509 certificate chains.
The interpreter validates the chain as an X.509 certification path, then reads its certificate policies as the program and evaluates them. If the chain does not validate, the program does not run.
Each expression in a program is one certificate policy OID. Each pair of parentheses is a set of policy mappings. The program's nesting depth is the length of the chain.
Run:
go install nmyk.io/government/cmd/government@latest go install nmyk.io/government/cmd/govlisp@latest
Alternatively, compile from source:
git clone https://git.nmyk.io/government.git cd government make install
government compiles, checks, inspects, runs and repeals .gov files.
govlisp runs GovLisp source directly, with no certificates, and has an interactive REPL.
; The square of a number. (def square (fn (n) (* n n))) (square 12)
openssl crl2pkcs7 -nocrl -certfile square.gov |\ openssl pkcs7 -print_certs -text -noout
| Command | Does |
|---|---|
| government example.gov | Ratify, decode and run the program. government run example.gov is the long form. |
| government verify example.gov | Ratify and decode the program without running it, and print its certificate of ratification. |
| government tree example.gov | Print the policy tree, with notes, then the tree of each archive the file bundles. |
| government decompile example.gov | Print the GovLisp source, with notes as comments and bundled archives written in. |
| government compile example.gov.lisp | Compile a program to example.gov, or to the file -o names. |
| government repeal example.gov -o repeal.crl | Write a CRL that repeals a program, or with --import, one of its imports. |
| govlisp | Start the REPL. |
| govlisp example.gov.lisp | Run GovLisp source, with no certificates. |
A file name of - means standard input, and -o - means standard output, so commands can be piped:
government compile example.gov.lisp -o - | government run -
A .gov file contains a series of PEM CERTIFICATE blocks: a trust anchor, then one certificate for each depth of the program. The compiler writes the anchor first, but the interpreter accepts the certificates in any order, because each signature links a certificate to its parent. A file can also bundle the archives that a program imports, each a chain of its own: see Archives.
Every node OID has the form GOV.<id>.<type>, followed by a payload for the types that need one. GOV is 2.25.4673366: the value 0x474F56 ("GOV" in ASCII) under the UUID arc 2.25. Types below 128 take one byte, and the functions from 128 on take two.
| Type | Kind | Payload | Source | OID |
|---|---|---|---|---|
| 0 | List | None | (a b) | GOV.<id>.0 |
| 2 | Symbol | The name's code points | foo | GOV.<id>.2.102.111.111 |
| 3 | Integer | The value, zigzag encoded | -42 | GOV.<id>.3.83 |
| 4 | Float | Decimal mantissa with sign, then exponent | 3.14 | GOV.<id>.4.628.3 |
| 5 | String | The string's code points | "hi" | GOV.<id>.5.104.105 |
| 6 | Byte string | The bytes | #"hi" | GOV.<id>.6.104.105 |
| 16-31 | Constant | None | T | GOV.<id>.16 |
| 32-63 | Special form | None | if | GOV.<id>.33 |
| 64-127 | Function | None | + | GOV.<id>.65 |
| 128- | Function | None | $f | GOV.<id>.128 |
IDs are unique within a program. A certificate's policies are an unordered set, so the IDs are what determine argument order.
The interpreter runs these checks before anything else. If one fails, the program does not run and the exit code is 2.
| Error | Cause |
|---|---|
| E-MALFORMED | The file is not valid PEM, or holds a block that is not a certificate. |
| E-CHAIN | The certificates do not sort into chains, or one has a forbidden extension. |
| E-TAMPERED | A signature does not verify. |
| E-FOREIGN | The anchor's key does not match --anchor, or a CRL comes from another program. |
| E-NOT-IN-FORCE | The check time is before the program takes effect. |
| E-LAPSED | The check time is after the program expires. |
| E-REPEALED | A CRL revokes one of the program's certificates, an archive's, or an import. |
| E-STALE-REPEALS | A CRL is past its next update time. |
| E-POLICY | The policies do not form a valid program, for example because a node is missing. |
| E-TOO-LARGE | The policy graph needs more nodes than --max-nodes allows. |
| E-DECODE | The policy graph is not a valid GovLisp tree. |
| E-ARCHIVE | An import is not ratified by the file, or a bundled archive is not imported. |
verify, tree and decompile allow 1,000,000 nodes by default, so they are safe on a file you do not trust yet. Running a program has no limit unless you set one with --max-nodes.
A runtime error stops the program with exit code 1. The runtime errors are in Program execution in the specification.
These features never change what a program computes. They decide when it may run, and record who made it.
--not-before and --not-after set when a program is in force. Each takes an RFC 3339 time or a date, which means midnight UTC at the start of that day.
government compile law.gov.lisp \
--not-before 2027-01-01 --not-after 2027-12-31
government law.gov --at 2027-06-01
--at sets the time to check against. It defaults to now.
openssl genpkey -algorithm ed25519 -out ada.pem
government compile law.gov.lisp \
--key ada.pem --author "Ada Lovelace <ada@example.org>"
government verify law.gov
government law.gov --anchor ada.gov
Warning: without --key, the compiler uses a public default key, so anyone can amend or repeal the program. government verify names the ratifier as Public (Default Key).
government repeal law.gov --key ada.pem --reason superseded -o repeal.crl
government law.gov --crl repeal.crlThe program is refused with E-REPEALED.
A CRL names the build it repeals, by the build ID in its issuer's name. Another program with the same name and key is not repealed by it. government verify prints a program's build ID.
repeal also takes:
An archive is a program for other programs to import. Compile one with --archive and a URI that names it:
government compile greet.gov.lisp --key ada.pem --archive https://example.org/greet
A program imports it with a module form that names the .gov file:
(module greet "greet.gov") (greet.hello "world")
Compiling that program checks the archive as running it would, then bundles it: the program's file holds the archive's certificates, the certificates of every archive that it bundles, and a cross-certificate from the program's anchor that ratifies the import. The program then runs without greet.gov. Each chain keeps its own anchor and keys, and is ratified on its own.
An archive's author can repeal it, which repeals every program that bundles it:
government repeal greet.gov --key ada.pem -o greet.crl government main.gov --crl greet.crl
A program's author can repeal one of its imports, with the program's own key:
government repeal main.gov --key me.pem --import https://example.org/greet -o import.crl
Every certificate's name ends with a build ID, a hash of everything in its chain but the names, so chains from different builds never share a name. Two archives with the same --name can be bundled together, and so can two versions of one archive.
A module from a .gov.lisp file is not an archive: the compiler writes its definitions into the program itself.
Comments in the source become notes in the certificates. government tree shows them, and government decompile turns them back into comments.