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,23 @@ 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
26
. with_no_client_auth ( )
27
- . with_single_cert ( certs, keys. remove ( 0 ) )
27
+ . with_single_cert (
28
+ certs,
29
+ tokio_rustls:: rustls:: pki_types:: PrivateKeyDer :: Pkcs8 ( keys. remove ( 0 ) ) ,
30
+ )
28
31
. map_err ( |e| anyhow:: anyhow!( "{}" , e) ) ?;
29
32
30
33
Ok ( Arc :: new ( cfg) . into ( ) )
31
34
}
32
35
}
33
36
34
37
// 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 ( ) )
38
+ fn load_certs ( path : impl AsRef < Path > ) -> io:: Result < Vec < CertificateDer < ' static > > > {
39
+ certs ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) ) . collect ( )
39
40
}
40
41
41
42
// 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 ( ) )
43
+ fn load_keys ( path : impl AsRef < Path > ) -> io:: Result < Vec < PrivatePkcs8KeyDer < ' static > > > {
44
+ pkcs8_private_keys ( & mut io:: BufReader :: new ( fs:: File :: open ( path) ?) ) . collect ( )
46
45
}
0 commit comments