Enrollment over Secure Transport (RFC 7030, RFC 8951), I/O-free core
README.md

est #

A client and a server for Enrollment over Secure Transport (EST,
RFC 7030) in OCaml.

A device that joins a private PKI needs a certificate from the PKI's
certification authority (CA), and must renew it before it expires, with
nobody at the keyboard. EST does that over HTTPS. The device fetches the CA
certificates (/cacerts), sends a PKCS #10 certification request
(/simpleenroll) and receives its certificate. It renews the certificate
with /simplereenroll, authenticated by the certificate it renews.

The est package is the protocol with no I/O: it builds and reads the HTTP
requests and answers, and the caller sends them. The est-eio package runs
it over HTTP/1.1 on TLS with Eio, and installs the est command. Both
follow RFC 8951, which corrects RFC 7030.

Installation #

Both packages need OCaml 5.1 or later. They are not in the public
opam-repository; add the overlay repository, then install them:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install est est-eio

Usage #

Command line #

A device fetches the CA certificates, enrols, and later renews its
certificate:

$ est cacerts --server est.example --fingerprint <sha256 hex> -o ca.pem
$ est enroll --server est.example --anchors ca.pem --key device.key \
    --cn device --user device --password-file password -o device.pem
$ est reenroll --server est.example --anchors ca.pem --cert device.pem \
    --key device.key -o device.pem

A first est cacerts without --anchors or --fingerprint prints the
fingerprint of the CA certificate, for a person to compare with one
obtained another way. est enroll makes the key when device.key does not
exist. --link ties the request to its TLS session. A client command fails
when its TLS session or an answer takes longer than --timeout seconds.

est serve runs a server that issues certificates with a CA key:

$ est serve --listen 0.0.0.0:443 --cert server.pem --key server.key \
    --ca ca.pem --ca-key ca.key --realm est --user device --password-file password

It issues each certificate for --days days, 30 by default. It accepts a
renewal on the TLS certificate being renewed. It accepts an enrolment on
the Basic credentials, or on a TLS client certificate when the server has
no credentials.
--request-timeout bounds the TLS handshake and each complete request;
--idle-timeout bounds how long a connected client may hold a slot between
requests. Both take positive seconds and use the server library's defaults
when omitted.

Library #

Est.Client holds the state of one client. Starting an operation returns
the HTTP request to send:

# let first_request =
    match Est.Client.v Est.Client.Bootstrap with
    | Error (`Msg m) -> Error m
    | Ok client -> (
        match Est.Client.cacerts client with
        | Ok (_, _, Est.Client.Send r) -> Ok (r.meth, r.path)
        | Ok _ -> Error "no request"
        | Error e -> Error (Fmt.str "%a" Est.Error.pp e));;
val first_request : ([ `GET | `POST ] * string, string) result =
  Ok (`GET, "/.well-known/est/cacerts")

The caller sends the request over TLS and gives the answer to
Est.Client.incoming. incoming returns the next action (Send, Sleep
or Idle) and the events of the step, such as Ca_certificates,
Enrolled or Failed.

A server may serve several CAs, each under a label in the path:

