Skip to content

Commit

Permalink
Make 1-hour validity period configurable via cflag
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Aug 25, 2021
1 parent 5dea8e0 commit 06cc20d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
36 changes: 36 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 Jeremy Rand.

// This file is part of safetlsa.
//
// safetlsa is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// safetlsa is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with safetlsa. If not, see
// <https://www.gnu.org/licenses/>.

package safetlsa

import (
"time"

"gopkg.in/hlandau/easyconfig.v1/cflag"
)

var (
flagGroup = cflag.NewGroup(nil, "safetlsa")
validityFlag = cflag.Int(flagGroup, "validity-short-term-seconds", 1*60*60,
"Use the time of signing +/- this duration as the validity period "+
"for short-term certificates.")
)

func ValidityShortTerm() time.Duration {
return validityFlag.Value() * time.Second
}
4 changes: 2 additions & 2 deletions generate_domain_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func GenerateDomainCA(domain string, publicKeyBytes []byte, parentDERBytes []byt
CommonName: domain + " Domain AIA Parent CA",
SerialNumber: "Namecoin TLS Certificate",
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotAfter: time.Now().Add(1 * time.Hour),
NotBefore: time.Now().Add(-1 * ValidityShortTerm()),
NotAfter: time.Now().Add(1 * ValidityShortTerm()),

IsCA: true,
//KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
Expand Down
2 changes: 1 addition & 1 deletion generate_root_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func GenerateRootCA(commonNamePrefix string) ([]byte, interface{}, error) {
CommonName: commonNamePrefix + " Root CA",
SerialNumber: "Namecoin TLS Certificate",
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotBefore: time.Now().Add(-1 * ValidityShortTerm()),
NotAfter: time.Now().Add(43800 * time.Hour),

IsCA: true,
Expand Down
2 changes: 1 addition & 1 deletion generate_tld_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func GenerateTLDCA(domain string, parentDERBytes []byte, parentPrivateKey interf
CommonName: "." + domain + " TLD CA",
SerialNumber: "Namecoin TLS Certificate",
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotBefore: time.Now().Add(-1 * ValidityShortTerm()),
NotAfter: time.Now().Add(43800 * time.Hour),

IsCA: true,
Expand Down
2 changes: 1 addition & 1 deletion generate_tld_exclusion_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func GenerateTLDExclusionCA(domain string, parentDERBytes []byte, parentPrivateK
CommonName: "." + domain + " TLD Exclusion CA",
SerialNumber: "Namecoin TLS Certificate",
},
NotBefore: time.Now().Add(-1 * time.Hour),
NotBefore: time.Now().Add(-1 * ValidityShortTerm()),
NotAfter: time.Now().Add(43800 * time.Hour),

IsCA: true,
Expand Down

0 comments on commit 06cc20d

Please sign in to comment.