weirdnet_tls/lib.rs
1//! TLS certificates for Weirdnet hosts.
2//!
3//! - [`acme`]: certificates from an ACME CA (Let's Encrypt or any RFC 8555 directory) over
4//! [instant-acme](https://docs.rs/instant-acme), with TLS-ALPN-01, HTTP-01 and DNS-01, several
5//! names per certificate, and the account kept in a [`CertStore`].
6//! - [`challenge`]: the HTTP-01 token board and listener, a TLS-ALPN-01 challenge-only
7//! listener, and DNS-01 publishers (a hook command,
8//! a manual prompt, and [grindvakt-core](https://docs.rs/grindvakt-core) providers with the
9//! `grindvakt` feature).
10//! - [`store`]: the [`CertStore`] trait, a file store (files 0600), a memory store, and with the
11//! `storage` feature a store in an encrypted weirdnet-storage database; [`store::import`]
12//! moves an app's earlier files in.
13//! - [`resolver`]: a rustls SNI [`Resolver`] with per-name hot swap, source order user, ACME,
14//! self-signed, pinned certificates for internal names, and the TLS-ALPN-01 answers.
15//! - [`renew`]: when to renew (ACME Renewal Information, else two thirds of the lifetime),
16//! failure backoff from 1 hour to 1 day, a guard on forced renewals, a typed [`Status`], and
17//! an offline [`Schedule`] read from the store ([`acme::schedule`]).
18//! - [`testing`] (feature `testing`): a mock ACME CA that validates the real challenge answers.
19//!
20//! The crate never serves plain HTTP in place of HTTPS: when an order fails, the resolver keeps
21//! serving the previous certificate (or the self-signed one), and the HTTP-01 listener answers
22//! only challenge tokens.
23//!
24//! Pick a crypto provider with the `ring` (default) or `aws-lc-rs` feature.
25
26#![forbid(unsafe_code)]
27#![warn(missing_docs)]
28
29#[cfg(not(any(feature = "ring", feature = "aws-lc-rs")))]
30compile_error!("weirdnet-tls needs the `ring` or the `aws-lc-rs` feature");
31
32pub mod acme;
33pub mod cert;
34pub mod challenge;
35mod error;
36pub mod renew;
37pub mod resolver;
38pub mod store;
39#[cfg(feature = "testing")]
40pub mod testing;
41
42pub use acme::{Acme, AcmeConfig, ChallengeKind, Directory};
43pub use cert::{CertInfo, CertPair};
44pub use challenge::{DnsChallenge, DnsRecord, HookDns, Http01Board, ManualDns};
45pub use error::{Error, Result};
46pub use instant_acme;
47pub use renew::{Outcome, Schedule, State, Status};
48pub use resolver::{Resolver, Source};
49pub use rustls;
50pub use store::{CertStore, FileStore, MemoryStore};
51
52/// The ALPN protocol of TLS-ALPN-01 validation (RFC 8737).
53pub const ACME_TLS_ALPN: &[u8] = b"acme-tls/1";
54
55/// The rustls crypto provider picked by the features: aws-lc-rs when on, else ring.
56pub fn crypto_provider() -> std::sync::Arc<rustls::crypto::CryptoProvider> {
57 #[cfg(feature = "aws-lc-rs")]
58 let p = rustls::crypto::aws_lc_rs::default_provider();
59 #[cfg(all(feature = "ring", not(feature = "aws-lc-rs")))]
60 let p = rustls::crypto::ring::default_provider();
61 std::sync::Arc::new(p)
62}