Skip to content

Commit 7e21f2d

Browse files
committed
Net: always use ring as crypto provider
1 parent 6a39f67 commit 7e21f2d

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

lib/net/error.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ pub enum AcceptConnection {
4141
ServerEndpointClosed,
4242
}
4343

44+
pub(in crate::net) mod configure_client {
45+
use thiserror::Error;
46+
47+
#[derive(Debug, Error)]
48+
pub(in crate::net) enum Inner {
49+
#[error(transparent)]
50+
NoInitialCipherSuite(
51+
#[from] quinn::crypto::rustls::NoInitialCipherSuite,
52+
),
53+
#[error("rustls error")]
54+
Rustls(#[source] rustls::Error),
55+
}
56+
57+
#[derive(Debug, Error)]
58+
#[error("failed to configure p2p client")]
59+
#[repr(transparent)]
60+
pub struct Error(#[source] Inner);
61+
62+
impl<E> From<E> for Error
63+
where
64+
Inner: From<E>,
65+
{
66+
fn from(err: E) -> Self {
67+
Self(err.into())
68+
}
69+
}
70+
}
71+
pub use configure_client::Error as ConfigureClient;
72+
4473
#[allow(clippy::duplicated_attributes)]
4574
#[derive(Debug, Error, Transitive)]
4675
#[transitive(from(db::error::Put, db::Error))]
@@ -58,6 +87,8 @@ pub enum Error {
5887
AlreadyConnected(#[from] AlreadyConnected),
5988
#[error("bincode error")]
6089
Bincode(#[from] bincode::Error),
90+
#[error(transparent)]
91+
ConfigureClient(#[from] ConfigureClient),
6192
#[error("connect error")]
6293
Connect(#[from] quinn::ConnectError),
6394
#[error(transparent)]
@@ -74,8 +105,6 @@ pub enum Error {
74105
/// `0.0.0.0` is one example of an "unspecified" IP.
75106
#[error("unspecified peer ip address (cannot connect to '{0}')")]
76107
UnspecfiedPeerIP(IpAddr),
77-
#[error(transparent)]
78-
NoInitialCipherSuite(#[from] quinn::crypto::rustls::NoInitialCipherSuite),
79108
#[error("peer connection")]
80109
PeerConnection(#[source] Box<PeerConnectionError>),
81110
#[error("quinn rustls error")]

lib/net/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ impl rustls::client::danger::ServerCertVerifier for SkipServerVerification {
100100
}
101101
}
102102

103-
fn configure_client()
104-
-> Result<ClientConfig, quinn::crypto::rustls::NoInitialCipherSuite> {
105-
let crypto = rustls::ClientConfig::builder()
103+
fn configure_client() -> Result<ClientConfig, error::ConfigureClient> {
104+
let crypto_provider = Arc::new(rustls::crypto::ring::default_provider());
105+
let crypto = rustls::ClientConfig::builder_with_provider(crypto_provider)
106+
.with_safe_default_protocol_versions()
107+
.map_err(error::configure_client::Inner::Rustls)?
106108
.dangerous()
107109
.with_custom_certificate_verifier(SkipServerVerification::new())
108110
.with_no_client_auth();

0 commit comments

Comments
 (0)