@@ -21,12 +21,15 @@ use bitcoin::{Script, Txid};
2121
2222#[ cfg( feature = "use-openssl" ) ]
2323use openssl:: ssl:: { SslConnector , SslMethod , SslStream , SslVerifyMode } ;
24+
2425#[ cfg( all(
2526 any( feature = "default" , feature = "use-rustls" ) ,
2627 not( feature = "use-openssl" )
2728) ) ]
2829use rustls:: {
29- ClientConfig , ClientConnection , OwnedTrustAnchor , RootCertStore , ServerName , StreamOwned ,
30+ pki_types:: ServerName ,
31+ pki_types:: { Der , TrustAnchor } ,
32+ ClientConfig , ClientConnection , RootCertStore , StreamOwned ,
3033} ;
3134
3235#[ cfg( any( feature = "default" , feature = "proxy" ) ) ]
@@ -287,25 +290,48 @@ impl RawClient<ElectrumSslStream> {
287290 not( feature = "use-openssl" )
288291) ) ]
289292mod danger {
290- use rustls;
291- use rustls:: client:: ServerCertVerified ;
292- use rustls:: { Certificate , Error , ServerName } ;
293- use std:: time:: SystemTime ;
293+ use raw_client:: ServerName ;
294+ use rustls:: client:: danger:: ServerCertVerified ;
295+ use rustls:: pki_types:: CertificateDer ;
296+ use rustls:: pki_types:: UnixTime ;
297+ use rustls:: Error ;
294298
299+ #[ derive( Debug ) ]
295300 pub struct NoCertificateVerification { }
296301
297- impl rustls:: client:: ServerCertVerifier for NoCertificateVerification {
302+ impl rustls:: client:: danger :: ServerCertVerifier for NoCertificateVerification {
298303 fn verify_server_cert (
299304 & self ,
300- _end_entity : & Certificate ,
301- _intermediates : & [ Certificate ] ,
305+ _end_entity : & CertificateDer ,
306+ _intermediates : & [ CertificateDer ] ,
302307 _server_name : & ServerName ,
303- _scts : & mut dyn Iterator < Item = & [ u8 ] > ,
304308 _ocsp_response : & [ u8 ] ,
305- _now : SystemTime ,
309+ _now : UnixTime ,
306310 ) -> Result < ServerCertVerified , Error > {
307311 Ok ( ServerCertVerified :: assertion ( ) )
308312 }
313+
314+ fn verify_tls12_signature (
315+ & self ,
316+ _message : & [ u8 ] ,
317+ _cert : & CertificateDer < ' _ > ,
318+ _dss : & rustls:: DigitallySignedStruct ,
319+ ) -> Result < rustls:: client:: danger:: HandshakeSignatureValid , Error > {
320+ Ok ( rustls:: client:: danger:: HandshakeSignatureValid :: assertion ( ) )
321+ }
322+
323+ fn verify_tls13_signature (
324+ & self ,
325+ _message : & [ u8 ] ,
326+ _cert : & CertificateDer < ' _ > ,
327+ _dss : & rustls:: DigitallySignedStruct ,
328+ ) -> Result < rustls:: client:: danger:: HandshakeSignatureValid , Error > {
329+ Ok ( rustls:: client:: danger:: HandshakeSignatureValid :: assertion ( ) )
330+ }
331+
332+ fn supported_verify_schemes ( & self ) -> Vec < rustls:: SignatureScheme > {
333+ vec ! [ ]
334+ }
309335 }
310336}
311337
@@ -358,24 +384,25 @@ impl RawClient<ElectrumSslStream> {
358384 ) -> Result < Self , Error > {
359385 use std:: convert:: TryFrom ;
360386
361- let builder = ClientConfig :: builder ( ) . with_safe_defaults ( ) ;
387+ let builder = ClientConfig :: builder ( ) ;
362388
363389 let config = if validate_domain {
364390 socket_addr. domain ( ) . ok_or ( Error :: MissingDomain ) ?;
365391
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- } ) ) ;
392+ let store = webpki_roots :: TLS_SERVER_ROOTS
393+ . into_iter ( )
394+ . map ( |t| TrustAnchor {
395+ subject : Der :: from_slice ( t. subject ) ,
396+ subject_public_key_info : Der :: from_slice ( t. spki ) ,
397+ name_constraints : t. name_constraints . map ( |nc| Der :: from_slice ( nc ) ) ,
398+ } )
399+ . collect :: < RootCertStore > ( ) ;
374400
375401 // TODO: cert pinning
376402 builder. with_root_certificates ( store) . with_no_client_auth ( )
377403 } else {
378404 builder
405+ . dangerous ( )
379406 . with_custom_certificate_verifier ( std:: sync:: Arc :: new (
380407 danger:: NoCertificateVerification { } ,
381408 ) )
@@ -385,7 +412,7 @@ impl RawClient<ElectrumSslStream> {
385412 let domain = socket_addr. domain ( ) . unwrap_or ( "NONE" ) . to_string ( ) ;
386413 let session = ClientConnection :: new (
387414 std:: sync:: Arc :: new ( config) ,
388- ServerName :: try_from ( domain. as_str ( ) )
415+ ServerName :: try_from ( domain. clone ( ) )
389416 . map_err ( |_| Error :: InvalidDNSNameError ( domain. clone ( ) ) ) ?,
390417 )
391418 . map_err ( Error :: CouldNotCreateConnection ) ?;
0 commit comments