Skip to content

Commit

Permalink
Merge pull request #8 from jgarzik/args
Browse files Browse the repository at this point in the history
Args and new Version
  • Loading branch information
jgarzik authored Feb 20, 2024
2 parents bccc978 + 41fa370 commit accb5cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "self-signed-cert"
version = "1.0.0"
version = "1.0.1"
authors = ["Jeff Garzik"]
edition = "2021"
description = "Tool to generate self-signed root CA, web server certs and keys"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Options:
Server cert: city or locality
--srv-org <SRV_ORG>
Server cert: organization
--srv-expire-days <SRV_EXPIRE_DAYS>
--srv-expire <SRV_EXPIRE>
Server cert: days until expiration [default: 365]
--ca-common-name <CA_COMMON_NAME>
Expand All @@ -63,7 +63,7 @@ Options:
CA cert: city or locality
--ca-org <CA_ORG>
CA cert: organization
--ca-expire-days <CA_EXPIRE_DAYS>
--ca-expire <CA_EXPIRE>
CA cert: days until expiration [default: 365]
--common-name <COMMON_NAME>
Expand All @@ -76,7 +76,7 @@ Options:
city or locality: Default set for both CA and server certs
--org <ORG>
organization: Default set for both CA and server certs
--expire-days <EXPIRE_DAYS>
--expire <EXPIRE>
expire days: Default set for both CA and server certs
-h, --help
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct Args {

/// Server cert: days until expiration
#[arg(long, default_value_t = 365)]
srv_expire_days: u32,
srv_expire: u32,

/// CA cert: common name
#[arg(long, default_value = "127.0.0.1")]
Expand All @@ -99,7 +99,7 @@ struct Args {

/// CA cert: days until expiration
#[arg(long, default_value_t = 365)]
ca_expire_days: u32,
ca_expire: u32,

/// common name: Default set for both CA and server certs.
#[arg(long)]
Expand All @@ -123,7 +123,7 @@ struct Args {

/// expire days: Default set for both CA and server certs.
#[arg(long)]
expire_days: Option<u32>,
expire: Option<u32>,
}

/// Process CLI args that assign two settings simultaneously
Expand Down Expand Up @@ -163,10 +163,10 @@ fn swizzle_args(args: &mut Args) {
}
None => {}
}
match &args.expire_days {
match &args.expire {
Some(val) => {
args.ca_expire_days = *val;
args.srv_expire_days = *val;
args.ca_expire = *val;
args.srv_expire = *val;
}
None => {}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ fn create_root_ca_certificate(args: &Args, pkey: &PKey<Private>) -> Result<X509,
builder.set_pubkey(pkey)?;

let not_before = Asn1Time::days_from_now(0)?;
let not_after = Asn1Time::days_from_now(args.ca_expire_days)?;
let not_after = Asn1Time::days_from_now(args.ca_expire)?;
builder.set_not_before(&not_before)?;
builder.set_not_after(&not_after)?;

Expand Down Expand Up @@ -303,7 +303,7 @@ fn sign_server_csr(

// Set validity
let not_before = openssl::asn1::Asn1Time::days_from_now(0)?;
let not_after = openssl::asn1::Asn1Time::days_from_now(args.srv_expire_days)?;
let not_after = openssl::asn1::Asn1Time::days_from_now(args.srv_expire)?;
builder.set_not_before(&not_before)?;
builder.set_not_after(&not_after)?;

Expand Down

0 comments on commit accb5cc

Please sign in to comment.