Skip to content

Commit 8d1ea72

Browse files
Address review comments
OCSP-Responder attempts to read the OCSP response from the certificateStatus table, if it cannot find a response there it reads the ocspResponses table to try to find a response, if neither contains a response the not found bool is passed back to the Responder.
1 parent 10b6bb5 commit 8d1ea72

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

cmd/ocsp-responder/main.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package main
88
import (
99
"bytes"
1010
"crypto/x509"
11+
"database/sql"
1112
"encoding/hex"
1213
"errors"
1314
"fmt"
@@ -80,20 +81,33 @@ func (src *DBSource) Response(req *ocsp.Request) ([]byte, bool) {
8081
log.Debug(fmt.Sprintf("Searching for OCSP issued by us for serial %s", serialString))
8182

8283
var response []byte
84+
defer func() {
85+
if len(response) != 0 {
86+
log.Info(fmt.Sprintf("OCSP Response sent for CA=%s, Serial=%s", hex.EncodeToString(src.caKeyHash), serialString))
87+
}
88+
}()
8389
// Note: we order by id rather than createdAt, because otherwise we sometimes
8490
// get the wrong result if a certificate is revoked in the same second as its
8591
// last update (e.g. client issues and instant revokes).
8692
err := src.dbMap.SelectOne(
8793
&response,
88-
"SELECT ocspResponse from certificateStatus WHERE serial = :serial",
94+
"SELECT ocspResponse FROM certificateStatus WHERE serial = :serial",
8995
map[string]interface{}{"serial": serialString},
9096
)
9197
if err != nil || len(response) == 0 {
98+
if err == sql.ErrNoRows || len(response) == 0 {
99+
err := src.dbMap.SelectOne(
100+
&response,
101+
"SELECT response from ocspResponses WHERE serial = :serial ORDER BY id DESC LIMIT 1;",
102+
map[string]interface{}{"serial": serialString},
103+
)
104+
if err == nil && len(response) != 0 {
105+
return response, true
106+
}
107+
}
92108
return nil, false
93109
}
94110

95-
log.Info(fmt.Sprintf("OCSP Response sent for CA=%s, Serial=%s", hex.EncodeToString(src.caKeyHash), serialString))
96-
97111
return response, true
98112
}
99113

cmd/ocsp-updater/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (updater *OCSPUpdater) findRevokedCertificates(batchSize int) ([]core.Certi
230230
&statuses,
231231
`SELECT * FROM certificateStatus
232232
WHERE status = :revoked
233-
AND ocspLastUpdated < revokedDate
233+
AND ocspLastUpdated <= revokedDate
234234
LIMIT :limit`,
235235
map[string]interface{}{
236236
"revoked": string(core.OCSPStatusRevoked),

sa/_db/migrations/20151008132352_MoveOCSPResponseToCertificateStatus.sql

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,8 @@
33
-- SQL in section 'Up' is executed when this migration is applied
44

55
ALTER TABLE `certificateStatus` ADD COLUMN (`ocspResponse` blob);
6-
UPDATE certificateStatus,ocspResponses SET certificateStatus.ocspResponse = ocspResponses.Response;
7-
DROP TABLE `ocspResponses`;
86

97
-- +goose Down
108
-- SQL section 'Down' is executed when this migration is rolled back
119

12-
CREATE TABLE `ocspResponses` (
13-
`id` int(11) NOT NULL AUTO_INCREMENT,
14-
`serial` varchar(255) NOT NULL,
15-
`createdAt` datetime NOT NULL,
16-
`response` blob NOT NULL,
17-
PRIMARY KEY (`id`),
18-
KEY `SERIAL` (`serial`) COMMENT 'Actual lookup mechanism'
19-
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20-
UPDATE certificateStatus,ocspResponses
21-
SET ocspResponses.ocspResponse = certificateStatus.Response
22-
AND ocspResponses.createdAt = certificateStatus.ocspLastUpdated;
2310
ALTER TABLE `certificateStatus` DROP COLUMN `ocspResponse`;

0 commit comments

Comments
 (0)