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: 481f613438c91521fd90078cc0915cf01cf44b4e
GitHub-Pull-Request: golang/crypto#122
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220353
Reviewed-by: Katie Hockman <katie@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
This commit is contained in:
Roland Shoemaker
2020-10-01 19:37:50 +00:00
committed by Roland Shoemaker
parent afb6bcd081
commit eb9a90e9f9
+17 -12
View File
@@ -445,10 +445,18 @@ func ParseRequest(bytes []byte) (*Request, error) {
}, nil }, nil
} }
// ParseResponse parses an OCSP response in DER form. It only supports // ParseResponse parses an OCSP response in DER form. The response must contain
// responses for a single certificate. If the response contains a certificate // only one certificate status. To parse the status of a specific certificate
// then the signature over the response is checked. If issuer is not nil then // from a response which may contain multiple statuses, use ParseResponseForCert
// it will be used to validate the signature or embedded certificate. // instead.
//
// If the response contains an embedded certificate, then that certificate will
// be used to verify the response signature. If the response contains an
// embedded certificate and issuer is not nil, then issuer will be used to verify
// the signature on the embedded certificate.
//
// If the response does not contain an embedded certificate and issuer is not
// nil, then issuer will be used to verify the response signature.
// //
// Invalid responses and parse failures will result in a ParseError. // Invalid responses and parse failures will result in a ParseError.
// Error responses will result in a ResponseError. // Error responses will result in a ResponseError.
@@ -456,14 +464,11 @@ func ParseResponse(bytes []byte, issuer *x509.Certificate) (*Response, error) {
return ParseResponseForCert(bytes, nil, issuer) return ParseResponseForCert(bytes, nil, issuer)
} }
// ParseResponseForCert parses an OCSP response in DER form and searches for a // ParseResponseForCert acts identically to ParseResponse, except it supports
// Response relating to cert. If such a Response is found and the OCSP response // parsing responses that contain multiple statuses. If the response contains
// contains a certificate then the signature over the response is checked. If // multiple statuses and cert is not nil, then ParseResponseForCert will return
// issuer is not nil then it will be used to validate the signature or embedded // the first status which contains a matching serial, otherwise it will return an
// certificate. // error. If cert is nil, then the first status in the response will be returned.
//
// Invalid responses and parse failures will result in a ParseError.
// Error responses will result in a ResponseError.
func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Response, error) { func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Response, error) {
var resp responseASN1 var resp responseASN1
rest, err := asn1.Unmarshal(bytes, &resp) rest, err := asn1.Unmarshal(bytes, &resp)