Skip to content

Commit

Permalink
fixup! Verify the certificate chain against the Fulcio root trust by …
Browse files Browse the repository at this point in the history
…default

Signed-off-by: Kazuma Watanabe <watassbass@gmail.com>
  • Loading branch information
wata727 committed Aug 7, 2022
1 parent ce81d79 commit eda267b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions cmd/cosign/cli/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,16 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
return err
}
if c.CertChain == "" {
err = cosign.CheckCertificatePolicy(cert, co)
// If no certChain is passed, the Fulcio root certificate will be used
co.RootCerts, err = fulcio.GetRoots()
if err != nil {
return err
return fmt.Errorf("getting Fulcio roots: %w", err)
}
co.IntermediateCerts, err = fulcio.GetIntermediates()
if err != nil {
return fmt.Errorf("getting Fulcio intermediates: %w", err)
}
pubKey, err = signature.LoadVerifier(cert.PublicKey, crypto.SHA256)
pubKey, err = cosign.ValidateAndUnpackCert(cert, co)
if err != nil {
return err
}
Expand Down
13 changes: 8 additions & 5 deletions cmd/cosign/cli/verify/verify_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package verify

import (
"context"
"crypto"
"errors"
"flag"
"fmt"
Expand All @@ -28,7 +27,6 @@ import (
"github.com/sigstore/cosign/pkg/cosign/pkcs11key"
"github.com/sigstore/cosign/pkg/cosign/rego"
"github.com/sigstore/cosign/pkg/oci"
"github.com/sigstore/sigstore/pkg/signature"

"github.com/sigstore/cosign/cmd/cosign/cli/fulcio"
"github.com/sigstore/cosign/cmd/cosign/cli/options"
Expand Down Expand Up @@ -139,11 +137,16 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, images []string) (e
return fmt.Errorf("loading certificate from reference: %w", err)
}
if c.CertChain == "" {
err = cosign.CheckCertificatePolicy(cert, co)
// If no certChain is passed, the Fulcio root certificate will be used
co.RootCerts, err = fulcio.GetRoots()
if err != nil {
return err
return fmt.Errorf("getting Fulcio roots: %w", err)
}
co.IntermediateCerts, err = fulcio.GetIntermediates()
if err != nil {
return fmt.Errorf("getting Fulcio intermediates: %w", err)
}
co.SigVerifier, err = signature.LoadVerifier(cert.PublicKey, crypto.SHA256)
co.SigVerifier, err = cosign.ValidateAndUnpackCert(cert, co)
if err != nil {
return fmt.Errorf("creating certificate verifier: %w", err)
}
Expand Down

0 comments on commit eda267b

Please sign in to comment.