Skip to content

Commit d554f0a

Browse files
committed
Delete sa.GetRevokedCerts
1 parent fc6dd8f commit d554f0a

File tree

4 files changed

+4
-175
lines changed

4 files changed

+4
-175
lines changed

docs/CRLS.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ contains an entry for every certificate, explicitly recording that newly-issued
3939
certificates are not revoked. The latter is less explicit but more scalable,
4040
containing rows only for certificates which have been revoked.
4141

42-
The SA exposes the two different types of recordkeeping in two different ways:
43-
`GetRevokedCerts` returns revoked certificates whose NotAfter dates fall within
44-
a requested range. `GetRevokedCertsByShard` returns revoked certificates whose
45-
`shardIdx` matches the requested shard. The crl-updater uses only the latter
46-
method, and the former will be removed in the future.
42+
The SA only exposes the latter of these two mechanisms via the
43+
`GetRevokedCertsByShard` method, which returns revoked certificates whose
44+
`shardIdx` matches the requested shard. The `certificateStatus` table will be
45+
removed in the near future.

mocks/sa.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,6 @@ func (sa *StorageAuthority) GetPausedIdentifiers(_ context.Context, _ *sapb.Regi
252252
return nil, nil
253253
}
254254

255-
// GetRevokedCerts is a mock
256-
func (sa *StorageAuthorityReadOnly) GetRevokedCerts(ctx context.Context, _ *sapb.GetRevokedCertsRequest, _ ...grpc.CallOption) (sapb.StorageAuthorityReadOnly_GetRevokedCertsClient, error) {
257-
return &ServerStreamClient[corepb.CRLEntry]{}, nil
258-
}
259-
260-
// GetRevokedCerts is a mock
261-
func (sa *StorageAuthority) GetRevokedCerts(ctx context.Context, _ *sapb.GetRevokedCertsRequest, _ ...grpc.CallOption) (sapb.StorageAuthority_GetRevokedCertsClient, error) {
262-
return &ServerStreamClient[corepb.CRLEntry]{}, nil
263-
}
264-
265255
// GetRevokedCertsByShard is a mock
266256
func (sa *StorageAuthorityReadOnly) GetRevokedCertsByShard(ctx context.Context, _ *sapb.GetRevokedCertsByShardRequest, _ ...grpc.CallOption) (grpc.ServerStreamingClient[corepb.CRLEntry], error) {
267257
return &ServerStreamClient[corepb.CRLEntry]{}, nil

sa/sa_test.go

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,113 +2974,6 @@ func TestSerialsForIncident(t *testing.T) {
29742974
test.AssertNotError(t, err, "Error getting serials for incident")
29752975
}
29762976

2977-
func TestGetRevokedCerts(t *testing.T) {
2978-
sa, _, cleanUp := initSA(t)
2979-
defer cleanUp()
2980-
2981-
// Add a cert to the DB to test with. We use AddPrecertificate because it sets
2982-
// up the certificateStatus row we need. This particular cert has a notAfter
2983-
// date of Mar 6 2023, and we lie about its IssuerNameID to make things easy.
2984-
reg := createWorkingRegistration(t, sa)
2985-
eeCert, err := core.LoadCert("../test/hierarchy/ee-e1.cert.pem")
2986-
test.AssertNotError(t, err, "failed to load test cert")
2987-
_, err = sa.AddSerial(ctx, &sapb.AddSerialRequest{
2988-
RegID: reg.Id,
2989-
Serial: core.SerialToString(eeCert.SerialNumber),
2990-
Created: timestamppb.New(eeCert.NotBefore),
2991-
Expires: timestamppb.New(eeCert.NotAfter),
2992-
})
2993-
test.AssertNotError(t, err, "failed to add test serial")
2994-
_, err = sa.AddPrecertificate(ctx, &sapb.AddCertificateRequest{
2995-
Der: eeCert.Raw,
2996-
RegID: reg.Id,
2997-
Issued: timestamppb.New(eeCert.NotBefore),
2998-
IssuerNameID: 1,
2999-
})
3000-
test.AssertNotError(t, err, "failed to add test cert")
3001-
3002-
// Check that it worked.
3003-
status, err := sa.GetCertificateStatus(
3004-
ctx, &sapb.Serial{Serial: core.SerialToString(eeCert.SerialNumber)})
3005-
test.AssertNotError(t, err, "GetCertificateStatus failed")
3006-
test.AssertEquals(t, core.OCSPStatus(status.Status), core.OCSPStatusGood)
3007-
3008-
// Here's a little helper func we'll use to call GetRevokedCerts and count
3009-
// how many results it returned.
3010-
countRevokedCerts := func(req *sapb.GetRevokedCertsRequest) (int, error) {
3011-
stream := make(chan *corepb.CRLEntry)
3012-
mockServerStream := &fakeServerStream[corepb.CRLEntry]{output: stream}
3013-
var err error
3014-
go func() {
3015-
err = sa.GetRevokedCerts(req, mockServerStream)
3016-
close(stream)
3017-
}()
3018-
entriesReceived := 0
3019-
for range stream {
3020-
entriesReceived++
3021-
}
3022-
return entriesReceived, err
3023-
}
3024-
3025-
// The basic request covers a time range that should include this certificate.
3026-
basicRequest := &sapb.GetRevokedCertsRequest{
3027-
IssuerNameID: 1,
3028-
ExpiresAfter: mustTimestamp("2023-03-01 00:00"),
3029-
ExpiresBefore: mustTimestamp("2023-04-01 00:00"),
3030-
RevokedBefore: mustTimestamp("2023-04-01 00:00"),
3031-
}
3032-
count, err := countRevokedCerts(basicRequest)
3033-
test.AssertNotError(t, err, "zero rows shouldn't result in error")
3034-
test.AssertEquals(t, count, 0)
3035-
3036-
// Revoke the certificate.
3037-
_, err = sa.RevokeCertificate(context.Background(), &sapb.RevokeCertificateRequest{
3038-
IssuerID: 1,
3039-
Serial: core.SerialToString(eeCert.SerialNumber),
3040-
Date: mustTimestamp("2023-01-01 00:00"),
3041-
Reason: 1,
3042-
Response: []byte{1, 2, 3},
3043-
ShardIdx: 1,
3044-
})
3045-
test.AssertNotError(t, err, "failed to revoke test cert")
3046-
3047-
// Asking for revoked certs now should return one result.
3048-
count, err = countRevokedCerts(basicRequest)
3049-
test.AssertNotError(t, err, "normal usage shouldn't result in error")
3050-
test.AssertEquals(t, count, 1)
3051-
3052-
// Asking for revoked certs with an old RevokedBefore should return no results.
3053-
count, err = countRevokedCerts(&sapb.GetRevokedCertsRequest{
3054-
IssuerNameID: 1,
3055-
ExpiresAfter: basicRequest.ExpiresAfter,
3056-
ExpiresBefore: basicRequest.ExpiresBefore,
3057-
RevokedBefore: mustTimestamp("2020-03-01 00:00"),
3058-
})
3059-
test.AssertNotError(t, err, "zero rows shouldn't result in error")
3060-
test.AssertEquals(t, count, 0)
3061-
3062-
// Asking for revoked certs in a time period that does not cover this cert's
3063-
// notAfter timestamp should return zero results.
3064-
count, err = countRevokedCerts(&sapb.GetRevokedCertsRequest{
3065-
IssuerNameID: 1,
3066-
ExpiresAfter: mustTimestamp("2022-03-01 00:00"),
3067-
ExpiresBefore: mustTimestamp("2022-04-01 00:00"),
3068-
RevokedBefore: mustTimestamp("2023-04-01 00:00"),
3069-
})
3070-
test.AssertNotError(t, err, "zero rows shouldn't result in error")
3071-
test.AssertEquals(t, count, 0)
3072-
3073-
// Asking for revoked certs from a different issuer should return zero results.
3074-
count, err = countRevokedCerts(&sapb.GetRevokedCertsRequest{
3075-
IssuerNameID: 5678,
3076-
ExpiresAfter: basicRequest.ExpiresAfter,
3077-
ExpiresBefore: basicRequest.ExpiresBefore,
3078-
RevokedBefore: basicRequest.RevokedBefore,
3079-
})
3080-
test.AssertNotError(t, err, "zero rows shouldn't result in error")
3081-
test.AssertEquals(t, count, 0)
3082-
}
3083-
30842977
func TestGetRevokedCertsByShard(t *testing.T) {
30852978
sa, _, cleanUp := initSA(t)
30862979
defer cleanUp()

sa/saro.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -972,59 +972,6 @@ func (ssa *SQLStorageAuthorityRO) GetRevokedCertsByShard(req *sapb.GetRevokedCer
972972
})
973973
}
974974

