What it brings
Certificates for any Weirdnet host without each app writing its own ACME client. It replaces the ACME code that was separate in Mouser, Muninn, itcmdr and TAUR, and it never trades availability for a certificate: a failed order keeps the last certificate in service and never falls back to plain HTTP.
Use it when an app terminates TLS itself with rustls: a relay on 443, a self-hosted site behind Weirdnet forwarding, a service like TAUR. HTTP servers and port forwarding stay in the app. Muninn orders its certificates through it.
What it is
Certificates from Let’s Encrypt or any ACME directory over instant-acme, kept current in the background and served through a rustls resolver that swaps them without a restart. It is the shared replacement for the ACME code in Mouser, Muninn, itcmdr and TAUR.
A failed order never drops TLS: the last certificate stays in service, and the crate never falls back to plain HTTP. HTTP servers and port forwarding are left to the app.
How it works
- Order:
Acmekeeps an account per directory in the store (Let's Encrypt production or staging, or any RFC 8555 directory), with several names per certificate, wildcards and ACME profiles. From 0.2.0,AcmeConfig::profile_optionalorders with the CA's default when the profile is refused. From 0.3.0, names a public CA refuses (localhost, IP addresses, all-digit top labels) fail validation unlessAcmeConfig::private_namesis set for a private CA. - Challenge: TLS-ALPN-01 is answered by the resolver on your port 443; HTTP-01 from an
Http01Board(served byserve_http01or your router); DNS-01 through theDnsChallengetrait: a hook command (it getsWEIRDNET_TLS_ACTION,WEIRDNET_TLS_DOMAIN,WEIRDNET_TLS_NAMEandWEIRDNET_TLS_TXT, and from 0.3.0 the same under an app's own prefix withHookDns::with_prefix), a manual prompt, or a grindvakt-core provider. While the app's own listener isn't running,Acme::serve_challengeanswers TLS-ALPN-01 or HTTP-01 on a listener of its own. - Store: the
CertStoretrait withFileStore(files 0600 in directories 0700, atomic writes),MemoryStore, orSqlStorein an encrypted weirdnet-storage database.Acme::importcopies an app's earlier account, certificate and state in, never overwriting. - Serve: the
Resolverpicks a certificate per name, in the order pinned (internal names, a private CA), the user's own, ACME, then self-signed, skipping expired ones, with a default for handshakes without SNI (the ACME certificate withAcme::with_default_cert). It swaps certificates without a restart;server_confighands a rustls config to tokio-rustls or hyper. - Renew: at a point in the CA's ACME Renewal Information window (RFC 9773) with
replaces, else two thirds into the lifetime, so shorter certificate lifetimes need no change. Failures back off from an hour to a day; a forced renewal within a day of the last issue is refused (Acme::trigger_renewalasks the running renewer for one).Acme::watchgives a typedStatus, andacme::schedulereads the next renewal from the store alone, for status commands.
Linux, macOS and Windows are tested in CI; Android (aarch64, API 26) and iOS (aarch64) build.
Key types and modules
- ACME: an account per directory, several names per certificate, wildcards, ACME profiles,
replaceson renewal. - Challenges: TLS-ALPN-01 answered by the resolver, HTTP-01 from a token board, DNS-01 by a hook command, a manual prompt or a
grindvakt-coreprovider. - Stores: files (0600), memory, or a table in an encrypted
weirdnet-storagedatabase. - Resolver: per-name certificates in the order pinned, user, ACME, self-signed, with a default for handshakes without SNI.
- Renewal: inside the CA’s renewal window (ARI), else two thirds into the lifetime; backoff from an hour to a day; a typed status.
- Testing: a mock ACME CA that checks the real challenge answers.
Feature flags
ring(default): rustls, rcgen and instant-acme on ring.aws-lc-rs: the same on aws-lc-rs; wins when both are on.grindvakt: DNS-01 through grindvakt-core providers. They can’t delete records, so the_acme-challengeTXT is overwritten on each order and left in place.storage:SqlStorein a weirdnet-storage (SQLCipher) database.testing:testing::MockCa, an in-process ACME CA that checks the real HTTP-01, TLS-ALPN-01 and DNS-01 answers and serves ARI.
Usage
In Cargo.toml:
[dependencies]
weirdnet-tls = "0.3.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }Then (built and run against the published crate when this page was made):
// Serve TLS now (self-signed), then let ACME replace the certificate in the background.
use std::sync::Arc;
use weirdnet_tls::*;
#[tokio::main]
async fn main() -> weirdnet_tls::Result<()> {
let names = vec!["example.com".to_string(), "www.example.com".to_string()];
let resolver = Arc::new(Resolver::with_self_signed(&names)?);
let mut cfg = AcmeConfig::new("main", names);
cfg.contact = vec!["admin@example.com".into()];
let acme = Arc::new(Acme::new(cfg, Arc::new(FileStore::new("/var/lib/myapp/tls")), resolver.clone())?);
acme.load()?;
let _renewer = acme.clone().spawn();
let _tls = resolver.server_config(&[b"h2", b"http/1.1"])?; // hand to tokio-rustls, hyper, ...
Ok(())
}
Where it fits
- Builds on weirdnet-storage.
- Extracted from Mouser.
- License: BSD-3-Clause.
HookDns::with_prefix, with_env), an offline renewal schedule read from the store (acme::schedule), the ACME certificate as the default for handshakes without SNI (Acme::with_default_cert), forced renewals from the running renewer behind the repeat-certificate guard (Acme::trigger_renewal), challenge-only TLS-ALPN-01 and HTTP-01 listeners (Acme::serve_challenge), and importing an app’s earlier account, certificate and state (Acme::import). 0.3.0 is breaking: valid_name and AcmeConfig::validate refuse localhost, IP addresses and all-digit top labels unless AcmeConfig::private_names is set for a private CA, AcmeConfig is #[non_exhaustive] (build it with AcmeConfig::new), and HookDns is built with HookDns::new.