@@ -7,7 +7,7 @@ use tokio::sync::mpsc;
7
7
use tokio_rustls:: rustls:: {
8
8
crypto:: CryptoProvider , server:: ResolvesServerCert , sign:: CertifiedKey ,
9
9
} ;
10
- use x509_cert:: { Certificate , certificate :: CertificateInner } ;
10
+ use x509_cert:: Certificate ;
11
11
12
12
use super :: { WEBHOOK_CA_LIFETIME , WEBHOOK_CERTIFICATE_LIFETIME } ;
13
13
@@ -21,12 +21,6 @@ pub enum CertificateResolverError {
21
21
#[ snafu( display( "failed to generate ECDSA signing key" ) ) ]
22
22
GenerateEcdsaSigningKey { source : ecdsa:: Error } ,
23
23
24
- #[ snafu( display( "failed to generate new certificate" ) ) ]
25
- GenerateNewCertificate {
26
- #[ snafu( source( from( CertificateResolverError , Box :: new) ) ) ]
27
- source : Box < CertificateResolverError > ,
28
- } ,
29
-
30
24
#[ snafu( display( "failed to create CA to generate and sign webhook leaf certificate" ) ) ]
31
25
CreateCertificateAuthority { source : stackable_certs:: ca:: Error } ,
32
26
@@ -74,11 +68,8 @@ impl CertificateResolver {
74
68
cert_tx : mpsc:: Sender < Certificate > ,
75
69
) -> Result < Self > {
76
70
let subject_alterative_dns_names = Arc :: new ( subject_alterative_dns_names) ;
77
- let ( cert, certified_key) = Self :: generate_new_cert ( subject_alterative_dns_names. clone ( ) )
78
- . await
79
- . context ( GenerateNewCertificateSnafu ) ?;
80
-
81
- Self :: send_certificate_to_channel ( cert, & cert_tx) . await ?;
71
+ let certified_key =
72
+ Self :: generate_new_cert ( & cert_tx, subject_alterative_dns_names. clone ( ) ) . await ?;
82
73
83
74
Ok ( Self {
84
75
subject_alterative_dns_names,
@@ -88,27 +79,29 @@ impl CertificateResolver {
88
79
}
89
80
90
81
pub async fn rotate_certificate ( & self ) -> Result < ( ) > {
91
- let ( cert, certified_key) =
92
- Self :: generate_new_cert ( self . subject_alterative_dns_names . clone ( ) )
93
- . await
94
- . context ( GenerateNewCertificateSnafu ) ?;
82
+ let certified_key =
83
+ Self :: generate_new_cert ( & self . cert_tx , self . subject_alterative_dns_names . clone ( ) )
84
+ . await ?;
95
85
96
86
// TODO: Sign the new cert somehow with the old cert. See https://github.com/stackabletech/decisions/issues/56
97
-
98
- Self :: send_certificate_to_channel ( cert, & self . cert_tx ) . await ?;
99
87
self . current_certified_key . store ( certified_key) ;
100
88
101
89
Ok ( ( ) )
102
90
}
103
91
92
+ /// Creates a new certificate and returns the certified key.
93
+ ///
94
+ /// The certificate is send to the passed `cert_tx`.
95
+ ///
104
96
/// FIXME: This should *not* construct a CA cert and cert, but only a cert!
105
97
/// This needs some changes in stackable-certs though.
106
98
/// See [the relevant decision](https://github.com/stackabletech/decisions/issues/56)
107
99
async fn generate_new_cert (
100
+ cert_tx : & mpsc:: Sender < Certificate > ,
108
101
subject_alterative_dns_names : Arc < Vec < String > > ,
109
- ) -> Result < ( Certificate , Arc < CertifiedKey > ) > {
102
+ ) -> Result < Arc < CertifiedKey > > {
110
103
// The certificate generations can take a while, so we use `spawn_blocking`
111
- tokio:: task:: spawn_blocking ( move || {
104
+ let ( cert , certified_key ) = tokio:: task:: spawn_blocking ( move || {
112
105
let tls_provider =
113
106
CryptoProvider :: get_default ( ) . context ( NoDefaultCryptoProviderInstalledSnafu ) ?;
114
107
@@ -142,17 +135,14 @@ impl CertificateResolver {
142
135
) )
143
136
} )
144
137
. await
145
- . context ( TokioSpawnBlockingSnafu ) ?
146
- }
138
+ . context ( TokioSpawnBlockingSnafu ) ??;
147
139
148
- async fn send_certificate_to_channel (
149
- cert : CertificateInner ,
150
- cert_tx : & mpsc:: Sender < Certificate > ,
151
- ) -> Result < ( ) > {
152
140
cert_tx
153
141
. send ( cert)
154
142
. await
155
- . map_err ( |_err| CertificateResolverError :: SendCertificateToChannel )
143
+ . map_err ( |_err| CertificateResolverError :: SendCertificateToChannel ) ?;
144
+
145
+ Ok ( certified_key)
156
146
}
157
147
}
158
148
0 commit comments