Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to use rustls 0.22.0-alpha.4 #12

Merged
merged 15 commits into from
Nov 28, 2023
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
env:
CARGO_TERM_COLOR: always
CARGO_NET_RETRY: 10
CARGO_INCREMENTAL: 0

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ admin/rustfmt
**/._.DS_Store
/.idea
/default.profraw
.cargo/
35 changes: 32 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[workspace]
members = ["examples","rustls-mbedcrypto-provider", "rustls-mbedpki-provider"]
default-members = ["rustls-mbedcrypto-provider", "rustls-mbedpki-provider"]
members = [
"examples",
"rustls-mbedcrypto-provider",
"rustls-mbedpki-provider",
"rustls-mbedtls-provider-utils",
]
default-members = ["rustls-mbedcrypto-provider", "rustls-mbedpki-provider", "rustls-mbedtls-provider-utils"]
resolver = "2"
4 changes: 1 addition & 3 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ publish = false
rustls-mbedcrypto-provider = { path = "../rustls-mbedcrypto-provider" }
rustls-mbedpki-provider = { path = "../rustls-mbedpki-provider" }
env_logger = "0.10"
# TODO: upgrade to use formal 0.22.0 or 0.22.0-* versions when availabe
rustls = { git = "https://github.com/rustls/rustls", rev = "b776a5778ad333653670c34ff9125d8ae59b6047", version = "0.22.0-alpha.4", default-features = false }
rustls = { version = "0.22.0-alpha.4", default-features = false }
rustls-native-certs = "0.6.3"

19 changes: 14 additions & 5 deletions rustls-mbedcrypto-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ categories = ["network-programming", "cryptography"]
resolver = "2"

[dependencies]
# TODO: upgrade to use formal 0.22.0 or 0.22.0-* versions when availabe
rustls = { git = "https://github.com/rustls/rustls", rev = "b776a5778ad333653670c34ff9125d8ae59b6047", version = "0.22.0-alpha.4", default-features = false }
rustls = { version = "0.22.0-alpha.4", default-features = false }
mbedtls = { version = "0.12.0-alpha.2", default-features = false, features = [
"std",
] }
log = { version = "0.4.20", optional = true }
log = { version = "0.4.4", optional = true }
pki-types = { package = "rustls-pki-types", version = "0.2.1", features = [
"std",
] }
webpki = { package = "rustls-webpki", version = "0.102.0-alpha.6", features = [
"alloc",
"std",
], default-features = false }
utils = { package = "rustls-mbedtls-provider-utils", path = "../rustls-mbedtls-provider-utils", version = "0.1.0-alpha.1" }
yasna = { version = "0.3", default-features = false, features = ["bit-vec"] }
bit-vec = "0.6.3"

[target.'cfg(target_env = "msvc")'.dependencies]
# mbedtls need feature `time` to build when targeting msvc
Expand All @@ -27,7 +36,7 @@ mbedtls = { version = "0.12.0-alpha.2", default-features = false, features = [
] }

