Skip to content

Commit 8743a71

Browse files
committed
incorporated review comments
Signed-off-by: Mukuls77 <[email protected]>
1 parent ce38bd7 commit 8743a71

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/cosign/verify.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ func verifyOCISignature(ctx context.Context, verifier signature.Verifier, sig pa
216216
return verifier.VerifySignature(bytes.NewReader(signature), bytes.NewReader(payload), options.WithContext(ctx))
217217
}
218218

219-
// ValidateAndUnpackCert calls ValidateAndUnpackCertWithIntermediates() by passing intermediate
220-
// certs from checkOpts as separate argument
219+
// ValidateAndUnpackCert creates a Verifier from a certificate. Verifies that the
220+
// certificate chains up to a trusted root using intermediate certificate chain coming from CheckOpts.
221+
// Optionally verifies the subject and issuer of the certificate.
221222
func ValidateAndUnpackCert(cert *x509.Certificate, co *CheckOpts) (signature.Verifier, error) {
222223
return ValidateAndUnpackCertWithIntermediates(cert, co, co.IntermediateCerts)
223224
}
@@ -246,9 +247,6 @@ func ValidateAndUnpackCertWithIntermediates(cert *x509.Certificate, co *CheckOpt
246247
}
247248

248249
// Now verify the cert, then the signature.
249-
if intermediateCerts == nil {
250-
intermediateCerts = co.IntermediateCerts
251-
}
252250
chains, err := TrustedCert(cert, co.RootCerts, intermediateCerts)
253251

254252
if err != nil {
@@ -742,6 +740,10 @@ func verifyInternal(ctx context.Context, sig oci.Signature, h v1.Hash,
742740
}
743741
}
744742
}
743+
// In case pool is not set than set it from co.IntermediateCerts
744+
if pool == nil {
745+
pool = co.IntermediateCerts
746+
}
745747
verifier, err = ValidateAndUnpackCertWithIntermediates(cert, co, pool)
746748
if err != nil {
747749
return false, err

0 commit comments

Comments
 (0)