netio/acme.rs#
Source: lib/netio/acme.rs
acme -- certificates from a CA that speaks ACME (RFC 8555): Let's Encrypt, ZeroSSL, Google
Trust Services, a company's step-ca. http-01, tls-alpn-01 (RFC 8737) and dns-01 challenges,
DNS names and IP addresses (RFC 8738), renewal information (ARI, RFC 9773), external
account binding (RFC 8555 7.3.4), profiles, key change, revocation
Acme::new(client, directory_url) -> Result<Acme, AcmeError> reads the CA's directory
acme.account(key, &NewAccount { contact, terms_agreed, eab, .. }) -> Account
account.issue(&ids, &cert_key, &mut solver, &OrderOptions) -> Issued { chain, pem, .. }
the whole issuance: an order, each authorization proved by `solver`, a certificate
request for `cert_key`, the chain once the CA has issued it
step by step: new_order, authorization, respond, wait_authorization, finalize,
wait_order, certificate
acme.renewal_info(&cert) (ARI: when to renew), account.revoke, change_key, update_contact,
deactivate; revoke_with_key (by the certificate's own key)
Solver: what proves control of a name -- Http01 (a netio Server's handler answers
/.well-known/acme-challenge/), TlsAlpn01 (a tls::ServerConfig that answers
"acme-tls/1"), a DNS provider's code of the program's own (dns01_name, dns01_value)
Every request is a JWS (RFC 7515) signed with the account key: ES256 (P-256), ES384 (P-384),
RS256 (RSA) or EdDSA (Ed25519; not every CA takes it). The CA's URLs must be https; its
answers are bounded (64 KiB, a certificate chain 1 MiB) and checked: the chain issued must be
for the certificate key and every identifier ordered. A wait for an authorization or the
order follows Retry-After and ends after Acme::timeout_ms.
/// Let's Encrypt's directory, and its staging one (for tests: higher rate limits, an untrusted
/// root)
LETS_ENCRYPT: &str = "https://acme-v02.api.letsencrypt.org/directory"
LETS_ENCRYPT_STAGING: &str = "https://acme-staging-v02.api.letsencrypt.org/directory"
/// the ALPN protocol of tls-alpn-01 (RFC 8737 6.2)
ACME_TLS_ALPN: &str = "acme-tls/1"
/// the longest answer of the CA (JSON), and of a certificate chain
MAX_ANSWER: usize = 64 * 1024
MAX_CHAIN: usize = 1 << 20
struct Problema problem document of the CA (RFC 8555 6.7, RFC 7807)status: u16-- the HTTP status of the answer (0 inside an object: an authorization's error)kind: String-- "urn:ietf:params:acme:error:rateLimited", ...detail: Stringidentifier: Option<Identifier>-- the identifier a subproblem is about (RFC 8555 6.7.1)subproblems: Vec<Problem>retry_after: Option<u64>-- seconds to wait before trying again (Retry-After), when the CA says
impl Problem
fn is(&self, name: &str) -> boolwhether it is the ACME errorname("badNonce", "rateLimited", "unauthorized", ...)enum AcmeErrorHttp(HttpError)-- the request did not reach the CA, or no HTTP answer cameProblem(Problem)-- the CA refused (its problem document)Protocol(String)-- an answer of the CA that does not follow RFC 8555Invalid(String, Option<Problem>)-- an authorization or the order ended invalid (the CA's reason, when it gave one)Solver(String)-- the solver could not set a challenge upTimeout(String)-- the CA did not decide within Acme::timeout_ms
enum Identifierwhat a certificate is forDns(String)-- a DNS name, lower case; "*.example.com" for a wildcard (dns-01 only)Ip(IpAddr)-- an IP address (RFC 8738)
impl Identifier
fn parse(s: &str) -> Identifiera name or an address ("example.com", "*.example.com", "192.0.2.1", "2001:db8::1")fn value(&self) -> Stringthe text of the identifier (an address in its RFC 5952 form)fn tls_name(&self) -> Stringthe name a validator puts in server_name for tls-alpn-01: the name, or for an address its reverse DNS name (RFC 8738 6)struct Directorythe CA's directory (RFC 8555 7.1.1)new_nonce: Stringnew_account: Stringnew_order: Stringrevoke_cert: Stringkey_change: Stringnew_authz: Option<String>-- pre-authorization (most CAs have none)renewal_info: Option<String>-- renewal information (RFC 9773)terms_of_service: Option<String>-- what an account must agree to (NewAccount::terms_agreed)website: Option<String>caa_identities: Vec<String>-- the names a CAA record must name for this CAexternal_account_required: bool-- accounts need an external account binding (NewAccount::eab)profiles: Vec<(String, String)>-- the certificate profiles offered: (name, description)
fn rfc3339(s: &str) -> Option<i64>an RFC 3339 time ("2026-11-24T08:00:00Z", fractions, an offset) -> Unix secondsfn rfc3339_text(t: i64) -> StringUnix seconds -> "2026-11-24T08:00:00Z"fn thumbprint(key: &PubKey) -> Option<String>the JWK thumbprint (RFC 7638, SHA-256), base64urlstruct Eaban external account binding (RFC 8555 7.3.4): the key id and MAC key the CA handed outkid: Stringhmac_key: Vec<u8>
impl Eab
fn new(kid: &str, hmac_key_b64: &str) -> Option<Eab>the key id and the MAC key as the CA shows it (base64url)struct NewAccounta new (or existing) accountcontact: Vec<String>-- "mailto:admin@example.com" (some CAs need one; Let's Encrypt no longer writes to them)terms_agreed: bool-- the directory's terms of service agreed toonly_existing: bool-- only find the account of the key, make none (RFC 8555 7.3.1)eab: Option<Eab>
struct OrderOptionsan order's optionsnot_before: Option<i64>-- the validity asked for (Unix seconds; most CAs decide it themselves)not_after: Option<i64>profile: Option<String>-- a profile of the directory's (Directory::profiles)replaces: Option<String>-- the certificate this one replaces (its ARI id, ari_id): the CA can tell a renewalmust_staple: bool-- a certificate that must come with a stapled OCSP response (RFC 7633; not every CA issues them)
struct Orderurl: Stringstatus: String-- "pending", "ready", "processing", "valid", "invalid"expires: Option<i64>identifiers: Vec<Identifier>authorizations: Vec<String>finalize: Stringcertificate: Option<String>error: Option<Problem>profile: Option<String>
struct Challengekind: String-- "http-01", "tls-alpn-01", "dns-01", ...url: Stringstatus: String-- "pending", "processing", "valid", "invalid"token: String-- base64url (checked: only its alphabet, 16 to 256 characters)error: Option<Problem>
struct Authorizationurl: Stringstatus: String-- "pending", "valid", "invalid", "deactivated", "expired", "revoked"identifier: Identifierwildcard: bool-- for "*." plus the identifier (dns-01 only)expires: Option<i64>challenges: Vec<Challenge>
struct Issueda certificate issuedchain: Vec<Vec<u8>>-- DER, leaf firstpem: String-- the chain as the CA sent it (PEM): for the server's certificate filealternates: Vec<String>-- other chains the CA offers (Link rel="alternate"; Acme::certificate fetches them)order: Order
impl Issued
fn identity(&self, key: &PrivateKey) -> Identitythe identity for a TLS server: the chain and the certificate keystruct RenewalInfowhen to renew a certificate (ARI, RFC 9773)start: i64-- the window the CA suggests (Unix seconds): renew at a random time in itend: i64explanation: Option<String>retry_after: u64-- when to ask again (seconds, Retry-After; 6 hours when the CA does not say)
impl RenewalInfo
fn renew_at(&self, fraction: f64) -> i64a time in the window to renew at: start + (end - start) * fraction (a random fraction in [0, 1) spreads the renewals out, as RFC 9773 4.2 asks)fn ari_id(cert: &Cert) -> Option<String>a certificate's id in renewal information and in an order's "replaces" (RFC 9773 4.1): the key identifier of its authority key identifier and its serial number; None without the formerstruct Acmethe client of one CA (cheap to clone: the clones share the nonces)directory: Arc<Directory>timeout_ms: u64-- the longest wait for an authorization or the order to be decided (ms; 3 minutes)poll_ms: u32-- the pause between two looks at an authorization or the order when the CA sends no Retry-After (ms; 2 seconds)max_poll_ms: u32-- the longest pause taken from a Retry-After (ms; 30 s); a shorter Retry-After counts as at least half a second (or max_poll_ms, when that is less). No pause of either kind goes past timeout_ms: the last one ends at it
impl Acme
fn new(client: Client, directory: &str) -> Result<Acme, AcmeError>the CA atdirectory(an https URL: LETS_ENCRYPT, ...) overclient(with an https connector: trust::system_connector for public CAs)fn account(&self, key: PrivateKey, new: &NewAccount) -> Result<Account, AcmeError>the account ofkey(made when there is none and new.only_existing is false)fn renewal_info(&self, cert: &Cert) -> Result<RenewalInfo, AcmeError>when the CA suggests renewingcert(ARI, RFC 9773); Err when the directory has no renewalInfo or the certificate no authority key identifierstruct Accountan account of a CAurl: String-- the account's URL (its key id, "kid")status: String-- "valid", "deactivated", "revoked"contact: Vec<String>created: bool-- the CA made it on this call (201)
impl Account
fn acme(&self) -> &Acmefn key(&self) -> &PrivateKeyfn new_order(&self, ids: &[Identifier], opts: &OrderOptions) -> Result<Order, AcmeError>a new order for these identifiersfn order(&self, url: &str) -> Result<Order, AcmeError>an order as it stands nowfn respond(&self, ch: &Challenge) -> Result<(), AcmeError>tell the CA a challenge is ready to be checked (RFC 8555 7.5.1)fn wait_order(&self, url: &str) -> Result<Order, AcmeError>wait until the order is no longer pending or processing (Acme::timeout_ms as wait_authorization)fn finalize(&self, order: &Order, csr: &[u8]) -> Result<Order, AcmeError>send the certificate request (DER) of a ready orderfn certificate(&self, url: &str) -> Result<(Vec<Vec<u8>>, String, Vec<String>), AcmeError>the chain at a certificate URL (an order's, or an alternate one) -> (DER chain, PEM, alternates)fn issue(&self, ids: &[Identifier], cert_key: &PrivateKey, solver: &mut dyn Solver, opts: &OrderOptions) -> Result<Issued, AcmeError>the whole issuance foridsand the keycert_key(not the account key): an order; each pending authorization proved with the first challenge type of solver.kinds() it offers (a wildcard only by dns-01), set up, answered, waited for and taken down; the certificate request; the chain, checked to be forcert_keyand every identifierfn revoke(&self, cert_der: &[u8], reason: Option<u8>) -> Result<(), AcmeError>revoke a certificate of this account (RFC 8555 7.6);reason: a CRLReason (RFC 5280 5.3.1: 1 keyCompromise, 4 superseded, 5 cessationOfOperation, ...)fn change_key(&mut self, new_key: PrivateKey) -> Result<(), AcmeError>change the account's key (RFC 8555 7.3.5)fn update_contact(&mut self, contact: &[String]) -> Result<(), AcmeError>replace the account's contact addressesfn deactivate(&mut self) -> Result<(), AcmeError>end the account (RFC 8555 7.3.6): it cannot be used againfn revoke_with_key(acme: &Acme, cert_der: &[u8], cert_key: &PrivateKey, reason: Option<u8>) -> Result<(), AcmeError>revoke a certificate by its own key (signed with it, no account: a lost account key, a compromised certificate key)trait Solverwhat proves control of an identifierfn kinds(&self) -> Vec<&'static str>the challenge types it sets up, the preferred first ("http-01", "tls-alpn-01", "dns-01")fn present(&mut self, id: &Identifier, ch: &Challenge, key_auth: &str) -> Result<(), String>set the challenge up forid("*.example.com" for a wildcard):key_authis what it must show (dns-01: dns01_value(key_auth) as TXT of dns01_name(id))fn cleanup(&mut self, id: &Identifier, ch: &Challenge)take it down once the authorization is decided
fn dns01_name(id: &Identifier) -> Stringthe TXT record's name of dns-01 (RFC 8555 8.4): "_acme-challenge." and the name (a wildcard's without "*.")fn dns01_value(key_auth: &str) -> Stringthe TXT record's value of dns-01: base64url of SHA-256 of the key authorizationstruct Http01http-01 (RFC 8555 8.3): the key authorizations a netio HTTP server answers at /.well-known/acme-challenge/<token> on port 80. Clones share the tokens: one goes to the solver, one into the server (handler or answer)
impl Http01
fn new() -> Http01fn answer(&self, req: &Request) -> Option<Response>the answer to a challenge request, None for every other requestfn handler(&self, next: Handler) -> Handlera handler that answers challenges and hands every other request tonextstruct TlsAlpn01tls-alpn-01 (RFC 8737): a certificate for the challenge, shown on port 443 to a client that offers only "acme-tls/1". Clones share the certificates: one goes to the solver, one into the server's config (setup). A name has one challenge at a time: another one for it fails to be set up until the first is cleaned up; the same challenge set up twice (two orders the CA gave it to) keeps its first certificate and stays until both are cleaned up
impl TlsAlpn01
fn new() -> TlsAlpn01fn setup(&self, cfg: &mut ServerConfig)letcfganswer the challenges: "acme-tls/1" among its protocols (last; to a client that does not offer it alone the server's list is as if it were not there, so a server without protocols of its own still answers without ALPN), and a select that shows the challenge certificate for a ClientHello offering only it (before the config's own select)fn certificate(id: &Identifier, key_auth: &str) -> Option<Identity>the self-signed certificate of a challenge (RFC 8737 3): the identifier as its only name, the critical acmeIdentifier with SHA-256 of the key authorizationstruct Solvers(pub Vec<Box<dyn Solver + Send>>)several solvers, each for the challenge types it sets up (a DNS provider for wildcards, http-01 for the rest): the first that sets up a type the authorization offers takes it