Skip to content

Commit

Permalink
Verify delegated & CA signed OCSP correctly (#736)
Browse files Browse the repository at this point in the history
Both ParseResponse and ParseResponseForCert in "golang.org/x/crypto/ocsp" do already verify the response and embedded certificates when present. Previous OCSP signature validation in this package was done incorrectly and would only be performed when ParseResponse would have verified the signature with no errors. By using ParseResponseForCert instead of ParseResponse also OCSP responses containing multiple answers can be handled successfully.
  • Loading branch information
vanbroup authored and lziest committed Mar 16, 2017
1 parent f27ab50 commit 418d970
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions revoke/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,13 @@ func certIsRevokedOCSP(leaf *x509.Certificate, strict bool) (revoked, ok bool) {
}

for _, server := range ocspURLs {
resp, err := sendOCSPRequest(server, ocspRequest, issuer)
resp, err := sendOCSPRequest(server, ocspRequest, leaf, issuer)
if err != nil {
if strict {
return
}
continue
}
if err = resp.CheckSignatureFrom(issuer); err != nil {
return false, false
}

// There wasn't an error fetching the OCSP status.
ok = true
Expand All @@ -266,7 +263,7 @@ func certIsRevokedOCSP(leaf *x509.Certificate, strict bool) (revoked, ok bool) {
// sendOCSPRequest attempts to request an OCSP response from the
// server. The error only indicates a failure to *fetch* the
// certificate, and *does not* mean the certificate is valid.
func sendOCSPRequest(server string, req []byte, issuer *x509.Certificate) (*ocsp.Response, error) {
func sendOCSPRequest(server string, req []byte, leaf, issuer *x509.Certificate) (*ocsp.Response, error) {
var resp *http.Response
var err error
if len(req) > 256 {
Expand Down Expand Up @@ -304,5 +301,5 @@ func sendOCSPRequest(server string, req []byte, issuer *x509.Certificate) (*ocsp
return nil, errors.New("OSCP signature required")
}

return ocsp.ParseResponse(body, issuer)
return ocsp.ParseResponseForCert(body, leaf, issuer)
}

0 comments on commit 418d970

Please sign in to comment.