74 releases

0.26.0 Mar 22, 2024
0.25.0 Dec 5, 2023
0.25.0-alpha.4 Nov 30, 2023
0.24.1 Jun 9, 2023
0.1.6 Mar 31, 2017

#3 in Asynchronous

Download history 2183323/week @ 2024-07-30 2184393/week @ 2024-08-06 2262961/week @ 2024-08-13 2339917/week @ 2024-08-20 2185822/week @ 2024-08-27 2415222/week @ 2024-09-03 2352247/week @ 2024-09-10 2233060/week @ 2024-09-17 2519813/week @ 2024-09-24 2494412/week @ 2024-10-01 2461945/week @ 2024-10-08 2622019/week @ 2024-10-15 2642696/week @ 2024-10-22 2496338/week @ 2024-10-29 2509768/week @ 2024-11-05 2156753/week @ 2024-11-12

10,279,766 downloads per month
Used in 4,945 crates (540 directly)

MIT/Apache

63KB
1.5K SLoC

tokio-rustls

github actions crates license license docs.rs

Asynchronous TLS/SSL streams for Tokio using Rustls.

Basic Structure of a Client

use rustls_pki_types::ServerName;
use std::sync::Arc;
use tokio::net::TcpStream;
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
use tokio_rustls::TlsConnector;

// ...

let mut root_cert_store = RootCertStore::empty();
root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let config = ClientConfig::builder()
    .with_root_certificates(root_cert_store)
    .with_no_client_auth();
let connector = TlsConnector::from(Arc::new(config));
let dnsname = ServerName::try_from("www.rust-lang.org").unwrap();

let stream = TcpStream::connect(&addr).await?;
let mut stream = connector.connect(dnsname, stream).await?;

// ...

Client Example Program

See examples/client.rs. You can run it with:

cargo run --example client -- hsts.badssl.com

Server Example Program

See examples/server.rs. You can run it with:

cargo run --example server -- 127.0.0.1:8000 --cert mycert.der --key mykey.der

License & Origin

This project is licensed under either of

at your option.

This started as a fork of tokio-tls.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in tokio-rustls by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~9–31MB
~691K SLoC