@@ -9,7 +9,7 @@ use metadata::{FileOptions, PresetMeta};
9
9
use {
10
10
once_cell:: sync:: Lazy ,
11
11
percent_encoding:: { percent_decode_str, percent_encode, AsciiSet , CONTROLS } ,
12
- rcgen:: { Certificate , CertificateParams , DnType } ,
12
+ rcgen:: { CertificateParams , DnType , KeyPair } ,
13
13
std:: {
14
14
borrow:: Cow ,
15
15
error:: Error ,
@@ -298,20 +298,22 @@ fn args() -> Result<Args> {
298
298
if !matches ! ( certs, Some ( ref certs) if certs. has_domain( domain) ) {
299
299
log:: info!( "No certificate or key found for {:?}, generating them." , s) ;
300
300
301
- let mut cert_params = CertificateParams :: new ( vec ! [ domain. clone( ) ] ) ;
301
+ let mut cert_params = CertificateParams :: new ( vec ! [ domain. clone( ) ] ) ? ;
302
302
cert_params
303
303
. distinguished_name
304
304
. push ( DnType :: CommonName , domain) ;
305
305
306
306
// <CertificateParams as Default>::default() already implements a
307
307
// date in the far future from the time of writing: 4096-01-01
308
308
309
- if matches. opt_present ( "e" ) {
310
- cert_params. alg = & rcgen:: PKCS_ED25519 ;
311
- }
309
+ let key_pair = if matches. opt_present ( "e" ) {
310
+ KeyPair :: generate_for ( & rcgen:: PKCS_ED25519 )
311
+ } else {
312
+ KeyPair :: generate ( )
313
+ } ?;
312
314
313
315
// generate the certificate with the configuration
314
- let cert = Certificate :: from_params ( cert_params) ?;
316
+ let cert = cert_params. self_signed ( & key_pair ) ?;
315
317
316
318
// make sure the certificate directory exists
317
319
fs:: create_dir ( certs_path. join ( domain) ) ?;
@@ -321,7 +323,7 @@ fn args() -> Result<Args> {
321
323
domain,
322
324
certificates:: CERT_FILE_NAME
323
325
) ) ) ?;
324
- cert_file. write_all ( & cert. serialize_der ( ) ? ) ?;
326
+ cert_file. write_all ( cert. der ( ) ) ?;
325
327
// write key data to disk
326
328
let key_file_path =
327
329
certs_path. join ( format ! ( "{}/{}" , domain, certificates:: KEY_FILE_NAME ) ) ;
@@ -337,7 +339,7 @@ fn args() -> Result<Args> {
337
339
) ,
338
340
}
339
341
}
340
- key_file. write_all ( & cert . serialize_private_key_der ( ) ) ?;
342
+ key_file. write_all ( key_pair . serialized_der ( ) ) ?;
341
343
342
344
reload_certs = true ;
343
345
}
0 commit comments