@@ -5,7 +5,7 @@ use const_oid::db::rfc5280::{ID_KP_CLIENT_AUTH, ID_KP_SERVER_AUTH};
5
5
use rsa:: pkcs8:: EncodePublicKey ;
6
6
use snafu:: { ResultExt , Snafu } ;
7
7
use stackable_operator:: time:: Duration ;
8
- use tracing:: { debug, warn} ;
8
+ use tracing:: { debug, instrument , warn} ;
9
9
use x509_cert:: {
10
10
builder:: { Builder , Profile } ,
11
11
der:: { DecodePem , asn1:: Ia5String } ,
@@ -98,12 +98,12 @@ where
98
98
/// Optional list of subject alternative name DNS entries
99
99
/// that are added to the certificate.
100
100
#[ builder( default ) ]
101
- subject_alterative_dns_names : & ' a [ & ' a str ] ,
101
+ subject_alternative_dns_names : & ' a [ & ' a str ] ,
102
102
103
103
/// Optional list of subject alternative name IP address entries
104
104
/// that are added to the certificate.
105
105
#[ builder( default ) ]
106
- subject_alterative_ip_addresses : & ' a [ IpAddr ] ,
106
+ subject_alternative_ip_addresses : & ' a [ IpAddr ] ,
107
107
108
108
/// Validity/lifetime of the certificate.
109
109
///
@@ -132,19 +132,24 @@ where
132
132
}
133
133
}
134
134
135
- impl < KP > CertificateBuilder < ' _ , KP >
135
+ impl < SKP > CertificateBuilder < ' _ , SKP >
136
136
where
137
- KP : CertificateKeypair ,
138
- <KP :: SigningKey as signature:: Keypair >:: VerifyingKey : EncodePublicKey ,
137
+ SKP : CertificateKeypair ,
138
+ <SKP :: SigningKey as signature:: Keypair >:: VerifyingKey : EncodePublicKey ,
139
139
{
140
- pub fn build ( self ) -> Result < CertificatePair < KP > , CreateCertificateError < KP :: Error > > {
140
+ #[ instrument(
141
+ name = "build_certificate" ,
142
+ skip( self ) ,
143
+ fields( subject = self . subject) ,
144
+ ) ]
145
+ pub fn build ( self ) -> Result < CertificatePair < SKP > , CreateCertificateError < SKP :: Error > > {
141
146
let validity = Validity :: from_now ( * self . validity ) . context ( ParseValiditySnafu ) ?;
142
147
let subject: Name = self . subject . parse ( ) . context ( ParseSubjectSnafu {
143
148
subject : self . subject ,
144
149
} ) ?;
145
150
let key_pair = match self . key_pair {
146
151
Some ( key_pair) => key_pair,
147
- None => KP :: new ( ) . context ( CreateKeyPairSnafu ) ?,
152
+ None => SKP :: new ( ) . context ( CreateKeyPairSnafu ) ?,
148
153
} ;
149
154
let serial_number = SerialNumber :: from ( rand:: random :: < u64 > ( ) ) ;
150
155
@@ -170,6 +175,18 @@ where
170
175
let spki = SubjectPublicKeyInfoOwned :: from_pem ( spki_pem. as_bytes ( ) )
171
176
. context ( DecodeSpkiFromPemSnafu ) ?;
172
177
178
+ debug ! (
179
+ certificate. subject = %subject,
180
+ certificate. not_after = %validity. not_after,
181
+ certificate. not_before = %validity. not_before,
182
+ certificate. serial = %serial_number,
183
+ certificate. san. dns_names = ?self . subject_alternative_dns_names,
184
+ certificate. san. ip_addresses = ?self . subject_alternative_ip_addresses,
185
+ certificate. signed_by. issuer = %self . signed_by. issuer_name( ) ,
186
+ certificate. public_key. algorithm = SKP :: algorithm_name( ) ,
187
+ certificate. public_key. size = SKP :: key_size( ) ,
188
+ "creating and signing certificate"
189
+ ) ;
173
190
let signing_key = self . signed_by . signing_key ( ) ;
174
191
let mut builder = x509_cert:: builder:: CertificateBuilder :: new (
175
192
Profile :: Leaf {
@@ -194,28 +211,27 @@ where
194
211
] ) )
195
212
. context ( AddCertificateExtensionSnafu ) ?;
196
213
197
- let san_dns = self . subject_alterative_dns_names . iter ( ) . map ( |dns_name| {
214
+ let san_dns = self . subject_alternative_dns_names . iter ( ) . map ( |dns_name| {
198
215
Ok ( GeneralName :: DnsName (
199
216
Ia5String :: new ( dns_name) . with_context ( |_| ParseSubjectAlternativeDnsNameSnafu {
200
217
subject_alternative_dns_name : dns_name. to_string ( ) ,
201
218
} ) ?,
202
219
) )
203
220
} ) ;
204
221
let san_ips = self
205
- . subject_alterative_ip_addresses
222
+ . subject_alternative_ip_addresses
206
223
. iter ( )
207
224
. copied ( )
208
225
. map ( GeneralName :: from)
209
226
. map ( Result :: Ok ) ;
210
227
let sans = san_dns
211
228
. chain ( san_ips)
212
- . collect :: < Result < Vec < _ > , CreateCertificateError < KP :: Error > > > ( ) ?;
229
+ . collect :: < Result < Vec < _ > , CreateCertificateError < SKP :: Error > > > ( ) ?;
213
230
214
231
builder
215
232
. add_extension ( & SubjectAltName ( sans) )
216
233
. context ( AddCertificateExtensionSnafu ) ?;
217
234
218
- debug ! ( "create and sign leaf certificate" ) ;
219
235
let certificate = builder. build ( ) . context ( BuildCertificateSnafu ) ?;
220
236
221
237
Ok ( CertificatePair {
@@ -271,8 +287,8 @@ mod tests {
271
287
272
288
let certificate = CertificatePair :: builder ( )
273
289
. subject ( "CN=trino-coordinator-default-0" )
274
- . subject_alterative_dns_names ( & sans)
275
- . subject_alterative_ip_addresses ( & san_ips)
290
+ . subject_alternative_dns_names ( & sans)
291
+ . subject_alternative_ip_addresses ( & san_ips)
276
292
. validity ( Duration :: from_days_unchecked ( 42 ) )
277
293
. key_pair ( rsa:: SigningKey :: new ( ) . unwrap ( ) )
278
294
. signed_by ( & ca)
0 commit comments