Skip to content

Commit

Permalink
Return the proper serial number in OCSP verification errors (#27696)
Browse files Browse the repository at this point in the history
* Return the proper serial number in OCSP verification errors

 - We returned the issuer's certificate number instead of the serial
   number of the actual certificate we validated from an OCSP request.

 - The problematic serial number within the error are never shown
   currently in Vault. The only user of this library is cert-auth
   which swallows errors around revoked certificates and returns
   a boolean false instead of the actual error message.

* Add cl

* Use previously formatted serial in error msg
  • Loading branch information
stevendpclark authored Jul 9, 2024
1 parent a2e78eb commit 054f5b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions builtin/logical/pki/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func TestIntegrationOCSPClientWithPKI(t *testing.T) {

err = ocspClient.VerifyLeafCertificate(context.Background(), cert, issuer, conf)
require.Error(t, err)
require.Contains(t, err.Error(), serialNumber, "Expected revoked serial number to appear in err")
}
}

Expand Down
3 changes: 3 additions & 0 deletions changelog/27696.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
auth/cert: Use subject's serial number, not issuer's within error message text in OCSP request errors
```
4 changes: 2 additions & 2 deletions sdk/helper/ocsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,12 @@ func (c *Client) VerifyLeafCertificate(ctx context.Context, subject, issuer *x50
if results.code == ocspStatusGood {
return nil
} else {
serial := issuer.SerialNumber
serial := subject.SerialNumber
serialHex := strings.TrimSpace(certutil.GetHexFormatted(serial.Bytes(), ":"))
if results.code == ocspStatusRevoked {
return fmt.Errorf("certificate with serial number %s has been revoked", serialHex)
} else if conf.OcspFailureMode == FailOpenFalse {
return fmt.Errorf("unknown OCSP status for cert with serial number %s", strings.TrimSpace(certutil.GetHexFormatted(serial.Bytes(), ":")))
return fmt.Errorf("unknown OCSP status for cert with serial number %s", serialHex)
} else {
c.Logger().Warn("could not validate OCSP status for cert, but continuing in fail open mode", "serial", serialHex)
}
Expand Down

0 comments on commit 054f5b1

Please sign in to comment.