ocsp: update ParseRequest docs & error conditions
ParseRequest was documented as erroring for inputs that contained an optional request signature, and as only supporting requests for a single certificate. However, prior to this commit DER inputs that contained a signature succeeded without verifying the signature, and inputs that contained multiple certificate identifiers succeeded but only the first certificate identifier was unmarshalled. This commit updates the function behaviour to return an error for the signature case as described in the docs, and to clarify the documentation for inputs with multiple certificate identifiers. Fixes golang/go#80300 Change-Id: I7446422d6c98bd406b8c43e55fea9a16ace9d4a6 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/798220 Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Daniel McCarney <daniel@binaryparadox.net> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <nsh@golang.org> Reviewed-by: Nicholas Husin <husin@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
cdce021fa6
commit
243e02a382
+11
-4
@@ -85,7 +85,8 @@ type certID struct {
|
||||
|
||||
// https://tools.ietf.org/html/rfc2560#section-4.1.1
|
||||
type ocspRequest struct {
|
||||
TBSRequest tbsRequest
|
||||
TBSRequest tbsRequest
|
||||
OptionalSignature asn1.RawValue `asn1:"explicit,tag:0,optional"`
|
||||
}
|
||||
|
||||
type tbsRequest struct {
|
||||
@@ -324,7 +325,7 @@ func (req *Request) Marshal() ([]byte, error) {
|
||||
return nil, errors.New("Unknown hash algorithm")
|
||||
}
|
||||
return asn1.Marshal(ocspRequest{
|
||||
tbsRequest{
|
||||
TBSRequest: tbsRequest{
|
||||
Version: 0,
|
||||
RequestList: []request{
|
||||
{
|
||||
@@ -418,8 +419,10 @@ func (p ParseError) Error() string {
|
||||
}
|
||||
|
||||
// ParseRequest parses an OCSP request in DER form. It only supports
|
||||
// requests for a single certificate. Signed requests are not supported.
|
||||
// If a request includes a signature, it will result in a ParseError.
|
||||
// requests for a single certificate identifier. If a request includes
|
||||
// multiple certificate identifiers, only the first will be included in
|
||||
// the parsed Request. Signed requests are not supported. If a request
|
||||
// includes a signature, it will result in a ParseError.
|
||||
func ParseRequest(bytes []byte) (*Request, error) {
|
||||
var req ocspRequest
|
||||
rest, err := asn1.Unmarshal(bytes, &req)
|
||||
@@ -430,6 +433,10 @@ func ParseRequest(bytes []byte) (*Request, error) {
|
||||
return nil, ParseError("trailing data in OCSP request")
|
||||
}
|
||||
|
||||
if len(req.OptionalSignature.FullBytes) > 0 {
|
||||
return nil, ParseError("signed OCSP requests are not supported")
|
||||
}
|
||||
|
||||
if len(req.TBSRequest.RequestList) == 0 {
|
||||
return nil, ParseError("OCSP request contains no request body")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user