11use std:: sync:: Arc ;
22
33use arc_swap:: ArcSwap ;
4- use snafu:: { ResultExt , Snafu } ;
4+ use snafu:: { OptionExt , ResultExt , Snafu } ;
55use stackable_certs:: { CertificatePairError , ca:: CertificateAuthority , keys:: ecdsa} ;
66use tokio:: sync:: mpsc;
77use tokio_rustls:: rustls:: {
8- crypto:: ring :: default_provider , server:: ResolvesServerCert , sign:: CertifiedKey ,
8+ crypto:: CryptoProvider , server:: ResolvesServerCert , sign:: CertifiedKey ,
99} ;
1010use x509_cert:: Certificate ;
1111
@@ -48,6 +48,9 @@ pub enum CertificateResolverError {
4848
4949 #[ snafu( display( "failed to run task in blocking thread" ) ) ]
5050 TokioSpawnBlocking { source : tokio:: task:: JoinError } ,
51+
52+ #[ snafu( display( "no default rustls CryptoProvider installed" ) ) ]
53+ NoDefaultCryptoProviderInstalled { } ,
5154}
5255
5356/// This struct serves as [`ResolvesServerCert`] to always hand out the current certificate for TLS
@@ -113,7 +116,8 @@ impl CertificateResolver {
113116 ) -> Result < ( Certificate , Arc < CertifiedKey > ) > {
114117 // The certificate generations can take a while, so we use `spawn_blocking`
115118 tokio:: task:: spawn_blocking ( move || {
116- let tls_provider = default_provider ( ) ;
119+ let tls_provider =
120+ CryptoProvider :: get_default ( ) . context ( NoDefaultCryptoProviderInstalledSnafu ) ?;
117121
118122 let ca_key = ecdsa:: SigningKey :: new ( ) . context ( GenerateEcdsaSigningKeySnafu ) ?;
119123 let mut ca =
@@ -139,7 +143,10 @@ impl CertificateResolver {
139143 CertifiedKey :: from_der ( vec ! [ certificate_der] , private_key_der, & tls_provider)
140144 . context ( DecodeCertifiedKeyFromDerSnafu ) ?;
141145
142- Ok ( ( certificate_pair. certificate ( ) . clone ( ) , Arc :: new ( certificate_key) ) )
146+ Ok ( (
147+ certificate_pair. certificate ( ) . clone ( ) ,
148+ Arc :: new ( certificate_key) ,
149+ ) )
143150 } )
144151 . await
145152 . context ( TokioSpawnBlockingSnafu ) ?
0 commit comments