[dev-dependencies]
rustls = { git = "https://github.com/rustls/rustls", rev = "b776a5778ad333653670c34ff9125d8ae59b6047", version = "0.22.0-alpha.4", default-features = false, features = [
rustls = { version = "0.22.0-alpha.4", default-features = false, features = [
"ring",
] }
webpki = { package = "rustls-webpki", version = "0.102.0-alpha.1", default-features = false, features = [
Expand All @@ -38,7 +47,7 @@ pki-types = { package = "rustls-pki-types", version = "0.2.0" }
webpki-roots = "0.26.0-alpha.2"
rustls-pemfile = "=2.0.0-alpha.2"
env_logger = "0.10"
log = { version = "0.4.20" }
log = { version = "0.4.4" }

[features]
default = ["logging", "tls12"]
Expand Down
34 changes: 13 additions & 21 deletions rustls-mbedcrypto-provider/examples/internal/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::time::{Duration, Instant};
use pki_types::{CertificateDer, PrivateKeyDer};

use rustls::client::Resumption;
use rustls::crypto::ring::Ticketer;
use rustls::crypto::ring::{cipher_suite, Ticketer};
use rustls::server::{NoServerSessionStorage, ServerSessionMemoryCache, WebPkiClientVerifier};
use rustls::RootCertStore;
use rustls::{ClientConfig, ClientConnection};
Expand Down Expand Up @@ -178,68 +178,60 @@ static ALL_BENCHMARKS: &[BenchmarkParam] = &[
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
cipher_suite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Ecdsa,
rustls::cipher_suite::TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
cipher_suite::TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
cipher_suite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
cipher_suite::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
cipher_suite::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Ecdsa,
rustls::cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
&rustls::version::TLS12,
),
#[cfg(feature = "tls12")]
BenchmarkParam::new(
KeyType::Ecdsa,
rustls::cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
&rustls::version::TLS12,
),
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS13_CHACHA20_POLY1305_SHA256,
&rustls::version::TLS13,
),
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS13_AES_256_GCM_SHA384,
&rustls::version::TLS13,
),
BenchmarkParam::new(
KeyType::Rsa,
rustls::cipher_suite::TLS13_AES_128_GCM_SHA256,
cipher_suite::TLS13_CHACHA20_POLY1305_SHA256,
&rustls::version::TLS13,
),
BenchmarkParam::new(KeyType::Rsa, cipher_suite::TLS13_AES_256_GCM_SHA384, &rustls::version::TLS13),
BenchmarkParam::new(KeyType::Rsa, cipher_suite::TLS13_AES_128_GCM_SHA256, &rustls::version::TLS13),
BenchmarkParam::new(
KeyType::Ecdsa,
rustls::cipher_suite::TLS13_AES_128_GCM_SHA256,
cipher_suite::TLS13_AES_128_GCM_SHA256,
&rustls::version::TLS13,
),
BenchmarkParam::new(
KeyType::Ed25519,
rustls::cipher_suite::TLS13_AES_128_GCM_SHA256,
cipher_suite::TLS13_AES_128_GCM_SHA256,
&rustls::version::TLS13,
),
];
Expand Down
9 changes: 9 additions & 0 deletions rustls-mbedcrypto-provider/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub(crate) static MBED_SHA_384: Algorithm = Algorithm {
output_len: 384 / 8,
};

/// SHA-512 as specified in [FIPS 180-4].
///
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
pub(crate) static MBED_SHA_512: Algorithm = Algorithm {
hash_algorithm: HashAlgorithm::SHA512,
hash_type: mbedtls::hash::Type::Sha512,
output_len: 512 / 8,
};

impl hash::Hash for Hash {
fn start(&self) -> Box<dyn hash::Context> {
Box::new(HashContext(MbedHashContext::new(self.0)))
Expand Down
13 changes: 3 additions & 10 deletions rustls-mbedcrypto-provider/src/kx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use super::agreement;
use crate::error::mbedtls_err_to_rustls_general_error;

use crate::log::error;
use alloc::boxed::Box;
use alloc::fmt;
use alloc::format;
Expand Down Expand Up @@ -42,15 +41,12 @@
}

impl SupportedKxGroup for KxGroup {
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, rustls::crypto::GetRandomFailed> {
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, Error> {
let mut pk = PkMbed::generate_ec(
&mut super::rng::rng_new().ok_or(rustls::crypto::GetRandomFailed)?,
self.agreement_algorithm.group_id,
)
.map_err(|_err| {
error!("Encountered error when generating ec key, mbedtls error: {}", _err);
rustls::crypto::GetRandomFailed
})?;
.map_err(|err| rustls::Error::General(format!("Encountered error when generating ec key, mbedtls error: {}", err)))?;

fn get_key_pair(pk: &mut PkMbed, kx_group: &KxGroup) -> Result<KeyExchange, mbedtls::Error> {
let group = EcGroup::new(kx_group.agreement_algorithm.group_id)?;
Expand All @@ -68,10 +64,7 @@

match get_key_pair(&mut pk, self) {
Ok(group) => Ok(Box::new(group)),
Err(_err) => {
error!("Unexpected mbedtls error: {}", _err);
Err(rustls::crypto::GetRandomFailed)
}
Err(err) => Err(rustls::Error::General(format!("Unexpected mbedtls error: {}", err))),

Check warning on line 67 in rustls-mbedcrypto-provider/src/kx.rs

View check run for this annotation

Codecov / codecov/patch

rustls-mbedcrypto-provider/src/kx.rs#L67

Added line #L67 was not covered by tests
}
}

Expand Down
Loading