Skip to content

Commit 7420e78

Browse files
authored
Try validation workspace approach (#46)
1 parent 9d86cdb commit 7420e78

File tree

7 files changed

+167
-0
lines changed

7 files changed

+167
-0
lines changed

validation/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# rustls-rustcrypto Validation
2+
3+
These are collection of crates that can be used to validate integration
4+
between rustls and rustcrypto-rustcrypto provider under different targets.
5+
6+
| Crate | Description |
7+
| :--- | :--- |
8+
| consumer-no_std | Basic consumer library aiming no_std environment |
9+
10+
These live in the workspace due to different dependency requirements between
11+
tests where development-deps may pollute the integration under test.
12+
13+
This is aimed for internal validation without requiring further upstream
14+
dependencies which are may or may not be in lock-step with current version of
15+
rustls the provider targets in any given time.

validation/consumer-no_std/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "consumer-no_std"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.orxg/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rustls-rustcrypto = { path = "../../" }
10+
rustls = { version = "0.23", default-features = false }

validation/consumer-no_std/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# no_std Consumer build
2+
3+
Simple self-tester to validate no_std build with a given rustls version.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub(crate) mod fake_cert_verifier;
2+
pub(crate) mod fake_time_provider;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use rustls::client::danger::HandshakeSignatureValid;
2+
use rustls::client::danger::ServerCertVerified;
3+
use rustls::client::danger::ServerCertVerifier;
4+
use rustls::pki_types::CertificateDer;
5+
use rustls::pki_types::ServerName;
6+
use rustls::pki_types::UnixTime;
7+
use rustls::DigitallySignedStruct;
8+
use rustls::Error;
9+
use rustls::SignatureScheme;
10+
11+
use alloc::vec::Vec;
12+
13+
#[derive(Debug)]
14+
pub(crate) struct FakeServerCertVerifier;
15+
16+
impl ServerCertVerifier for FakeServerCertVerifier {
17+
fn verify_server_cert(
18+
&self,
19+
_end_entity: &CertificateDer<'_>,
20+
_intermediates: &[CertificateDer<'_>],
21+
_server_name: &ServerName<'_>,
22+
_ocsp_response: &[u8],
23+
_now: UnixTime,
24+
) -> Result<ServerCertVerified, Error> {
25+
Ok(ServerCertVerified::assertion())
26+
}
27+
fn verify_tls12_signature(
28+
&self,
29+
_message: &[u8],
30+
_cert: &CertificateDer<'_>,
31+
_dss: &DigitallySignedStruct,
32+
) -> Result<HandshakeSignatureValid, Error> {
33+
Ok(HandshakeSignatureValid::assertion())
34+
}
35+
fn verify_tls13_signature(
36+
&self,
37+
_message: &[u8],
38+
_cert: &CertificateDer<'_>,
39+
_dss: &DigitallySignedStruct,
40+
) -> Result<HandshakeSignatureValid, Error> {
41+
Ok(HandshakeSignatureValid::assertion())
42+
}
43+
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
44+
alloc::vec![
45+
SignatureScheme::RSA_PKCS1_SHA1,
46+
SignatureScheme::ECDSA_SHA1_Legacy,
47+
SignatureScheme::RSA_PKCS1_SHA256,
48+
SignatureScheme::ECDSA_NISTP256_SHA256,
49+
SignatureScheme::RSA_PKCS1_SHA384,
50+
SignatureScheme::ECDSA_NISTP384_SHA384,
51+
SignatureScheme::RSA_PKCS1_SHA512,
52+
SignatureScheme::ECDSA_NISTP521_SHA512,
53+
SignatureScheme::RSA_PSS_SHA256,
54+
SignatureScheme::RSA_PSS_SHA384,
55+
SignatureScheme::RSA_PSS_SHA512,
56+
SignatureScheme::ED25519,
57+
SignatureScheme::ED448,
58+
//SignatureScheme::Unknown(u16),
59+
]
60+
}
61+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use rustls::time_provider::TimeProvider;
2+
//use core::time::Duration;
3+
use rustls::pki_types::UnixTime;
4+
5+
// Required for no_std
6+
#[derive(Debug)]
7+
pub(crate) struct FakeTime;
8+
9+
// TODO: Figure how to handle time
10+
impl TimeProvider for FakeTime {
11+
fn current_time(&self) -> Option<UnixTime> {
12+
None
13+
}
14+
}

validation/consumer-no_std/src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#![no_std]
2+
#![forbid(unsafe_code)]
3+
#![warn(
4+
clippy::unwrap_used,
5+
//missing_docs,
6+
rust_2018_idioms,
7+
unused_lifetimes,
8+
unused_qualifications
9+
)]
10+
#![doc = include_str!("../README.md")]
11+
#![allow(dead_code)] // HEAVY TODO
12+
13+
//! RusTLS RustCrypto ValidationProvider
14+
//! This crate is used to internally minimally validate the provider in CI
15+
//! Obviously - don't use in prod ;-)
16+
17+
// I hope in future there is an API without Arc for providers
18+
extern crate alloc;
19+
use alloc::sync::Arc;
20+
21+
use rustls::client::ClientConfig as RusTlsClientConfig;
22+
23+
use rustls_rustcrypto::provider as rustcrypto_provider;
24+
25+
// TODO: rustcrypto tls PKI verifier provider missing
26+
// We are not testing webpki / rustls itself which typically handle certificates
27+
// Perhaps a separate crate for PKI operations e.g. cert verifying and then test that ?
28+
mod fakes;
29+
use crate::fakes::fake_cert_verifier::FakeServerCertVerifier;
30+
use crate::fakes::fake_time_provider::FakeTime;
31+
32+
pub struct ProviderValidatorClient {
33+
pub(crate) rustls_client_config: RusTlsClientConfig,
34+
}
35+
36+
impl ProviderValidatorClient {
37+
pub fn builder() -> Self {
38+
let provider = rustcrypto_provider();
39+
let time_provider = FakeTime {};
40+
41+
let fake_server_cert_verifier = FakeServerCertVerifier {};
42+
43+
let builder_init =
44+
RusTlsClientConfig::builder_with_details(Arc::new(provider), Arc::new(time_provider));
45+
46+
let builder_default_versions = builder_init
47+
.with_safe_default_protocol_versions()
48+
.expect("Default protocol versions error?");
49+
50+
// TODO - test with different verifiers
51+
let dangerous_verifier = builder_default_versions
52+
.dangerous()
53+
.with_custom_certificate_verifier(Arc::new(fake_server_cert_verifier));
54+
55+
// Out of scope
56+
let rustls_client_config = dangerous_verifier.with_no_client_auth();
57+
58+
Self {
59+
rustls_client_config,
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)