@@ -5,6 +5,7 @@ use std::{
5
5
sync:: Arc ,
6
6
} ;
7
7
use tokio_rustls:: { rustls, TlsAcceptor } ;
8
+ use crate :: tls:: rustls:: pki_types:: { CertificateDer , PrivatePkcs8KeyDer } ;
8
9
9
10
/// TLS configuration for the server.
10
11
#[ derive( Clone ) ]
@@ -22,25 +23,22 @@ 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 ( certs, tokio_rustls :: rustls :: pki_types :: PrivateKeyDer :: Pkcs8 ( keys. remove ( 0 ) ) )
28
28
. map_err ( |e| anyhow:: anyhow!( "{}" , e) ) ?;
29
29
30
30
Ok ( Arc :: new ( cfg) . into ( ) )
31
31
}
32
32
}
33
33
34
34
// Loads public certificate from file.
35
- fn load_certs ( path : impl AsRef < Path > ) -> io:: Result < Vec < rustls :: Certificate > > {
35
+ fn load_certs ( path : impl AsRef < Path > ) -> io:: Result < Vec < CertificateDer < ' static > > > {
36
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 ( ) )
37
+ . collect ( )
39
38
}
40
39
41
40
// Loads private key from file.
42
- fn load_keys ( path : impl AsRef < Path > ) -> io:: Result < Vec < rustls :: PrivateKey > > {
41
+ fn load_keys ( path : impl AsRef < Path > ) -> io:: Result < Vec < PrivatePkcs8KeyDer < ' static > > > {
43
42
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
+ . collect ( )
46
44
}
0 commit comments