From 64f013a8fba0422f990b2cb6e5025c9e14c2a409 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 23 Oct 2024 16:02:18 +0300 Subject: [PATCH] fix args and config --- src/certs.rs | 2 +- src/common.rs | 26 +++++++++----------------- src/openssl/internal.rs | 7 ++++++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/certs.rs b/src/certs.rs index 081d258..2154e8e 100644 --- a/src/certs.rs +++ b/src/certs.rs @@ -21,7 +21,7 @@ where { pub(crate) fn new(cfg: &AppConfig, provider: T) -> Self { let base_dir = PathBuf::from(&cfg.base_directory); - let keys_dir = base_dir.clone().join(cfg.keys_subdir.clone()); + let keys_dir = base_dir.clone(); let name = cfg.name.clone(); Certs { diff --git a/src/common.rs b/src/common.rs index c70a473..92c13ba 100644 --- a/src/common.rs +++ b/src/common.rs @@ -49,18 +49,10 @@ pub(crate) struct Args { #[arg(short = 'c', long)] pub(crate) encoding: Option, - /// keys subdir - #[arg(long, default_value = ".")] - pub(crate) keys_dir: String, - /// valid days #[arg(long, default_value = "3650")] pub(crate) days: u32, - /// openssl binary or (internal) - #[arg(long, short, default_value = "internal")] - pub(crate) openssl: OpenSSLProviderArg, - /// dns name #[arg(short = 'n', long)] pub(crate) dns: Vec, @@ -77,6 +69,10 @@ pub(crate) struct Args { #[arg(long)] pub(crate) province: Option, + /// Location + #[arg(long)] + pub(crate) loc: Option, + /// Organization #[arg(long)] pub(crate) org: Option, @@ -93,11 +89,9 @@ pub(crate) struct Args { pub(crate) struct AppConfig { pub(crate) encoding: String, pub(crate) req_days: u32, - pub(crate) keys_subdir: String, pub(crate) ca_filename: String, pub(crate) default_email_domain: String, #[allow(unused)] - pub(crate) openssl: OpenSSLProviderArg, pub(crate) base_directory: String, pub(crate) email: String, pub(crate) name: String, @@ -105,6 +99,7 @@ pub(crate) struct AppConfig { pub(crate) ip: Vec, pub(crate) country: Option, pub(crate) province: Option, + pub(crate) loc: Option, pub(crate) org: Option, pub(crate) ou: Option, pub(crate) key_size: u32, @@ -115,10 +110,8 @@ impl Default for AppConfig { Self { encoding: "cp866".into(), req_days: 30650, - keys_subdir: "keys".into(), ca_filename: "ca.crt".into(), default_email_domain: "example.com".into(), - openssl: OpenSSLProviderArg::Internal, base_directory: ".".into(), email: "name@example.com".into(), name: "user".into(), @@ -126,6 +119,7 @@ impl Default for AppConfig { ip: Vec::new(), country: None, province: None, + loc: None, org: None, ou: None, key_size: 2048, @@ -153,14 +147,13 @@ impl From<&Args> for AppConfig { defaults.encoding.clone() }; let name = args.name.clone(); - let openssl = args.openssl.clone(); let req_days = args.days; - let keys_subdir = args.keys_dir.clone(); - let (dns, ip, country, province, org, ou) = ( + let (dns, ip, country, province, loc, org, ou) = ( args.dns.clone(), args.ip.clone(), args.country.clone(), args.province.clone(), + args.loc.clone(), args.org.clone(), args.ou.clone(), ); @@ -170,13 +163,12 @@ impl From<&Args> for AppConfig { email, encoding, name, - openssl, req_days, - keys_subdir, dns, ip, country, province, + loc, org, ou, key_size: args.key_size, diff --git a/src/openssl/internal.rs b/src/openssl/internal.rs index 6740338..130119d 100644 --- a/src/openssl/internal.rs +++ b/src/openssl/internal.rs @@ -90,6 +90,7 @@ pub(crate) struct OpenSSLInternalProvider { ip: Vec, country: Option, province: Option, + location: Option, org: Option, ou: Option, } @@ -109,7 +110,7 @@ impl OpenSSLInternalProvider { pub(crate) fn from_cfg(cfg: &AppConfig) -> Self { let base_dir = PathBuf::from(&cfg.base_directory); - let keys_dir = base_dir.clone().join(cfg.keys_subdir.clone()); + let keys_dir = base_dir.clone(); let name = cfg.name.clone(); let ca_file = keys_dir.join(cfg.ca_filename.clone()); @@ -135,6 +136,7 @@ impl OpenSSLInternalProvider { ip: cfg.ip.clone(), country: cfg.country.clone(), province: cfg.province.clone(), + location: cfg.loc.clone(), org: cfg.org.clone(), ou: cfg.ou.clone(), } @@ -192,6 +194,9 @@ impl OpenSSLInternalProvider { if let Some(province) = self.province.clone() { name_builder.append_entry_by_text("ST", &province)?; } + if let Some(location) = self.location.clone() { + name_builder.append_entry_by_text("L", &location)?; + } if let Some(org) = self.org.clone() { name_builder.append_entry_by_text("O", &org)?; }