sewer

A crypto module for ACME

There were several motivations behind the creation of crypto.py:

Preliminaries

I use the term private key quite a bit, as it is the term widely used for some representation of both the public and private parts of an asymmetric key.

AcmeKey

AcmeKey is a parameterized holder for the primitive key classes of the underlying implementation (the cryptography package).

So now Client and the cli code can stop schlepping around a string that holds the key in PEM format. That’s part of the reason this work intentionally broke the names in Client (eg., acct_key in place of account key) when it switched to an AcmeKey object.

Factory (class)methods

Two essential factories:

And an inessential convenience:

AcmeKey attributes

Sewer’s code never needs to touch the pk directly.

AcmeKey methods

private_bytes is the only method that all ACME clients must use, and that will often be done indirectly through to_file.

You will have noticed the symmetry of the method names: to/from_pem for in-memory byte strings, read/write_pem for keys in files.

AcmeAccount

Accounts are keys which are registered with the ACME service and thereafter used to identify and authenticate the origina of most of the messages sent to the service. They are a subclass of AcmeKey that extends the interface to include things only an account key has to do.

AcmeAccount attributes

_kid is needed only for constructing the signed ACME requests, and is used mostly as an in-memory value. There is experimental support for saving the Key ID and timestamp along with the account key.

AcmeAccount methods

set_kid() is pure implementation detail, a stash for the account’s registered URL on a specific ACME server. timestamp is what time.time() returns.

not yet implemented: write_extended_pem, read_extended_pem (or will read just be an override that loads the extended values if present?)

AcmeCsr

This is currently a minimal replacement for the OpenSSL-based create_csr method. Which might be all an ACME client requires, so perhaps the current design will be more or less how it comes out? There will be an additional flag for setting the “must be stapled” certificate extension, but there’s really not much else to add, based on a review of the de-facto standard of cert-bot’s options.

One thing to note: yes, the choice of DER format is intentional and necessary, as the ACME protocol requires that format, base64-url encoded, without the starting and ending text lines that PEM adds.