update rustls v0.20.7 -> v0.21.0 (#137)

* deps: update to rustls 0.21.0.

This commit updates tokio-rustls to use the freshly released Rustls
0.21.0 release tag, and the rustls-webpki fork of webpki.

* tests: improve server wait in early data test.

Previously the `test_0rtt` test had a hardcoded 1s sleep waiting for an
`openssl s_server` process to become ready.

If 1s waiting wasn't long enough, the test could fail with an error
like:

```
Error: Os { code: 10061, kind: ConnectionRefused, message: "No
connection could be made because the target machine actively refused
it." }
```

This commit replaces the hardcoded sleep with a sleep loop that
gradually increases the delay time up to a fixed maximum. This makes the
test run faster when the server is ready quickly and prevents an error
if it takes longer than 1s to stabilize.

* version: 0.23.4 -> 0.24.0
This commit is contained in:
Daniel McCarney 2023-03-30 11:44:26 -04:00 committed by GitHub
parent 7dfc981020
commit 07e8da6e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.23.4" version = "0.24.0"
authors = ["quininer kel <quininer@live.com>"] authors = ["quininer kel <quininer@live.com>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
repository = "https://github.com/tokio-rs/tls" repository = "https://github.com/tokio-rs/tls"
@ -14,8 +14,8 @@ rust-version = "1.56"
[dependencies] [dependencies]
tokio = "1.0" tokio = "1.0"
rustls = { version = "0.20.7", default-features = false } rustls = { version = "0.21.0", default-features = false }
webpki = "0.22" webpki = { package = "rustls-webpki", version = "0.100.0", features = ["alloc", "std"] }
[features] [features]
default = ["logging", "tls12"] default = ["logging", "tls12"]

View File

@ -102,22 +102,34 @@ impl Drop for DropKill {
} }
} }
async fn wait_for_server(addr: &str) {
let tries = 10;
for i in 0..tries {
if let Ok(_) = TcpStream::connect(addr).await {
return;
}
sleep(Duration::from_millis(i * 100)).await;
}
panic!("failed to connect to {:?} after {} tries", addr, tries)
}
#[tokio::test] #[tokio::test]
async fn test_0rtt() -> io::Result<()> { async fn test_0rtt() -> io::Result<()> {
let server_port = 12354;
let mut handle = Command::new("openssl") let mut handle = Command::new("openssl")
.arg("s_server") .arg("s_server")
.arg("-early_data") .arg("-early_data")
.arg("-tls1_3") .arg("-tls1_3")
.args(["-cert", "./tests/end.cert"]) .args(["-cert", "./tests/end.cert"])
.args(["-key", "./tests/end.rsa"]) .args(["-key", "./tests/end.rsa"])
.args(["-port", "12354"]) .args(["-port", &server_port.to_string()])
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()
.map(DropKill)?; .map(DropKill)?;
// wait openssl server // wait openssl server
sleep(Duration::from_secs(1)).await; wait_for_server(format!("127.0.0.1:{}", server_port).as_str()).await;
let mut chain = BufReader::new(Cursor::new(include_str!("end.chain"))); let mut chain = BufReader::new(Cursor::new(include_str!("end.chain")));
let certs = rustls_pemfile::certs(&mut chain).unwrap(); let certs = rustls_pemfile::certs(&mut chain).unwrap();
@ -140,7 +152,7 @@ async fn test_0rtt() -> io::Result<()> {
.with_no_client_auth(); .with_no_client_auth();
config.enable_early_data = true; config.enable_early_data = true;
let config = Arc::new(config); let config = Arc::new(config);
let addr = SocketAddr::from(([127, 0, 0, 1], 12354)); let addr = SocketAddr::from(([127, 0, 0, 1], server_port));
// workaround: write to openssl s_server standard input periodically, to // workaround: write to openssl s_server standard input periodically, to
// get it unstuck on Windows // get it unstuck on Windows