# Est.Operation.path ~label:"factory" Est.Operation.Simpleenroll;;
- : (string, [> `Msg of string ]) result =
Ok "/.well-known/est/factory/simpleenroll"
# Est.Operation.of_path "/.well-known/est/cacerts";;
- : (string option * Est.Operation.t) option =
Some (None, Est.Operation.Cacerts)

Est_eio.Client and Est_eio.Server do the same over real connections.

API #

lib/est.mli is the entry point of est:

  • Est.Operation names the operations and their paths under
    /.well-known/est, with the optional CA label.
  • Est.Body holds the media types, and the base64 encoding of bodies that
    RFC 8951 section 3 defines. Its decoder ignores white space.
  • Est.Csr_attrs is the codec of the /csrattrs answer (RFC 8951
    section 4).
  • Est.Ca_certs reads a /cacerts answer. The trust anchor is the
    self-signed certificate with the latest notAfter, and the certificates
    that validate to it are kept as intermediates. It also checks the
    fingerprint a client compares when it has no trust anchor yet (RFC 7030
    section 4.1.1).
  • Est.Client runs one operation at a time: cacerts, simpleenroll,
    simplereenroll, csrattrs and incoming.
  • Est.Server reads one request and applies the checks RFC 7030 asks of a
    server. The caller's CA policy decides each enrolment.
  • Est.challenge_password computes the value that ties a request to its
    TLS session.

lib/eio/est_eio.mli is the entry point of
est-eio:

  • Est_eio.Client is a client of one EST server. It authenticates the
    server against given trust anchors, or connects without authenticating
    it to fetch the CA certificates. It sends Basic credentials and a TLS
    client certificate.
  • Est_eio.Server answers each TLS connection it accepts with
    Est.Server.

Limitations #

  • Full CMC (/fullcmc), server-side key generation (/serverkeygen) and
    HTTP Digest authentication are not implemented.
  • Tying a request to its TLS session needs TLS 1.2 with the extended master
    secret, because TLS 1.3 defines no tls-unique value and an earlier TLS
    session without the extension cannot safely use it after resumption
    (RFC 7627 section 6.1).
  • Est.Csr_attrs reads attribute values that are object identifiers or
    character strings. A value of another ASN.1 type makes the whole answer
    an error.

Design #

est does no I/O. It takes the time as an argument, and Est.Client and
Est.Server return actions for the caller to perform. Est.Client.control
and Est.Server.control describe the phases of each and the inputs each
phase accepts, as values of the fsm package.

TLS belongs to the caller #

The caller of Est.Client authenticates the server and tells
Est.Client.v the result. Authorised means TLS authenticated the server
against trust anchors. Bootstrap means TLS completed without
authenticating the server. On a Bootstrap server the client refuses what
RFC 7030 forbids (sections 3.2.3 and 4.1.1): any operation but /cacerts,
and any answer to an HTTP authentication request.

The caller of Est.Server verifies the client's TLS certificate chain. It
hands the chain to Est.Server.incoming, with the tls-unique channel
binding of the session (RFC 5929).

A request tied to its TLS session #

RFC 7030 section 3.5 links the identity of the client to its proof of
possession of the key. The request's challenge-password attribute carries
the base64 of the session's tls-unique value, which
Est.challenge_password computes. The server compares it with the value of
its own session and refuses a mismatch.

est-eio opens one TLS session per operation and sends the operation's
requests over it. It opens a new session when the server closes the first.
A linked request keeps its session for the whole operation, including the
wait of a deferred enrolment. It fails once the server closes the session,
because a new session has a new tls-unique value.

The server of est-eio terminates TLS itself and serves the decrypted
connection with respond-eio. Each request is therefore read with the
client certificate chain the handshake verified and the tls-unique value of
its session.

PKCS #10 requests and the certs-only CMS SignedData of RFC 5272 section 4.1
come from nox-x509, as X509.Signing_request and X509.CMS.Certs_only.

Bounds on the work a peer can cause #

  • An answer to the client, or a request to the server, is decoded once,
    from base64 and then from DER. Each decoding allocates at most 8 KiB plus
    twice the length of the body, which the tests check on bodies of 1 KiB
    and 10 KiB.
  • est-eio reads an answer or a request body of at most max_body bytes,
    64 KiB by default, and fails the exchange beyond that.
  • The certificates of a /cacerts answer are traversed from their trust
    anchor by nox-x509. The path search refuses an answer that needs more
    than eight candidate edges per certificate, 1024 paths in all or 64
    intermediates on one path. An unrelated certificate costs one candidate
    check against the anchor, rather than a search through the whole answer.
  • A server that defers an enrolment (HTTP 202) makes the client wait at
    most max_wait each time, and send the request again at most
    max_deferrals times. A 401 is answered once per request.
  • Est.Server keeps no state between requests.

Interoperability #

The tests in test/interop replay exchanges between the estclient and
the estserver of two other implementations, recorded through a TLS relay.
Est.Server reads each recorded request and Est.Client each recorded
answer. REGEN=1 dune build @traces records them again, and needs Docker.

  • libest: /cacerts, /csrattrs,
    /simpleenroll with a Basic challenge, /simplereenroll over the TLS
    certificate it renews, and an enrolment deferred with a 202. Its example
    estserver ends its /csrattrs body with a NUL byte. RFC 8951
    section 3.1 does not allow it, and Est.Client refuses that answer.
  • globalsign/est, in Go: the same
    operations with chunked requests and Basic credentials sent before any
    challenge, then one enrolment deferred and one refused under a CA label.
    With no attributes to send, its estserver answers /csrattrs with a
    200 and an empty sequence, where Est.Server answers 204. RFC 8951
    section 4 makes the two equivalent.
  • libest (Cisco, BSD) is a C client and
    server.
  • globalsign/est (MIT) is a Go client
    and server.
  • XiPKI (Apache-2.0) is a CA that serves
    EST.
  • acme implements ACME (RFC 8555), another issuance protocol, with JSON
    objects signed as JWS and challenges that prove control of a name.
  • cmp implements CMP (RFC 9810), which protects its own messages where
    EST relies on TLS.

References #

  • RFC 7030, Enrollment over Secure Transport
  • RFC 8951, Clarification of Enrollment over Secure Transport
    (EST): Transfer Encodings and ASN.1
  • RFC 5929, Channel Bindings for
    TLS

Licence #

ISC. See LICENSE.md.