Skip to content

Commit

Permalink
Add ctlogs to cosign trusted-root create
Browse files Browse the repository at this point in the history
With `--ignore-sct` to support if you are using keys instead of Fulcio.

Signed-off-by: Zach Steindler <[email protected]>
  • Loading branch information
steiza committed Sep 12, 2024
1 parent e0041bb commit 06284e2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/cosign/cli/options/trustedroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type TrustedRootCreateOptions struct {
CAIntermediates string
CARoots string
CertChain string
IgnoreSCT bool
Out string
RekorURL string
TSACertChainPath string
Expand Down Expand Up @@ -53,6 +54,10 @@ func (o *TrustedRootCreateOptions) AddFlags(cmd *cobra.Command) {
cmd.MarkFlagsMutuallyExclusive("ca-roots", "certificate-chain")
cmd.MarkFlagsMutuallyExclusive("ca-intermediates", "certificate-chain")

cmd.Flags().BoolVar(&o.IgnoreSCT, "ignore-sct", false,
"when set, do not include key for verifying certificate transparency "+
"log. Set this if you signed with a key instead of using Fulcio.")

cmd.Flags().StringVar(&o.Out, "out", "",
"path to output trusted root")

Expand Down
1 change: 1 addition & 0 deletions cmd/cosign/cli/trustedroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func trustedRootCreate() *cobra.Command {
CAIntermediates: o.CAIntermediates,
CARoots: o.CARoots,
CertChain: o.CertChain,
IgnoreSCT: o.IgnoreSCT,
Out: o.Out,
RekorURL: o.RekorURL,
TSACertChainPath: o.TSACertChainPath,
Expand Down
29 changes: 27 additions & 2 deletions cmd/cosign/cli/trustedroot/trustedroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/pem"
"errors"
"fmt"
Expand All @@ -29,19 +30,22 @@ import (
"github.com/sigstore/sigstore-go/pkg/root"

"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/v2/pkg/cosign"
)

type CreateCmd struct {
CAIntermediates string
CARoots string
CertChain string
IgnoreSCT bool
Out string
RekorURL string
TSACertChainPath string
}

func (c *CreateCmd) Exec(_ context.Context) error {
func (c *CreateCmd) Exec(ctx context.Context) error {
var fulcioCertAuthorities []root.CertificateAuthority
ctLogs := make(map[string]*root.TransparencyLog)
var timestampAuthorities []root.CertificateAuthority
rekorTransparencyLogs := make(map[string]*root.TransparencyLog)

Expand Down Expand Up @@ -80,6 +84,26 @@ func (c *CreateCmd) Exec(_ context.Context) error {
}
}

if !c.IgnoreSCT {
ctLogPubKeys, err := cosign.GetCTLogPubs(ctx)
if err != nil {
return err
}

for id, key := range ctLogPubKeys.Keys {
idBytes, err := hex.DecodeString(id)
if err != nil {
return err
}
ctLogs[id] = &root.TransparencyLog{
ID: idBytes,
HashFunc: crypto.SHA256,
PublicKey: key.PubKey,
SignatureHashFunc: crypto.SHA256,
}
}
}

if c.RekorURL != "" {
rekorClient, err := rekor.NewClient(c.RekorURL)
if err != nil {
Expand Down Expand Up @@ -124,7 +148,8 @@ func (c *CreateCmd) Exec(_ context.Context) error {
}

newTrustedRoot, err := root.NewTrustedRoot(root.TrustedRootMediaType01,
fulcioCertAuthorities, nil, timestampAuthorities, rekorTransparencyLogs,
fulcioCertAuthorities, ctLogs, timestampAuthorities,
rekorTransparencyLogs,
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/cosign/cli/trustedroot/trustedroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestCreateCmd(t *testing.T) {

trustedrootCreate := CreateCmd{
CertChain: fulcioChainPath,
IgnoreSCT: true,
Out: outPath,
TSACertChainPath: tsaChainPath,
}
Expand Down
1 change: 1 addition & 0 deletions doc/cosign_trusted-root_create.md

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

0 comments on commit 06284e2

Please sign in to comment.