@@ -12,6 +12,7 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1212use futures_util:: ready;
1313use hyper:: server:: accept:: Accept ;
1414use hyper:: server:: conn:: { AddrIncoming , AddrStream } ;
15+ use tokio_rustls:: rustls:: pki_types:: { self , pem:: PemObject } ;
1516use tokio_rustls:: rustls:: server:: WebPkiClientVerifier ;
1617use tokio_rustls:: rustls:: { Error as TlsError , RootCertStore , ServerConfig } ;
1718
@@ -173,7 +174,7 @@ impl TlsConfigBuilder {
173174
174175 pub ( crate ) fn build ( mut self ) -> Result < ServerConfig , TlsConfigError > {
175176 let mut cert_rdr = BufReader :: new ( self . cert ) ;
176- let cert = rustls_pemfile :: certs ( & mut cert_rdr)
177+ let cert = pki_types :: CertificateDer :: pem_reader_iter ( & mut cert_rdr)
177178 . collect :: < Result < Vec < _ > , _ > > ( )
178179 . map_err ( |_e| TlsConfigError :: CertParseError ) ?;
179180
@@ -188,15 +189,18 @@ impl TlsConfigBuilder {
188189
189190 let mut key_opt = None ;
190191 let mut key_cur = std:: io:: Cursor :: new ( key_vec) ;
191- for item in rustls_pemfile:: read_all ( & mut key_cur)
192- . collect :: < Result < Vec < _ > , _ > > ( )
192+ while let Some ( ( kind, pem) ) = pki_types:: pem:: from_buf ( & mut key_cur)
193193 . map_err ( |_e| TlsConfigError :: InvalidIdentityPem ) ?
194194 {
195- match item {
196- rustls_pemfile:: Item :: Pkcs1Key ( k) => key_opt = Some ( k. into ( ) ) ,
197- rustls_pemfile:: Item :: Pkcs8Key ( k) => key_opt = Some ( k. into ( ) ) ,
198- rustls_pemfile:: Item :: Sec1Key ( k) => key_opt = Some ( k. into ( ) ) ,
199- _ => return Err ( TlsConfigError :: UnknownPrivateKeyFormat ) ,
195+ use pki_types:: pem:: SectionKind ;
196+
197+ if matches ! (
198+ kind,
199+ SectionKind :: PrivateKey | SectionKind :: RsaPrivateKey | SectionKind :: EcPrivateKey
200+ ) {
201+ key_opt = pki_types:: PrivateKeyDer :: from_pem ( kind, pem) ;
202+ } else {
203+ return Err ( TlsConfigError :: UnknownPrivateKeyFormat ) ;
200204 }
201205 }
202206 let key = match key_opt {
@@ -209,9 +213,12 @@ impl TlsConfigBuilder {
209213 ) -> Result < RootCertStore , TlsConfigError > {
210214 let trust_anchors = {
211215 let mut reader = BufReader :: new ( trust_anchor) ;
212- rustls_pemfile :: certs ( & mut reader)
216+ pki_types :: CertificateDer :: pem_reader_iter ( & mut reader)
213217 . collect :: < Result < Vec < _ > , _ > > ( )
214- . map_err ( TlsConfigError :: Io ) ?
218+ . map_err ( |e| match e {
219+ pki_types:: pem:: Error :: Io ( e) => TlsConfigError :: Io ( e) ,
220+ _ => TlsConfigError :: CertParseError ,
221+ } ) ?
215222 } ;
216223
217224 let mut store = RootCertStore :: empty ( ) ;
0 commit comments