Skip to content

Commit 4c71af7

Browse files
kreichgauerbradfitz
authored andcommitted
crypto/x509: marshal certificate revocation times in UTC (Zulu time).
This is required by RFC 5280. Fixes #16686 Change-Id: I291c68dd97410a4f7ae7c4e524b91a2493ac50a9 Reviewed-on: https://go-review.googlesource.com/34245 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8c190e5 commit 4c71af7

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/crypto/x509/x509.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -1850,13 +1850,20 @@ func (c *Certificate) CreateCRL(rand io.Reader, priv interface{}, revokedCerts [
18501850
return nil, err
18511851
}
18521852

1853+
// Force revocation times to UTC per RFC 5280.
1854+
revokedCertsUTC := make([]pkix.RevokedCertificate, len(revokedCerts))
1855+
for i, rc := range revokedCerts {
1856+
rc.RevocationTime = rc.RevocationTime.UTC()
1857+
revokedCertsUTC[i] = rc
1858+
}
1859+
18531860
tbsCertList := pkix.TBSCertificateList{
18541861
Version: 1,
18551862
Signature: signatureAlgorithm,
18561863
Issuer: c.Subject.ToRDNSequence(),
18571864
ThisUpdate: now.UTC(),
18581865
NextUpdate: expiry.UTC(),
1859-
RevokedCertificates: revokedCerts,
1866+
RevokedCertificates: revokedCertsUTC,
18601867
}
18611868

18621869
// Authority Key Id

src/crypto/x509/x509_test.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,31 @@ func TestCRLCreation(t *testing.T) {
850850
block, _ = pem.Decode([]byte(pemCertificate))
851851
cert, _ := ParseCertificate(block.Bytes)
852852

853-
now := time.Unix(1000, 0)
853+
loc := time.FixedZone("Oz/Atlantis", int((2 * time.Hour).Seconds()))
854+
855+
now := time.Unix(1000, 0).In(loc)
856+
nowUTC := now.UTC()
854857
expiry := time.Unix(10000, 0)
855858

856859
revokedCerts := []pkix.RevokedCertificate{
857860
{
858861
SerialNumber: big.NewInt(1),
862+
RevocationTime: nowUTC,
863+
},
864+
{
865+
SerialNumber: big.NewInt(42),
866+
// RevocationTime should be converted to UTC before marshaling.
859867
RevocationTime: now,
860868
},
869+
}
870+
expectedCerts := []pkix.RevokedCertificate{
871+
{
872+
SerialNumber: big.NewInt(1),
873+
RevocationTime: nowUTC,
874+
},
861875
{
862876
SerialNumber: big.NewInt(42),
863-
RevocationTime: now,
877+
RevocationTime: nowUTC,
864878
},
865879
}
866880

@@ -869,10 +883,14 @@ func TestCRLCreation(t *testing.T) {
869883
t.Errorf("error creating CRL: %s", err)
870884
}
871885

872-
_, err = ParseDERCRL(crlBytes)
886+
parsedCRL, err := ParseDERCRL(crlBytes)
873887
if err != nil {
874888
t.Errorf("error reparsing CRL: %s", err)
875889
}
890+
if !reflect.DeepEqual(parsedCRL.TBSCertList.RevokedCertificates, expectedCerts) {
891+
t.Errorf("RevokedCertificates mismatch: got %v; want %v.",
892+
parsedCRL.TBSCertList.RevokedCertificates, expectedCerts)
893+
}
876894
}
877895

878896
func fromBase64(in string) []byte {

0 commit comments

Comments
 (0)