Skip to content

Commit

Permalink
PKI Valdiator always fails on unknown CAs
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Nov 1, 2024
1 parent 8d74a2a commit 3877cde
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pki/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (v *validator) Validate(chain []*x509.Certificate) error {
// check in reverse order to prevent CRL expiration errors due to revoked CAs no longer issuing CRLs
if err = v.validateCert(cert); err != nil {
errOut := fmt.Errorf("%w: subject=%s, S/N=%s, issuer=%s", err, cert.Subject.String(), cert.SerialNumber.String(), cert.Issuer.String())
if v.softfail && !(errors.Is(err, ErrCertRevoked) || errors.Is(err, ErrCertBanned)) {
// Accept the certificate even if it cannot be properly validated
if v.softfail && (errors.Is(err, ErrCRLExpired) || errors.Is(err, ErrCRLMissing) || errors.Is(err, ErrDenylistMissing)) {
// Accept the certificate even if it cannot be properly validated against the CRL or denylist
logger().WithError(errOut).Error("Certificate CRL check softfail bypass. Might be unsafe, find cause of failure!")
continue
}
Expand Down Expand Up @@ -169,6 +169,7 @@ func (v *validator) validateCert(cert *x509.Certificate) error {
// Validate the cert against the denylist
if err := v.denylist.ValidateCert(cert); err != nil {
// Return any denylist error, blocking the certificate
// Can only be ErrDenylistMissing or ErrCertBanned
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pki/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestValidator_Validate(t *testing.T) {
})
t.Run("unknown issuer", func(t *testing.T) {
val := &validator{}
testSoftHard(t, val, validCertA, nil, ErrCertUntrusted)
testSoftHard(t, val, validCertA, ErrCertUntrusted, ErrCertUntrusted)
})
t.Run("missing crl", func(t *testing.T) {
testSoftHard(t, val, validCertBWithRevokedCA, nil, ErrCRLMissing)
Expand Down

0 comments on commit 3877cde

Please sign in to comment.