lcert_verify.serve
An HTTP verification service — standard library only, no dependencies.
Some teams will not add a Python dependency to a signoff flow but will call an endpoint. This is that endpoint. It runs the same verifier, reaches nothing but the request body, and writes nothing outside a temporary directory it deletes.
The status code carries the verdict, so a naive caller cannot misread it.
That is the whole design. A service that returned 200 with {"verdict":
"UNVERIFIED"} would let if response.ok: treat an abstention as a pass — the
exact failure this project exists to prevent, in HTTP form. So:
=========================== ====== =============================================== Verdict Status Why that code =========================== ====== =============================================== VERIFIED, VERIFIED-VACUOUS, 200 the check was made and it stood INTERNALLY-CONSISTENT UNVERIFIED 428 Precondition Required — the anchor is a missing precondition, not a failure of the bundle REFUTED, VACUOUS 422 Unprocessable Content — the artifact was read and does not hold up too large / malformed 413/400 not a verdict at all =========================== ====== ===============================================
428 is deliberate rather than 4xx-generic: RFC 6585 defines it for a request that must be made conditional, and supplying the out-of-band fingerprint is exactly that condition.
Endpoints:
GET /health liveness, and the version
GET /scope what is and is not checked, verbatim
POST /verify a bundle, as a zip (the whole directory) or as a bare
bundle.json. Bundles with payload files must be zipped,
because a single document cannot carry them; posting one
bare then fails its own manifest, and the reply says so.
HTTP request handler base class.
The following explanation of HTTP serves to guide you through the code as well as to expose any misunderstandings I may have about HTTP (so you don't need to read the code to figure out I'm wrong :-).
HTTP (HyperText Transfer Protocol) is an extensible protocol on top of a reliable stream transport (e.g. TCP/IP). The protocol recognizes three parts to a request:
- One line identifying the request type and path
- An optional set of RFC-822-style headers
- An optional data part
The headers and data are separated by a blank line.
The first line of the request has the form
where
The specification specifies that lines are separated by CRLF but for compatibility with the widest range of clients recommends servers also handle LF. Similarly, whitespace in the request line is treated sensibly (allowing multiple spaces between components and allowing trailing whitespace).
Similarly, for output, lines ought to be separated by CRLF pairs but most clients grok LF characters just fine.
If the first line of the request has the form
(i.e.
The reply form of the HTTP 1.x protocol again has three parts:
- One line giving the response code
- An optional set of RFC-822-style headers
- The data
Again, the headers and data are separated by a blank line.
The response code line has the form
where
This server parses the request and the headers, and then calls a
function specific to the request type (
do_SPAM()
Note that the request name is case sensitive (i.e. SPAM and spam are different requests).
The various request details are stored in instance variables:
client_address is the client IP address in the form (host, port);
command, path and version are the broken-down request line;
headers is an instance of email.message.Message (or a derived class) containing the header information;
rfile is a file object open for reading positioned at the start of the optional input data part;
wfile is a file object open for writing.
IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!
The first thing to be written must be the response line. Then follow 0 or more header lines, then a blank line, and then the actual data (if any). The meaning of the header lines depends on the command executed by the server; in most cases, when data is returned, there should be at least one header line of the form
Content-type:
where
Log an arbitrary message.
This is used by all other logging functions. Override it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it's just like printf!).
The client ip and current date/time are prefixed to every message.
Unicode control characters are replaced with escaped hex before writing the output to stderr.