Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -days flag to specify the validity period. #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m *mkcert) makeCert(hosts []string) {
// Certificates last for 2 years and 3 months, which is always less than
// 825 days, the limit that macOS/iOS apply to all certificates,
// including custom roots. See https://support.apple.com/en-us/HT210176.
expiration := time.Now().AddDate(2, 3, 0)
expiration := time.Now().AddDate(0, 0, m.days)

tpl := &x509.Certificate{
SerialNumber: randomSerialNumber(),
Expand Down Expand Up @@ -225,7 +225,7 @@ func (m *mkcert) makeCertFromCSR() {
fatalIfErr(err, "failed to parse the CSR")
fatalIfErr(csr.CheckSignature(), "invalid CSR signature")

expiration := time.Now().AddDate(2, 3, 0)
expiration := time.Now().AddDate(0, 0, m.days)
tpl := &x509.Certificate{
SerialNumber: randomSerialNumber(),
Subject: csr.Subject,
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const advancedUsage = `Advanced options:
-CAROOT
Print the CA certificate and key storage location.

-days INT
Generate a certificate valid for the specified number of days.
The default is 810, which is just under the macOS/iOS limit of 825.

$CAROOT (environment variable)
Set the CA certificate and key storage location. (This allows
maintaining multiple local CAs in parallel.)
Expand Down Expand Up @@ -103,6 +107,7 @@ func main() {
keyFileFlag = flag.String("key-file", "", "")
p12FileFlag = flag.String("p12-file", "", "")
versionFlag = flag.Bool("version", false, "")
daysFlag = flag.Int("days", 810, "")
)
flag.Usage = func() {
fmt.Fprint(flag.CommandLine.Output(), shortUsage)
Expand Down Expand Up @@ -146,6 +151,7 @@ func main() {
installMode: *installFlag, uninstallMode: *uninstallFlag, csrPath: *csrFlag,
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, client: *clientFlag,
certFile: *certFileFlag, keyFile: *keyFileFlag, p12File: *p12FileFlag,
days: *daysFlag,
}).Run(flag.Args())
}

Expand All @@ -157,6 +163,7 @@ type mkcert struct {
pkcs12, ecdsa, client bool
keyFile, certFile, p12File string
csrPath string
days int

CAROOT string
caCert *x509.Certificate
Expand Down