1
+ use crate :: tls:: rustls:: pki_types:: { CertificateDer , PrivatePkcs8KeyDer } ;
1
2
use rustls_pemfile:: { certs, pkcs8_private_keys} ;
2
3
use std:: {
3
4
fs, io,
@@ -22,25 +23,24 @@ impl TlsConfig {
22
23
let mut keys = load_keys ( & self . key_path ) ?;
23
24
24
25
let cfg = rustls:: ServerConfig :: builder ( )
25
- . with_safe_defaults ( )
26
+ . with_safe_default_protocol_versions ( )
26
27
. with_no_client_auth ( )
27
- . with_single_cert ( certs, keys. remove ( 0 ) )
28
+ . with_single_cert (
29
+ certs,
30
+ tokio_rustls:: rustls:: pki_types:: PrivateKeyDer :: Pkcs8 ( keys. remove ( 0 ) ) ,
31
+ )
28
32
. map_err ( |e| anyhow:: anyhow!( "{}" , e) ) ?;
29
33
30
34
Ok ( Arc :: new ( cfg) . into ( ) )
31
35
}
32
36
}
33
37
34
38
// Loads public certificate from file.
35
- fn load_certs ( path : impl AsRef < Path > ) -> io:: Result < Vec < rustls:: Certificate > > {
36
- certs ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) )
37
- . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "invalid cert" ) )
38
- . map ( |mut certs| certs. drain ( ..) . map ( rustls:: Certificate ) . collect ( ) )
39
+ fn load_certs ( path : impl AsRef < Path > ) -> io:: Result < Vec < CertificateDer < ' static > > > {
40
+ certs ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) ) . collect ( )
39
41
}
40
42
41
43
// Loads private key from file.
42
- fn load_keys ( path : impl AsRef < Path > ) -> io:: Result < Vec < rustls:: PrivateKey > > {
43
- pkcs8_private_keys ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) )
44
- . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "invalid key" ) )
45
- . map ( |mut keys| keys. drain ( ..) . map ( rustls:: PrivateKey ) . collect ( ) )
44
+ fn load_keys ( path : impl AsRef < Path > ) -> io:: Result < Vec < PrivatePkcs8KeyDer < ' static > > > {
45
+ pkcs8_private_keys ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) ) . collect ( )
46
46
}
0 commit comments