Skip to content

Commit 1eea0aa

Browse files
committed
upgrade rustls to 0.23
* With rustls 0.23 there is no longer a dependency on ring, allowing for easier compilation for various targets.
1 parent 898f230 commit 1eea0aa

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ serde_json = { version = "^1.0" }
2424

2525
# Optional dependencies
2626
openssl = { version = "0.10", optional = true }
27-
rustls = { version = "0.21", optional = true, features = ["dangerous_configuration"] }
27+
rustls = { version = "0.23", optional = true }
2828
webpki-roots = { version = "0.25", optional = true }
2929

3030
byteorder = { version = "1.0", optional = true }

src/raw_client.rs

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ use bitcoin::{Script, Txid};
2121

2222
#[cfg(feature = "use-openssl")]
2323
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
24+
use rustls::pki_types::{Der, TrustAnchor};
2425
#[cfg(all(
2526
any(feature = "default", feature = "use-rustls"),
2627
not(feature = "use-openssl")
2728
))]
28-
use rustls::{
29-
ClientConfig, ClientConnection, OwnedTrustAnchor, RootCertStore, ServerName, StreamOwned,
30-
};
29+
use rustls::{pki_types::ServerName, ClientConfig, ClientConnection, RootCertStore, StreamOwned};
3130

3231
#[cfg(any(feature = "default", feature = "proxy"))]
3332
use crate::socks::{Socks5Stream, TargetAddr, ToTargetAddr};
@@ -287,25 +286,48 @@ impl RawClient<ElectrumSslStream> {
287286
not(feature = "use-openssl")
288287
))]
289288
mod danger {
290-
use rustls;
291-
use rustls::client::ServerCertVerified;
292-
use rustls::{Certificate, Error, ServerName};
293-
use std::time::SystemTime;
289+
use raw_client::ServerName;
290+
use rustls::client::danger::ServerCertVerified;
291+
use rustls::pki_types::CertificateDer;
292+
use rustls::pki_types::UnixTime;
293+
use rustls::Error;
294294

295+
#[derive(Debug)]
295296
pub struct NoCertificateVerification {}
296297

297-
impl rustls::client::ServerCertVerifier for NoCertificateVerification {
298+
impl rustls::client::danger::ServerCertVerifier for NoCertificateVerification {
298299
fn verify_server_cert(
299300
&self,
300-
_end_entity: &Certificate,
301-
_intermediates: &[Certificate],
301+
_end_entity: &CertificateDer,
302+
_intermediates: &[CertificateDer],
302303
_server_name: &ServerName,
303-
_scts: &mut dyn Iterator<Item = &[u8]>,
304304
_ocsp_response: &[u8],
305-
_now: SystemTime,
305+
_now: UnixTime,
306306
) -> Result<ServerCertVerified, Error> {
307307
Ok(ServerCertVerified::assertion())
308308
}
309+
310+
fn verify_tls12_signature(
311+
&self,
312+
_message: &[u8],
313+
_cert: &CertificateDer<'_>,
314+
_dss: &rustls::DigitallySignedStruct,
315+
) -> Result<rustls::client::danger::HandshakeSignatureValid, Error> {
316+
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
317+
}
318+
319+
fn verify_tls13_signature(
320+
&self,
321+
_message: &[u8],
322+
_cert: &CertificateDer<'_>,
323+
_dss: &rustls::DigitallySignedStruct,
324+
) -> Result<rustls::client::danger::HandshakeSignatureValid, Error> {
325+
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
326+
}
327+
328+
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
329+
vec![]
330+
}
309331
}
310332
}
311333

@@ -358,24 +380,25 @@ impl RawClient<ElectrumSslStream> {
358380
) -> Result<Self, Error> {
359381
use std::convert::TryFrom;
360382

361-
let builder = ClientConfig::builder().with_safe_defaults();
383+
let builder = ClientConfig::builder();
362384

363385
let config = if validate_domain {
364386
socket_addr.domain().ok_or(Error::MissingDomain)?;
365387

366-
let mut store = RootCertStore::empty();
367-
store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.into_iter().map(|t| {
368-
OwnedTrustAnchor::from_subject_spki_name_constraints(
369-
t.subject,
370-
t.spki,
371-
t.name_constraints,
372-
)
373-
}));
388+
let store = webpki_roots::TLS_SERVER_ROOTS
389+
.into_iter()
390+
.map(|t| TrustAnchor {
391+
subject: Der::from_slice(t.subject),
392+
subject_public_key_info: Der::from_slice(t.spki),
393+
name_constraints: t.name_constraints.map(|nc| Der::from_slice(nc)),
394+
})
395+
.collect::<RootCertStore>();
374396

375397
// TODO: cert pinning
376398
builder.with_root_certificates(store).with_no_client_auth()
377399
} else {
378400
builder
401+
.dangerous()
379402
.with_custom_certificate_verifier(std::sync::Arc::new(
380403
danger::NoCertificateVerification {},
381404
))
@@ -385,7 +408,7 @@ impl RawClient<ElectrumSslStream> {
385408
let domain = socket_addr.domain().unwrap_or("NONE").to_string();
386409
let session = ClientConnection::new(
387410
std::sync::Arc::new(config),
388-
ServerName::try_from(domain.as_str())
411+
ServerName::try_from(domain.clone())
389412
.map_err(|_| Error::InvalidDNSNameError(domain.clone()))?,
390413
)
391414
.map_err(Error::CouldNotCreateConnection)?;

0 commit comments

Comments
 (0)