mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
Update rcgen code
This commit is contained in:
parent
f1f0f744d6
commit
6b67e603bd
1 changed files with 10 additions and 8 deletions
18
src/main.rs
18
src/main.rs
|
|
@ -9,7 +9,7 @@ use metadata::{FileOptions, PresetMeta};
|
||||||
use {
|
use {
|
||||||
once_cell::sync::Lazy,
|
once_cell::sync::Lazy,
|
||||||
percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS},
|
percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS},
|
||||||
rcgen::{Certificate, CertificateParams, DnType},
|
rcgen::{CertificateParams, DnType, KeyPair},
|
||||||
std::{
|
std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
error::Error,
|
error::Error,
|
||||||
|
|
@ -298,7 +298,7 @@ fn args() -> Result<Args> {
|
||||||
if !matches!(certs, Some(ref certs) if certs.has_domain(domain)) {
|
if !matches!(certs, Some(ref certs) if certs.has_domain(domain)) {
|
||||||
log::info!("No certificate or key found for {:?}, generating them.", s);
|
log::info!("No certificate or key found for {:?}, generating them.", s);
|
||||||
|
|
||||||
let mut cert_params = CertificateParams::new(vec![domain.clone()]);
|
let mut cert_params = CertificateParams::new(vec![domain.clone()])?;
|
||||||
cert_params
|
cert_params
|
||||||
.distinguished_name
|
.distinguished_name
|
||||||
.push(DnType::CommonName, domain);
|
.push(DnType::CommonName, domain);
|
||||||
|
|
@ -306,12 +306,14 @@ fn args() -> Result<Args> {
|
||||||
// <CertificateParams as Default>::default() already implements a
|
// <CertificateParams as Default>::default() already implements a
|
||||||
// date in the far future from the time of writing: 4096-01-01
|
// date in the far future from the time of writing: 4096-01-01
|
||||||
|
|
||||||
if matches.opt_present("e") {
|
let key_pair = if matches.opt_present("e") {
|
||||||
cert_params.alg = &rcgen::PKCS_ED25519;
|
KeyPair::generate_for(&rcgen::PKCS_ED25519)
|
||||||
}
|
} else {
|
||||||
|
KeyPair::generate()
|
||||||
|
}?;
|
||||||
|
|
||||||
// generate the certificate with the configuration
|
// generate the certificate with the configuration
|
||||||
let cert = Certificate::from_params(cert_params)?;
|
let cert = cert_params.self_signed(&key_pair)?;
|
||||||
|
|
||||||
// make sure the certificate directory exists
|
// make sure the certificate directory exists
|
||||||
fs::create_dir(certs_path.join(domain))?;
|
fs::create_dir(certs_path.join(domain))?;
|
||||||
|
|
@ -321,7 +323,7 @@ fn args() -> Result<Args> {
|
||||||
domain,
|
domain,
|
||||||
certificates::CERT_FILE_NAME
|
certificates::CERT_FILE_NAME
|
||||||
)))?;
|
)))?;
|
||||||
cert_file.write_all(&cert.serialize_der()?)?;
|
cert_file.write_all(cert.der())?;
|
||||||
// write key data to disk
|
// write key data to disk
|
||||||
let key_file_path =
|
let key_file_path =
|
||||||
certs_path.join(format!("{}/{}", domain, certificates::KEY_FILE_NAME));
|
certs_path.join(format!("{}/{}", domain, certificates::KEY_FILE_NAME));
|
||||||
|
|
@ -337,7 +339,7 @@ fn args() -> Result<Args> {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
key_file.write_all(&cert.serialize_private_key_der())?;
|
key_file.write_all(key_pair.serialized_der())?;
|
||||||
|
|
||||||
reload_certs = true;
|
reload_certs = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue