@@ -9,7 +9,8 @@ use std::{
99
1010use futures:: future:: { FutureExt , TryFutureExt } ;
1111use ring:: digest;
12- use rustls:: { ClientConfig , ServerName } ;
12+ use rustls:: ClientConfig ;
13+ use rustls_pki_types:: ServerName ;
1314use tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
1415use tokio_postgres:: tls:: { ChannelBinding , MakeTlsConnect , TlsConnect } ;
1516use tokio_rustls:: { client:: TlsStream , TlsConnector } ;
3940 ServerName :: try_from ( hostname)
4041 . map ( |dns_name| {
4142 RustlsConnect ( Some ( RustlsConnectData {
42- hostname : dns_name,
43+ hostname : dns_name. to_owned ( ) ,
4344 connector : Arc :: clone ( & self . config ) . into ( ) ,
4445 } ) )
4546 } )
5051pub struct RustlsConnect ( Option < RustlsConnectData > ) ;
5152
5253struct RustlsConnectData {
53- hostname : ServerName ,
54+ hostname : ServerName < ' static > ,
5455 connector : TlsConnector ,
5556}
5657
@@ -130,30 +131,62 @@ where
130131mod tests {
131132 use super :: * ;
132133 use futures:: future:: TryFutureExt ;
133- use rustls:: { client:: ServerCertVerified , client:: ServerCertVerifier , Certificate , Error } ;
134- use std:: time:: SystemTime ;
135-
134+ use rustls:: {
135+ client:: danger:: ServerCertVerifier ,
136+ client:: danger:: { HandshakeSignatureValid , ServerCertVerified } ,
137+ Error , SignatureScheme ,
138+ } ;
139+ use rustls_pki_types:: { CertificateDer , UnixTime } ;
140+
141+ #[ derive( Debug ) ]
136142 struct AcceptAllVerifier { }
137143 impl ServerCertVerifier for AcceptAllVerifier {
138144 fn verify_server_cert (
139145 & self ,
140- _end_entity : & Certificate ,
141- _intermediates : & [ Certificate ] ,
142- _server_name : & ServerName ,
143- _scts : & mut dyn Iterator < Item = & [ u8 ] > ,
146+ _end_entity : & CertificateDer < ' _ > ,
147+ _intermediates : & [ CertificateDer < ' _ > ] ,
148+ _server_name : & ServerName < ' _ > ,
144149 _ocsp_response : & [ u8 ] ,
145- _now : SystemTime ,
150+ _now : UnixTime ,
146151 ) -> Result < ServerCertVerified , Error > {
147152 Ok ( ServerCertVerified :: assertion ( ) )
148153 }
154+
155+ fn verify_tls12_signature (
156+ & self ,
157+ _message : & [ u8 ] ,
158+ _cert : & CertificateDer < ' _ > ,
159+ _dss : & rustls:: DigitallySignedStruct ,
160+ ) -> Result < rustls:: client:: danger:: HandshakeSignatureValid , Error > {
161+ Ok ( HandshakeSignatureValid :: assertion ( ) )
162+ }
163+
164+ fn verify_tls13_signature (
165+ & self ,
166+ _message : & [ u8 ] ,
167+ _cert : & CertificateDer < ' _ > ,
168+ _dss : & rustls:: DigitallySignedStruct ,
169+ ) -> Result < rustls:: client:: danger:: HandshakeSignatureValid , Error > {
170+ Ok ( HandshakeSignatureValid :: assertion ( ) )
171+ }
172+
173+ fn supported_verify_schemes ( & self ) -> Vec < SignatureScheme > {
174+ vec ! [
175+ SignatureScheme :: ECDSA_NISTP384_SHA384 ,
176+ SignatureScheme :: ECDSA_NISTP256_SHA256 ,
177+ SignatureScheme :: RSA_PSS_SHA512 ,
178+ SignatureScheme :: RSA_PSS_SHA384 ,
179+ SignatureScheme :: RSA_PSS_SHA256 ,
180+ SignatureScheme :: ED25519 ,
181+ ]
182+ }
149183 }
150184
151185 #[ tokio:: test]
152186 async fn it_works ( ) {
153187 env_logger:: builder ( ) . is_test ( true ) . try_init ( ) . unwrap ( ) ;
154188
155189 let mut config = rustls:: ClientConfig :: builder ( )
156- . with_safe_defaults ( )
157190 . with_root_certificates ( rustls:: RootCertStore :: empty ( ) )
158191 . with_no_client_auth ( ) ;
159192 config
0 commit comments