Skip to content

Commit 3751b71

Browse files
committed
feat: add rustls_platform_verifier::tls_config_with_provider
1 parent ae5f7a8 commit 3751b71

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ To get a rustls `ClientConfig` configured to use the platform verifier use:
5858
let config = rustls_platform_verifier::tls_config();
5959
```
6060

61+
This crate will use the [rustls process-default crypto provider](https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#using-the-per-process-default-cryptoprovider). To construct a ClientConfig with a different crypto provider, use:
62+
63+
```rust
64+
let arc_crypto_provider = std::sync::Arc::new(rustls::crypto::ring::default_provider());
65+
let config = rustls_platform_verifier::tls_config_with_provider(arc_crypto_provider);
66+
```
67+
6168
If you want to adapt the configuration, you can build the `ClientConfig` like this:
6269

6370
```rust

rustls-platform-verifier/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ pub fn tls_config() -> ClientConfig {
6565
.with_no_client_auth()
6666
}
6767

68+
/// Attempts to construct a `rustls` configuration that verifies TLS certificates in the best way
69+
/// for the underlying OS platform, using the provided
70+
/// [`CryptoProvider`][rustls::crypto::CryptoProvider].
71+
///
72+
/// # Errors
73+
///
74+
/// Propagates any error returned by [`rustls::ConfigBuilder::with_safe_default_protocol_versions`]
75+
pub fn tls_config_with_provider(
76+
provider: Arc<rustls::crypto::CryptoProvider>,
77+
) -> Result<ClientConfig, rustls::Error> {
78+
Ok(ClientConfig::builder_with_provider(provider.clone())
79+
.with_safe_default_protocol_versions()?
80+
.dangerous()
81+
.with_custom_certificate_verifier(Arc::new(Verifier::new().with_provider(provider)))
82+
.with_no_client_auth())
83+
}
84+
6885
/// Exposed for debugging certificate issues with standalone tools.
6986
///
7087
/// This is not intended for production use, you should use [tls_config] instead.

0 commit comments

Comments
 (0)