Skip to content

Commit

Permalink
Track the latest changes from upstream rustls (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal authored Sep 23, 2023
1 parent 94bfa8e commit e49f673
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ exclude = ["/.github", "/examples", "/scripts"]

[dependencies]
tokio = "1.0"
rustls = { version = "=0.22.0-alpha.2", default-features = false }
rustls = { version = "=0.22.0-alpha.3", default-features = false }

[features]
default = ["logging", "tls12"]
dangerous_configuration = ["rustls/dangerous_configuration"]
default = ["logging", "tls12", "ring"]
early-data = []
logging = ["rustls/logging"]
ring = ["rustls/ring"]
secret_extraction = ["rustls/secret_extraction"]
tls12 = ["rustls/tls12"]

Expand All @@ -31,4 +31,4 @@ futures-util = "0.3.1"
lazy_static = "1.1"
webpki-roots = "=0.26.0-alpha.1"
rustls-pemfile = "=2.0.0-alpha.1"
webpki = { package = "rustls-webpki", version = "=0.102.0-alpha.2", features = ["alloc", "std"] }
webpki = { package = "rustls-webpki", version = "=0.102.0-alpha.3", features = ["alloc", "std"] }
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn main() -> io::Result<()> {
root_cert_store.add(cert?).unwrap();
}
} else {
root_cert_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
}

let config = rustls::ClientConfig::builder()
Expand Down
20 changes: 9 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use std::sync::Arc;
use std::task::{Context, Poll};

pub use rustls;
use rustls::crypto::ring::Ring;
use rustls::{ClientConfig, ClientConnection, CommonState, ServerConfig, ServerConnection};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

Expand All @@ -68,19 +67,19 @@ pub mod server;
/// A wrapper around a `rustls::ClientConfig`, providing an async `connect` method.
#[derive(Clone)]
pub struct TlsConnector {
inner: Arc<ClientConfig<Ring>>,
inner: Arc<ClientConfig>,
#[cfg(feature = "early-data")]
early_data: bool,
}

/// A wrapper around a `rustls::ServerConfig`, providing an async `accept` method.
#[derive(Clone)]
pub struct TlsAcceptor {
inner: Arc<ServerConfig<Ring>>,
inner: Arc<ServerConfig>,
}

impl From<Arc<ClientConfig<Ring>>> for TlsConnector {
fn from(inner: Arc<ClientConfig<Ring>>) -> TlsConnector {
impl From<Arc<ClientConfig>> for TlsConnector {
fn from(inner: Arc<ClientConfig>) -> TlsConnector {
TlsConnector {
inner,
#[cfg(feature = "early-data")]
Expand All @@ -89,8 +88,8 @@ impl From<Arc<ClientConfig<Ring>>> for TlsConnector {
}
}

impl From<Arc<ServerConfig<Ring>>> for TlsAcceptor {
fn from(inner: Arc<ServerConfig<Ring>>) -> TlsAcceptor {
impl From<Arc<ServerConfig>> for TlsAcceptor {
fn from(inner: Arc<ServerConfig>) -> TlsAcceptor {
TlsAcceptor { inner }
}
}
Expand Down Expand Up @@ -211,10 +210,9 @@ where
/// # Example
///
/// ```no_run
/// # use rustls::crypto::ring::Ring;
/// # fn choose_server_config(
/// # _: rustls::server::ClientHello,
/// # ) -> std::sync::Arc<rustls::ServerConfig<Ring>> {
/// # ) -> std::sync::Arc<rustls::ServerConfig> {
/// # unimplemented!();
/// # }
/// # #[allow(unused_variables)]
Expand Down Expand Up @@ -306,11 +304,11 @@ where
self.accepted.client_hello()
}

pub fn into_stream(self, config: Arc<ServerConfig<Ring>>) -> Accept<IO> {
pub fn into_stream(self, config: Arc<ServerConfig>) -> Accept<IO> {
self.into_stream_with(config, |_| ())
}

pub fn into_stream_with<F>(self, config: Arc<ServerConfig<Ring>>, f: F) -> Accept<IO>
pub fn into_stream_with<F>(self, config: Arc<ServerConfig>, f: F) -> Accept<IO>
where
F: FnOnce(&mut ServerConnection),
{
Expand Down
7 changes: 3 additions & 4 deletions tests/badssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::io;
use std::net::ToSocketAddrs;
use std::sync::Arc;

use rustls::crypto::ring::Ring;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio_rustls::{
Expand All @@ -12,7 +11,7 @@ use tokio_rustls::{
};

async fn get(
config: Arc<ClientConfig<Ring>>,
config: Arc<ClientConfig>,
domain: &str,
port: u16,
) -> io::Result<(TlsStream<TcpStream>, String)> {
Expand All @@ -35,7 +34,7 @@ async fn get(
#[tokio::test]
async fn test_tls12() -> io::Result<()> {
let mut root_store = rustls::RootCertStore::empty();
root_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
root_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let config = rustls::ClientConfig::builder()
.with_safe_default_cipher_suites()
.with_safe_default_kx_groups()
Expand Down Expand Up @@ -67,7 +66,7 @@ fn test_tls13() {
#[tokio::test]
async fn test_modern() -> io::Result<()> {
let mut root_store = rustls::RootCertStore::empty();
root_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
root_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
let config = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
Expand Down
3 changes: 1 addition & 2 deletions tests/early-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::thread;
use std::time::Duration;

use futures_util::{future, future::Future, ready};
use rustls::crypto::ring::Ring;
use rustls::{self, ClientConfig, RootCertStore};
use tokio::io::{split, AsyncRead, AsyncWriteExt, ReadBuf};
use tokio::net::TcpStream;
Expand Down Expand Up @@ -39,7 +38,7 @@ impl<T: AsyncRead + Unpin> Future for Read1<T> {
}

async fn send(
config: Arc<ClientConfig<Ring>>,
config: Arc<ClientConfig>,
addr: SocketAddr,
data: &[u8],
) -> io::Result<TlsStream<TcpStream>> {
Expand Down
7 changes: 1 addition & 6 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{io, thread};

use futures_util::future::TryFutureExt;
use lazy_static::lazy_static;
use rustls::crypto::ring::Ring;
use rustls::ClientConfig;
use rustls_pemfile::{certs, rsa_private_keys};
use tokio::io::{copy, split, AsyncReadExt, AsyncWriteExt};
Expand Down Expand Up @@ -84,11 +83,7 @@ fn start_server() -> &'static (SocketAddr, &'static str, &'static [u8]) {
&TEST_SERVER
}

async fn start_client(
addr: SocketAddr,
domain: &str,
config: Arc<ClientConfig<Ring>>,
) -> io::Result<()> {
async fn start_client(addr: SocketAddr, domain: &str, config: Arc<ClientConfig>) -> io::Result<()> {
const FILE: &[u8] = include_bytes!("../README.md");

let domain = rustls::ServerName::try_from(domain).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ mod utils {
use std::io::{BufReader, Cursor};
use std::sync::Arc;

use rustls::crypto::ring::Ring;
use rustls::{ClientConfig, RootCertStore, ServerConfig};
use rustls_pemfile::{certs, rsa_private_keys};

#[allow(dead_code)]
pub fn make_configs() -> (Arc<ServerConfig<Ring>>, Arc<ClientConfig<Ring>>) {
pub fn make_configs() -> (Arc<ServerConfig>, Arc<ClientConfig>) {
const CERT: &str = include_str!("end.cert");
const CHAIN: &str = include_str!("end.chain");
const RSA: &str = include_str!("end.rsa");
Expand Down

0 comments on commit e49f673

Please sign in to comment.