- OCaml 100%
- Shell <1%
nox-x509 #
X.509 certificates, CRLs, OCSP and the PKCS encodings in pure OCaml.
Warning. This is a work-in-progress experimental fork of ocaml-x509. Do not use it in production; use ocaml-x509 instead.
A TLS client that accepts a server's key needs a reason to believe the key belongs to that server. X.509 provides it: a certificate binds a public key to a name and is signed by an authority, and the client trusts a small set of authorities that it received over another channel. Checking a chain means parsing ASN.1 DER, verifying each signature and applying the path validation rules of RFC 5280 and the name matching rules of RFC 6125. This library implements most of both, together with certificate revocation lists, OCSP (RFC 6960) and the PKCS encodings 1, 5, 7, 8, 9, 10 and 12 in DER and PEM.
ASN.1 is the schema language certificates are defined in. DER is its unique
binary encoding, each value written as a tag, a length and the content, so
that the bytes a signature covers are unambiguous. PEM is the same DER bytes
in base64 between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines. Certificate revocation lists (CRLs) and OCSP both
withdraw a certificate before it expires: a CRL is a signed list of revoked
serial numbers that the authority publishes periodically, and OCSP (the
Online Certificate Status Protocol) asks the authority's server about one
certificate and gets back a signed answer, good, revoked or unknown.
nox-x509 is a fork of
mirleft/ocaml-x509 by David Kaloper
and Hannes Mehnert, whose design is described in their
USENIX Security 2015 paper.
Installation #
$ opam install nox-x509
If opam cannot find the package, it has not reached the public
opam-repository yet. Add the overlay repository first:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install nox-x509
Usage #
Decode a PEM bundle into certificates, then build an authenticator from a set of trust anchors:
let pem_bundle = "...PEM CERTIFICATE bundle string..."
let trust_anchors = []
let time () = None
let certs = X509.Certificate.decode_pem_multiple pem_bundle
let authenticator =
X509.Authenticator.chain_of_trust ~time trust_anchors
With time returning None, as here, the validity-period check is skipped,
so an expired or not-yet-valid certificate passes. A real client passes the
current time, fun () -> Some now.
API #
The X509 module is the only entry point, and
lib/x509.mli documents it. dune build @doc generates the
HTML documentation.
License #
BSD-2-Clause. See LICENSE.md.