Skip to content

Commit

Permalink
add days option
Browse files Browse the repository at this point in the history
  • Loading branch information
juunini committed Dec 26, 2024
1 parent 1c1dc4e commit 3e7f56e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
}
}

func (m *mkcert) makeCert(hosts []string) {
func (m *mkcert) makeCert(hosts []string, days int) {
if m.caKey == nil {
log.Fatalln("ERROR: can't create new certificates because the CA key (rootCA-key.pem) is missing")
}
Expand All @@ -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, days)

tpl := &x509.Certificate{
SerialNumber: randomSerialNumber(),
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const advancedUsage = `Advanced options:
-client
Generate a certificate for client authentication.
-days DAYS
Set the duration that the certificate is valid for. (default: 820 days)
-ecdsa
Generate a certificate with an ECDSA key.
Expand Down Expand Up @@ -102,6 +105,7 @@ func main() {
certFileFlag = flag.String("cert-file", "", "")
keyFileFlag = flag.String("key-file", "", "")
p12FileFlag = flag.String("p12-file", "", "")
daysFlag = flag.Int("days", 820, "")
versionFlag = flag.Bool("version", false, "")
)
flag.Usage = func() {
Expand Down Expand Up @@ -146,7 +150,7 @@ func main() {
installMode: *installFlag, uninstallMode: *uninstallFlag, csrPath: *csrFlag,
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, client: *clientFlag,
certFile: *certFileFlag, keyFile: *keyFileFlag, p12File: *p12FileFlag,
}).Run(flag.Args())
}).Run(flag.Args(), *daysFlag)
}

const rootName = "rootCA.pem"
Expand All @@ -168,7 +172,7 @@ type mkcert struct {
ignoreCheckFailure bool
}

func (m *mkcert) Run(args []string) {
func (m *mkcert) Run(args []string, days int) {
m.CAROOT = getCAROOT()
if m.CAROOT == "" {
log.Fatalln("ERROR: failed to find the default CA location, set one as the CAROOT env var")
Expand Down Expand Up @@ -234,7 +238,7 @@ func (m *mkcert) Run(args []string) {
}
}

m.makeCert(args)
m.makeCert(args, days)
}

func getCAROOT() string {
Expand Down

0 comments on commit 3e7f56e

Please sign in to comment.