@@ -3,6 +3,7 @@ package crl
3
3
import (
4
4
"bytes"
5
5
"crypto/x509"
6
+ "crypto/x509/pkix"
6
7
"encoding/asn1"
7
8
"encoding/hex"
8
9
"encoding/pem"
@@ -258,7 +259,7 @@ func commitCACRLUpdate(stagingDirectory, caBundleFilename string, stagingCRLUpda
258
259
return nil
259
260
}
260
261
261
- var existingCRLs map [string ]* x509. RevocationList
262
+ var existingCRLs map [string ]* pkix. CertificateList
262
263
263
264
// writeCRLFile reads the CA bundle at caBundleFilename, and makes sure all CRLs specified in the CA bundle are written
264
265
// into the crl file at newCRLFilename. If any of the specified CRLs are in existingCRLFilename and have not expired,
@@ -291,9 +292,13 @@ func writeCRLFile(caBundleFilename, existingCRLFilename, newCRLFilename string)
291
292
292
293
buf := & bytes.Buffer {}
293
294
for subjectKeyId , crl := range crls {
295
+ asn1Data , err := asn1 .Marshal (* crl )
296
+ if err != nil {
297
+ return time.Time {}, false , fmt .Errorf ("failed to encode ASN.1 for CRL for certificate key %s: %w" , subjectKeyId , err )
298
+ }
294
299
block := & pem.Block {
295
300
Type : "X509 CRL" ,
296
- Bytes : crl . Raw ,
301
+ Bytes : asn1Data ,
297
302
}
298
303
if err := pem .Encode (buf , block ); err != nil {
299
304
return time.Time {}, false , fmt .Errorf ("failed to encode PEM for CRL for certificate key %s: %w" , subjectKeyId , err )
@@ -319,9 +324,9 @@ func writeCRLFile(caBundleFilename, existingCRLFilename, newCRLFilename string)
319
324
// existingCRLs are no longer required
320
325
//
321
326
// Returns an error if CRL downloading or parsing fails.
322
- func downloadMissingCRLs (existingCRLs map [string ]* x509. RevocationList , clientCAData []byte ) (map [string ]* x509. RevocationList , time.Time , bool , error ) {
327
+ func downloadMissingCRLs (existingCRLs map [string ]* pkix. CertificateList , clientCAData []byte ) (map [string ]* pkix. CertificateList , time.Time , bool , error ) {
323
328
var nextCRLUpdate time.Time
324
- crls := make (map [string ]* x509. RevocationList )
329
+ crls := make (map [string ]* pkix. CertificateList )
325
330
updated := false
326
331
now := time .Now ()
327
332
for len (clientCAData ) > 0 {
@@ -343,12 +348,12 @@ func downloadMissingCRLs(existingCRLs map[string]*x509.RevocationList, clientCAD
343
348
continue
344
349
}
345
350
if crl , ok := existingCRLs [subjectKeyId ]; ok {
346
- if crl .NextUpdate .Before (now ) {
347
- log .Info ("certificate revocation list has expired" , "subject key identifier" , subjectKeyId , "next update" , crl .NextUpdate .Format (time .RFC3339 ))
351
+ if crl .TBSCertList . NextUpdate .Before (now ) {
352
+ log .Info ("certificate revocation list has expired" , "subject key identifier" , subjectKeyId , "next update" , crl .TBSCertList . NextUpdate .Format (time .RFC3339 ))
348
353
} else {
349
354
crls [subjectKeyId ] = existingCRLs [subjectKeyId ]
350
- if nextCRLUpdate .IsZero () || crl .NextUpdate .Before (nextCRLUpdate ) {
351
- nextCRLUpdate = crl .NextUpdate
355
+ if nextCRLUpdate .IsZero () || crl .TBSCertList . NextUpdate .Before (nextCRLUpdate ) {
356
+ nextCRLUpdate = crl .TBSCertList . NextUpdate
352
357
}
353
358
continue
354
359
}
@@ -360,9 +365,9 @@ func downloadMissingCRLs(existingCRLs map[string]*x509.RevocationList, clientCAD
360
365
return nil , time.Time {}, false , fmt .Errorf ("failed to get certificate revocation list for certificate key %s: %w" , subjectKeyId , err )
361
366
} else {
362
367
crls [subjectKeyId ] = crl
363
- log .Info ("new certificate revocation list" , "subject key identifier" , subjectKeyId , "next update" , crl .NextUpdate .Format (time .RFC3339 ))
364
- if nextCRLUpdate .IsZero () || crl .NextUpdate .Before (nextCRLUpdate ) {
365
- nextCRLUpdate = crl .NextUpdate
368
+ log .Info ("new certificate revocation list" , "subject key identifier" , subjectKeyId , "next update" , crl .TBSCertList . NextUpdate .Format (time .RFC3339 ))
369
+ if nextCRLUpdate .IsZero () || crl .TBSCertList . NextUpdate .Before (nextCRLUpdate ) {
370
+ nextCRLUpdate = crl .TBSCertList . NextUpdate
366
371
}
367
372
updated = true
368
373
}
@@ -382,7 +387,7 @@ func downloadMissingCRLs(existingCRLs map[string]*x509.RevocationList, clientCAD
382
387
383
388
// getCRL gets a certificate revocation list using the provided distribution points and returns the certificate list.
384
389
// Returns an error if the CRL could not be downloaded.
385
- func getCRL (distributionPoints []string , now time.Time ) (* x509. RevocationList , error ) {
390
+ func getCRL (distributionPoints []string , now time.Time ) (* pkix. CertificateList , error ) {
386
391
var errs []error
387
392
for _ , distributionPoint := range distributionPoints {
388
393
// The distribution point is typically a URL with the "http" scheme. "https" is generally not used because the
@@ -399,8 +404,8 @@ func getCRL(distributionPoints []string, now time.Time) (*x509.RevocationList, e
399
404
errs = append (errs , fmt .Errorf ("error getting %q: %w" , distributionPoint , err ))
400
405
continue
401
406
}
402
- if crl .NextUpdate .Before (now ) {
403
- log .Info ("CRL expired. trying next distribution point" , "nextUpdate" , crl .NextUpdate .Format (time .RFC3339 ))
407
+ if crl .TBSCertList . NextUpdate .Before (now ) {
408
+ log .Info ("CRL expired. trying next distribution point" , "nextUpdate" , crl .TBSCertList . NextUpdate .Format (time .RFC3339 ))
404
409
errs = append (errs , fmt .Errorf ("retrieved expired CRL from %s" , distributionPoint ))
405
410
continue
406
411
}
@@ -415,7 +420,7 @@ func getCRL(distributionPoints []string, now time.Time) (*x509.RevocationList, e
415
420
416
421
// getHTTPCRL gets a certificate revocation list using the provided HTTP URL. Returns an error if the CRL could not be
417
422
// downloaded, or if parsing the CRL fails.
418
- func getHTTPCRL (url string ) (* x509. RevocationList , error ) {
423
+ func getHTTPCRL (url string ) (* pkix. CertificateList , error ) {
419
424
resp , err := http .Get (url )
420
425
if err != nil {
421
426
return nil , fmt .Errorf ("http.Get failed: %w" , err )
@@ -440,7 +445,7 @@ func getHTTPCRL(url string) (*x509.RevocationList, error) {
440
445
return nil , fmt .Errorf ("error parsing response: file is not CRL type" )
441
446
}
442
447
}
443
- crl , err := x509 .ParseRevocationList (crlBytes )
448
+ crl , err := x509 .ParseCRL (crlBytes )
444
449
if err != nil {
445
450
return nil , fmt .Errorf ("error parsing response: %w" , err )
446
451
}
0 commit comments