Skip to content

Commit 9d5788c

Browse files
Merge pull request #1056 from sozu-proxy/update-rustls-to-0.22
update rustls to 0.22.1
2 parents 537352c + 23d8171 commit 9d5788c

File tree

4 files changed

+93
-33
lines changed

4 files changed

+93
-33
lines changed

Cargo.lock

Lines changed: 51 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ nom = { version = "^7.1.3", default-features = true, features = ["std"] }
4343
poule = "^0.3.2"
4444
rand = "^0.8.5"
4545
regex = "^1.10.0"
46-
rustls = "^0.21.10"
47-
rustls-pemfile = "^1.0.4"
46+
rustls = "^0.22.1"
47+
rustls-pemfile = "^2.0.0"
4848
rusty_ulid = "^2.0.0"
4949
sha2 = "^0.10.8"
5050
slab = "^0.4.9"

lib/src/https.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ use mio::{
1616
Interest, Poll, Registry, Token,
1717
};
1818
use rustls::{
19-
cipher_suite::{
20-
TLS13_AES_128_GCM_SHA256, TLS13_AES_256_GCM_SHA384, TLS13_CHACHA20_POLY1305_SHA256,
21-
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
22-
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
23-
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
19+
crypto::{
20+
ring::{
21+
self,
22+
cipher_suite::{
23+
TLS13_AES_128_GCM_SHA256, TLS13_AES_256_GCM_SHA384, TLS13_CHACHA20_POLY1305_SHA256,
24+
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
25+
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
26+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
27+
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
28+
},
29+
},
30+
CryptoProvider,
2431
},
2532
CipherSuite, ProtocolVersion, ServerConfig, ServerConnection, SupportedCipherSuite,
2633
};
@@ -757,9 +764,12 @@ impl HttpsListener {
757764
})
758765
.collect::<Vec<_>>();
759766

760-
let mut server_config = ServerConfig::builder()
761-
.with_cipher_suites(&ciphers[..])
762-
.with_safe_default_kx_groups()
767+
let provider = CryptoProvider {
768+
cipher_suites: ciphers,
769+
..ring::default_provider()
770+
};
771+
772+
let mut server_config = ServerConfig::builder_with_provider(provider.into())
763773
.with_protocol_versions(&versions[..])
764774
.map_err(|err| ListenerError::BuildRustls(err.to_string()))?
765775
.with_no_client_auth()
@@ -1650,14 +1660,12 @@ mod tests {
16501660
.expect("test address 127.0.0.1:1032 should be parsed");
16511661
let resolver = Arc::new(MutexWrappedCertificateResolver::default());
16521662

1653-
let server_config = ServerConfig::builder()
1654-
.with_safe_default_cipher_suites()
1655-
.with_safe_default_kx_groups()
1656-
.with_protocol_versions(&[&rustls::version::TLS12, &rustls::version::TLS13])
1657-
.map_err(|err| ListenerError::BuildRustls(err.to_string()))
1658-
.expect("could not create Rustls server config")
1659-
.with_no_client_auth()
1660-
.with_cert_resolver(resolver.clone());
1663+
let server_config = ServerConfig::builder_with_protocol_versions(&[
1664+
&rustls::version::TLS12,
1665+
&rustls::version::TLS13,
1666+
])
1667+
.with_no_client_auth()
1668+
.with_cert_resolver(resolver.clone());
16611669

16621670
let rustls_details = Arc::new(server_config);
16631671

lib/src/tls.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ use std::{
77
borrow::ToOwned,
88
collections::{HashMap, HashSet},
99
convert::From,
10+
fmt::Debug,
1011
io::BufReader,
1112
str::FromStr,
1213
sync::{Arc, Mutex},
1314
};
1415

1516
use once_cell::sync::Lazy;
1617
use rustls::{
18+
crypto::ring::sign::any_supported_type,
19+
pki_types::{CertificateDer, PrivateKeyDer},
1720
server::{ClientHello, ResolvesServerCert},
1821
sign::CertifiedKey,
19-
Certificate, PrivateKey,
2022
};
2123
use sha2::{Digest, Sha256};
2224
use sozu_command::{
@@ -118,7 +120,7 @@ pub struct CertifiedKeyWrapper {
118120
impl CertifiedKeyWrapper {
119121
/// bytes of the pem formatted certificate, first of the chain
120122
fn pem_bytes(&self) -> &[u8] {
121-
&self.inner.cert[0].0
123+
self.inner.cert[0].as_ref()
122124
}
123125
}
124126

@@ -288,11 +290,11 @@ impl CertificateResolver {
288290
let certificate_pem =
289291
sozu_command::certificate::parse_pem(certificate_and_key.certificate.as_bytes())?;
290292

291-
let mut chain = vec![Certificate(certificate_pem.contents)];
293+
let mut chain = vec![CertificateDer::from(certificate_pem.contents)];
292294
for cert in &certificate_and_key.certificate_chain {
293295
let chain_link = parse_pem(cert.as_bytes())?.contents;
294296

295-
chain.push(Certificate(chain_link));
297+
chain.push(CertificateDer::from(chain_link));
296298
}
297299

298300
let mut key_reader = BufReader::new(certificate_and_key.key.as_bytes());
@@ -305,12 +307,12 @@ impl CertificateResolver {
305307
};
306308

307309
let private_key = match item {
308-
rustls_pemfile::Item::RSAKey(rsa_key) => PrivateKey(rsa_key),
309-
rustls_pemfile::Item::PKCS8Key(pkcs8_key) => PrivateKey(pkcs8_key),
310-
rustls_pemfile::Item::ECKey(ec_key) => PrivateKey(ec_key),
310+
rustls_pemfile::Item::Pkcs1Key(rsa_key) => PrivateKeyDer::from(rsa_key),
311+
rustls_pemfile::Item::Pkcs8Key(pkcs8_key) => PrivateKeyDer::from(pkcs8_key),
312+
rustls_pemfile::Item::Sec1Key(ec_key) => PrivateKeyDer::from(ec_key),
311313
_ => return Err(CertificateResolverError::EmptyKeys),
312314
};
313-
match rustls::sign::any_supported_type(&private_key) {
315+
match any_supported_type(&private_key) {
314316
Ok(signing_key) => {
315317
let stored_certificate = CertifiedKeyWrapper {
316318
inner: Arc::new(CertifiedKey::new(chain, signing_key)),
@@ -466,6 +468,12 @@ impl ResolvesServerCert for MutexWrappedCertificateResolver {
466468
}
467469
}
468470

471+
impl Debug for MutexWrappedCertificateResolver {
472+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
473+
f.write_str("MutexWrappedCertificateResolver")
474+
}
475+
}
476+
469477
// -----------------------------------------------------------------------------
470478
// Unit tests
471479

0 commit comments

Comments
 (0)