Skip to content

Commit

Permalink
feat: add debug information to cert validation error (#2579)
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa authored Dec 28, 2022
1 parent fa6c58f commit 7bbfea7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
return err
}
oidcIssuer := ce.GetIssuer()
sans := getSubjectAlternateNames(cert)
// If there are identities given, go through them and if one of them
// matches, call that good, otherwise, return an error.
if len(co.Identities) > 0 {
Expand Down Expand Up @@ -303,14 +304,14 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
if err != nil {
return fmt.Errorf("malformed subject in identity: %s : %w", identity.SubjectRegExp, err)
}
for _, san := range getSubjectAlternateNames(cert) {
for _, san := range sans {
if regex.MatchString(san) {
subjectMatches = true
break
}
}
case identity.Subject != "":
for _, san := range getSubjectAlternateNames(cert) {
for _, san := range sans {
if san == identity.Subject {
subjectMatches = true
break
Expand All @@ -321,11 +322,13 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
subjectMatches = true
}
if subjectMatches && issuerMatches {
// If both issuer / subject match, return verifier
// If both issuer / subject match, return verified
return nil
}
}
return &VerificationError{"none of the expected identities matched what was in the certificate"}
return &VerificationError{
fmt.Sprintf("none of the expected identities matched what was in the certificate, got subjects [%s] with issuer %s",
strings.Join(sans, ", "), oidcIssuer)}
}
return nil
}
Expand Down

0 comments on commit 7bbfea7

Please sign in to comment.