Skip to content

Commit addf672

Browse files
drfkisom
authored andcommitted
CRL: Add a method for generating a CRL from the local DB
1 parent 584d957 commit addf672

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crl/crl.go

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/cloudflare/cfssl/certdb"
1516
"github.com/cloudflare/cfssl/helpers"
1617
"github.com/cloudflare/cfssl/log"
1718
)
@@ -73,6 +74,27 @@ func NewCRLFromFile(serialList, issuerFile, keyFile []byte, expiryTime string) (
7374
return CreateGenericCRL(revokedCerts, key, issuerCert, newExpiryTime)
7475
}
7576

77+
// NewCRLFromDB takes in a list of CertificateRecords, as well as the issuing certificate
78+
// of the CRL, and the private key. This function is then used to parse the records and generate a CRL
79+
func NewCRLFromDB(certs []certdb.CertificateRecord, issuerCert *x509.Certificate, key crypto.Signer, expiryTime time.Duration) ([]byte, error) {
80+
var revokedCerts []pkix.RevokedCertificate
81+
82+
newExpiryTime := time.Now().Add(expiryTime)
83+
84+
// For every record, create a new revokedCertificate and add it to slice
85+
for _, certRecord := range certs {
86+
serialInt := new(big.Int)
87+
serialInt.SetString(certRecord.Serial, 10)
88+
tempCert := pkix.RevokedCertificate{
89+
SerialNumber: serialInt,
90+
RevocationTime: certRecord.RevokedAt,
91+
}
92+
revokedCerts = append(revokedCerts, tempCert)
93+
}
94+
95+
return CreateGenericCRL(revokedCerts, key, issuerCert, newExpiryTime)
96+
}
97+
7698
// CreateGenericCRL is a helper function that takes in all of the information above, and then calls the createCRL
7799
// function. This outputs the bytes of the created CRL.
78100
func CreateGenericCRL(certList []pkix.RevokedCertificate, key crypto.Signer, issuingCert *x509.Certificate, expiryTime time.Time) ([]byte, error) {

0 commit comments

Comments
 (0)