Skip to content

Commit

Permalink
Verify the certificate chain against the Fulcio root trust by default (
Browse files Browse the repository at this point in the history
…#2139)

* Verify the certificate chain against the Fulcio root trust by default

Signed-off-by: Kazuma Watanabe <watassbass@gmail.com>

* fixup! Verify the certificate chain against the Fulcio root trust by default

Signed-off-by: Kazuma Watanabe <watassbass@gmail.com>

* fixup! fixup! Verify the certificate chain against the Fulcio root trust by default

Signed-off-by: Kazuma Watanabe <watassbass@gmail.com>
  • Loading branch information
wata727 committed Aug 9, 2022
1 parent 7a334aa commit fdceee4
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/cosign/cli/options/certificate.go
Expand Up @@ -37,7 +37,7 @@ var _ Interface = (*RekorOptions)(nil)
// AddFlags implements Interface
func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Cert, "certificate", "",
"path to the public certificate")
"path to the public certificate. The certificate will be verified against the Fulcio roots if the --certificate-chain option is not passed.")

cmd.Flags().StringVar(&o.CertEmail, "certificate-email", "",
"the email expected in a valid Fulcio certificate")
Expand Down
11 changes: 8 additions & 3 deletions cmd/cosign/cli/verify/verify.go
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
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
11 changes: 8 additions & 3 deletions cmd/cosign/cli/verify/verify_blob.go
Expand Up @@ -119,11 +119,16 @@ func VerifyBlobCmd(ctx context.Context, ko options.KeyOpts, certRef, certEmail,
EnforceSCT: enforceSCT,
}
if 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)
}
verifier, err = signature.LoadVerifier(cert.PublicKey, crypto.SHA256)
co.IntermediateCerts, err = fulcio.GetIntermediates()
if err != nil {
return fmt.Errorf("getting Fulcio intermediates: %w", err)
}
verifier, err = cosign.ValidateAndUnpackCert(cert, co)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion doc/cosign_dockerfile_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/cosign_manifest_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/cosign_verify-attestation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/cosign_verify-blob.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/cosign_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdceee4

Please sign in to comment.