Skip to content

Commit d54542f

Browse files
committed
FAB-6251 Backdate certificates generated by cryptogen
cryptogen currently sets the NotBefore field for certificates to the current time. Fabric CA sets the NotBefore field to current time - 5 minutes. If one attempts to use the CA certs generated by cryptogen with Fabric CA and then tries to enroll with Fabric CA, if you don't wait 5+ min then the certs signed by Fabric CA end up being invalid. This change simply backdates the NotBefore 5 minutes prior to the current time for all generated certs Change-Id: I0f5661216dc6459d19d808ed592046a0de3f3034 Signed-off-by: Gari Singh <[email protected]>
1 parent d30b129 commit d54542f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

common/tools/cryptogen/ca/generator.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,20 @@ func subjectTemplate() pkix.Name {
124124
// default template for X509 certificates
125125
func x509Template() x509.Certificate {
126126

127-
//generate a serial number
127+
// generate a serial number
128128
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
129129
serialNumber, _ := rand.Int(rand.Reader, serialNumberLimit)
130130

131-
now := time.Now()
131+
// set expiry to around 10 years
132+
expiry := 3650 * 24 * time.Hour
133+
// backdate 5 min
134+
notBefore := time.Now().Add(-5 * time.Minute).UTC()
135+
132136
//basic template to use
133137
x509 := x509.Certificate{
134138
SerialNumber: serialNumber,
135-
NotBefore: now,
136-
NotAfter: now.Add(3650 * 24 * time.Hour), //~ten years
139+
NotBefore: notBefore,
140+
NotAfter: notBefore.Add(expiry).UTC(),
137141
BasicConstraintsValid: true,
138142
}
139143
return x509

0 commit comments

Comments
 (0)