72 releases

new 0.25.0-alpha.4 Nov 30, 2023
0.25.0-alpha.1 Sep 23, 2023
0.24.1 Jun 9, 2023
0.24.0 Mar 31, 2023
0.1.6 Mar 31, 2017

#5 in Asynchronous

Download history 910095/week @ 2023-08-11 949526/week @ 2023-08-18 944201/week @ 2023-08-25 845650/week @ 2023-09-01 906069/week @ 2023-09-08 936425/week @ 2023-09-15 923277/week @ 2023-09-22 889945/week @ 2023-09-29 992852/week @ 2023-10-06 986521/week @ 2023-10-13 983873/week @ 2023-10-20 1007162/week @ 2023-10-27 997549/week @ 2023-11-03 986922/week @ 2023-11-10 942187/week @ 2023-11-17 744374/week @ 2023-11-24

3,856,695 downloads per month
Used in 3,869 crates (373 directly)

MIT/Apache

57KB
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 std::sync::Arc;
use tokio::net::TcpStream;
use tokio_rustls::rustls::{ClientConfig, OwnedTrustAnchor, RootCertStore, ServerName};
use tokio_rustls::TlsConnector;

// ...

let mut root_cert_store = RootCertStore::empty();
root_cert_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
    OwnedTrustAnchor::from_subject_spki_name_constraints(
        ta.subject,
        ta.spki,
        ta.name_constraints,
    )
}));
let config = ClientConfig::builder()
    .with_safe_defaults()
    .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

~8–17MB
~302K SLoC