12 releases

0.4.9 Dec 21, 2025
0.4.7 May 28, 2025
0.4.5 Apr 14, 2025
0.4.4 Mar 8, 2025
0.4.1 May 27, 2024

#534 in HTTP server

Download history 1960/week @ 2025-10-27 1304/week @ 2025-11-03 739/week @ 2025-11-10 1343/week @ 2025-11-17 818/week @ 2025-11-24 93/week @ 2025-12-01 54/week @ 2025-12-08 88/week @ 2025-12-15 81/week @ 2025-12-22 97/week @ 2025-12-29 619/week @ 2026-01-05 356/week @ 2026-01-12 286/week @ 2026-01-19 363/week @ 2026-01-26 338/week @ 2026-02-02 997/week @ 2026-02-09

1,984 downloads per month

MPL-2.0 license

38KB
741 lines

Warning

Be advised that LetsEncrypt, sadly, decided to drop support for OCSP stapling in 2025. So if you were planning to use this crate with LetsEncrypt - soon it won't be possible.

ocsp-stapler

crates.io Documentation MPL-2 Licensed

OCSP stapler for Rustls.

  • OCSP Client that can be used separately
  • Stapler wraps Arc<dyn ResolvesServerCert> trait object and automatically staples all certificates provided by it

Please see the docs for more details.

Example

// Read the chain & private key and combine them into CertifiedKey
let certs = std::fs::read("chain.pem").unwrap();
let certs = rustls_pemfile::certs(&mut certs.as_ref()).collect::<Result<Vec<_>, _>>().unwrap();

let key = std::fs::read("private.pem").unwrap();
let key = rustls_pemfile::private_key(&mut key.as_ref()).unwrap();
let key = rustls::crypto::ring::sign::any_supported_type(&key).unwrap();

let ckey = rustls::sign::CertifiedKey::new(certs, key);

// Inner service that provides certificates to Rustls, can be anything
let mut inner = rustls::server::ResolvesServerCertUsingSni::new();
inner.add("crates.io", ckey).unwrap();

// Create a Stapler wrapping inner resolver
let stapler = Arc::new(ocsp_stapler::Stapler::new(inner));

// Then you can build & use ServerConfig wherever applicable
let server_config = rustls::server::ServerConfig::builder()
        .with_no_client_auth()
        .with_cert_resolver(stapler.clone());

// Stop the background worker to clean up resources
stapler.stop().await;

Dependencies

~28–55MB
~1M SLoC