The high-level API provides a single stream of incoming TLS connections. Polling this stream automatically handles ACME certificate acquisition and renewal, as well as the TLS handshake. When a connection is successfully established, the TLS stream is handed over to the caller.
By default, rustls-acme uses the TLS-ALPN-01 validation mechanism, which is recommended. If your DNS points to an HTTP proxy that terminates TLS, you may need to use HTTP-01 instead.
use futures::prelude::*;
use rustls_acme::{AcmeConfig, caches::DirCache};
#[macro_rules::apply(smol_macros::main!)]
async fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();
let tcp_listener = smol::net::TcpListener::bind("[::]:443").await.unwrap();
let mut tls_incoming = AcmeConfig::new(["example.com"])
.contact_push("mailto:admin@example.com")
.cache(DirCache::new("./rustls_acme_cache"))
.incoming(tcp_listener.incoming(), Vec::new());
while let Some(tls) = tls_incoming.next().await {
let mut tls = tls.unwrap();
smol::spawn(async move {
tls.write_all(HELLO).await.unwrap();
tls.close().await.unwrap();
}).detach();
}
}
const HELLO: &'static [u8] = br"#HTTP/1.1 200 OK
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Hello Tls!"#;