Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify the certificate chain against the Fulcio root trust by default #2139

Merged
merged 3 commits into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Fulcio root provided in the TUF root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mention it to TUF here because I have a concern about the description would be too long. If we should mention it, please let me know so I fix it.


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 == "" {
asraa marked this conversation as resolved.
Show resolved Hide resolved
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.