975-
// GetRevokedCerts returns revoked certificates based on temporal sharding.
976-
//
977-
// Based on a request specifying an issuer and a period of time,
978-
// it writes to the output stream the set of all certificates issued by that
979-
// issuer which expire during that period of time and which have been revoked.
980-
// The starting timestamp is treated as inclusive (certs with exactly that
981-
// notAfter date are included), but the ending timestamp is exclusive (certs
982-
// with exactly that notAfter date are *not* included).
983-
func (ssa *SQLStorageAuthorityRO) GetRevokedCerts(req *sapb.GetRevokedCertsRequest, stream grpc.ServerStreamingServer[corepb.CRLEntry]) error {
984-
if core.IsAnyNilOrZero(req.IssuerNameID, req.RevokedBefore, req.ExpiresAfter, req.ExpiresBefore) {
985-
return errIncompleteRequest
986-
}
987-
atTime := req.RevokedBefore.AsTime()
988-
989-
clauses := `
990-
WHERE notAfter >= ?
991-
AND notAfter < ?
992-
AND issuerID = ?
993-
AND status = ?`
994-
params := []any{
995-
req.ExpiresAfter.AsTime(),
996-
req.ExpiresBefore.AsTime(),
997-
req.IssuerNameID,
998-
core.OCSPStatusRevoked,
999-
}
1000-
1001-
selector, err := db.NewMappedSelector[crlEntryModel](ssa.dbReadOnlyMap)
1002-
if err != nil {
1003-
return fmt.Errorf("initializing db map: %w", err)
1004-
}
1005-
1006-
rows, err := selector.QueryContext(stream.Context(), clauses, params...)
1007-
if err != nil {
1008-
return fmt.Errorf("reading db: %w", err)
1009-
}
1010-
1011-
return rows.ForEach(func(row *crlEntryModel) error {
1012-
// Double-check that the cert wasn't revoked between the time at which we're
1013-
// constructing this snapshot CRL and right now. If the cert was revoked
1014-
// at-or-after the "atTime", we'll just include it in the next generation
1015-
// of CRLs.
1016-
if row.RevokedDate.After(atTime) || row.RevokedDate.Equal(atTime) {
1017-
return nil
1018-
}
1019-
1020-
return stream.Send(&corepb.CRLEntry{
1021-
Serial: row.Serial,
1022-
Reason: int32(row.RevokedReason), //nolint: gosec // Revocation reasons are guaranteed to be small, no risk of overflow.
1023-
RevokedAt: timestamppb.New(row.RevokedDate),
1024-
})
1025-
})
1026-
}
1027-
1028975
// Health implements the grpc.checker interface.
1029976
func (ssa *SQLStorageAuthorityRO) Health(ctx context.Context) error {
1030977
err := ssa.dbReadOnlyMap.SelectOne(ctx, new(int), "SELECT 1")

0 commit comments

Comments
 (0)