Skip to content

Commit 19c09ff

Browse files
author
Bowon Yang
committed
pick columns to get revoked/unexpired certs
1 parent 1f29b04 commit 19c09ff

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

certdb/certdb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Accessor interface {
7777
GetUnexpiredCertificates() ([]CertificateRecord, error)
7878
GetRevokedAndUnexpiredCertificates() ([]CertificateRecord, error)
7979
GetRevokedAndUnexpiredCertificatesByLabel(label string) ([]CertificateRecord, error)
80+
GetRevokedAndUnexpiredCertificatesByLabelSelectColumns(label string) ([]CertificateRecord, error)
8081
RevokeCertificate(serial, aki string, reasonCode int) error
8182
InsertOCSP(rr OCSPRecord) error
8283
GetOCSP(serial, aki string) ([]OCSPRecord, error)

certdb/sql/database_accessor.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ SELECT %s FROM certificates
3636
SELECT %s FROM certificates
3737
WHERE CURRENT_TIMESTAMP < expiry AND status='revoked' AND ca_label= ?;`
3838

39+
selectRevokedAndUnexpiredWithLabelSQL = `
40+
SELECT serial_number, revoked_at FROM certificates
41+
WHERE CURRENT_TIMESTAMP < expiry AND status='revoked' AND ca_label= ?;`
42+
3943
selectAllRevokedAndUnexpiredSQL = `
4044
SELECT %s FROM certificates
4145
WHERE CURRENT_TIMESTAMP < expiry AND status='revoked';`
@@ -202,6 +206,21 @@ func (d *Accessor) GetRevokedAndUnexpiredCertificatesByLabel(label string) (crs
202206
return crs, nil
203207
}
204208

209+
// GetRevokedAndUnexpiredCertificatesSelectColumnsByLabel gets serial_number and revoed_at from all revoked and unexpired certificate from db (for CRLs) with specified ca_label.
210+
func (d *Accessor) GetRevokedAndUnexpiredCertificatesByLabelSelectColumns(label string) (crs []certdb.CertificateRecord, err error) {
211+
err = d.checkDB()
212+
if err != nil {
213+
return nil, err
214+
}
215+
216+
err = d.db.Select(&crs, d.db.Rebind(selectRevokedAndUnexpiredWithLabelSQL), label)
217+
if err != nil {
218+
return nil, wrapSQLError(err)
219+
}
220+
221+
return crs, nil
222+
}
223+
205224
// RevokeCertificate updates a certificate with a given serial number and marks it revoked.
206225
func (d *Accessor) RevokeCertificate(serial, aki string, reasonCode int) error {
207226
err := d.checkDB()

certdb/sql/sql_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ func testUpdateCertificateAndGetCertificate(ta TestAccessor, t *testing.T) {
280280
want.PEM != got.PEM {
281281
t.Errorf("want Certificate %+v, got %+v", want, got)
282282
}
283+
284+
rets, err = ta.Accessor.GetRevokedAndUnexpiredCertificatesByLabelSelectColumns("")
285+
if err != nil {
286+
t.Fatal(err)
287+
}
288+
289+
got = rets[0]
290+
// reflection comparison with zero time objects are not stable as it seems
291+
if want.Serial != got.Serial || got.RevokedAt.IsZero() {
292+
t.Errorf("want Certificate %+v, got %+v", want, got)
293+
}
283294
}
284295

285296
func testInsertOCSPAndGetOCSP(ta TestAccessor, t *testing.T) {

0 commit comments

Comments
 (0)