Skip to content

Commit eb9a90e

Browse files
ocsp: Improve documentation for ParseResponse and ParseResponseForCert
This change clarifies the behaviors of ParseResponse and ParseResponseForCert, particularly when parsing responses that contain multiple certificate statuses. Fixes golang/go#30651 Change-Id: Ia632c8c2a69d1b0c17d71f9f9dcb59ddb0be401b GitHub-Last-Rev: 481f613 GitHub-Pull-Request: #122 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220353 Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
1 parent afb6bcd commit eb9a90e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

ocsp/ocsp.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,30 @@ func ParseRequest(bytes []byte) (*Request, error) {
445445
}, nil
446446
}
447447

448-
// ParseResponse parses an OCSP response in DER form. It only supports
449-
// responses for a single certificate. If the response contains a certificate
450-
// then the signature over the response is checked. If issuer is not nil then
451-
// it will be used to validate the signature or embedded certificate.
448+
// ParseResponse parses an OCSP response in DER form. The response must contain
449+
// only one certificate status. To parse the status of a specific certificate
450+
// from a response which may contain multiple statuses, use ParseResponseForCert
451+
// instead.
452+
//
453+
// If the response contains an embedded certificate, then that certificate will
454+
// be used to verify the response signature. If the response contains an
455+
// embedded certificate and issuer is not nil, then issuer will be used to verify
456+
// the signature on the embedded certificate.
457+
//
458+
// If the response does not contain an embedded certificate and issuer is not
459+
// nil, then issuer will be used to verify the response signature.
452460
//
453461
// Invalid responses and parse failures will result in a ParseError.
454462
// Error responses will result in a ResponseError.
455463
func ParseResponse(bytes []byte, issuer *x509.Certificate) (*Response, error) {
456464
return ParseResponseForCert(bytes, nil, issuer)
457465
}
458466

459-
// ParseResponseForCert parses an OCSP response in DER form and searches for a
460-
// Response relating to cert. If such a Response is found and the OCSP response
461-
// contains a certificate then the signature over the response is checked. If
462-
// issuer is not nil then it will be used to validate the signature or embedded
463-
// certificate.
464-
//
465-
// Invalid responses and parse failures will result in a ParseError.
466-
// Error responses will result in a ResponseError.
467+
// ParseResponseForCert acts identically to ParseResponse, except it supports
468+
// parsing responses that contain multiple statuses. If the response contains
469+
// multiple statuses and cert is not nil, then ParseResponseForCert will return
470+
// the first status which contains a matching serial, otherwise it will return an
471+
// error. If cert is nil, then the first status in the response will be returned.
467472
func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Response, error) {
468473
var resp responseASN1
469474
rest, err := asn1.Unmarshal(bytes, &resp)

0 commit comments

Comments
 (0)