Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions cmd/cosign/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package attest
import (
"bytes"
"context"
"crypto"
_ "crypto/sha256" // for `crypto.SHA256`
"encoding/json"
"fmt"
Expand Down Expand Up @@ -252,10 +251,9 @@ func (c *AttestCommand) Exec(ctx context.Context, imageRef string) error {
if err != nil {
return err
}
var pubKey *crypto.PublicKey
pk, err := sv.PublicKey()
if err == nil {
pubKey = &pk
pubKey, err := sv.PublicKey()
if err != nil {
return err
}
bundleBytes, err := cbundle.MakeNewBundle(pubKey, rekorEntry, payload, signedPayload, signerBytes, timestampBytes)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions cmd/cosign/cli/attest/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
if c.BundlePath != "" {
var contents []byte
if c.NewBundleFormat {
var pubKey *crypto.PublicKey
pk, err := sv.PublicKey()
if err == nil {
pubKey = &pk
pubKey, err := sv.PublicKey()
if err != nil {
return err
}

contents, err = cbundle.MakeNewBundle(pubKey, rekorEntry, payload, sig, signer, timestampBytes)
Expand Down
7 changes: 3 additions & 4 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ func signDigestBundle(ctx context.Context, digest name.Digest, ko options.KeyOpt
return fmt.Errorf("constructing client options: %w", err)
}

var pubKey *crypto.PublicKey
pk, err := sv.PublicKey()
if err == nil {
pubKey = &pk
pubKey, err := sv.PublicKey()
if err != nil {
return err
}

bundleBytes, err := cbundle.MakeNewBundle(pubKey, rekorEntry, payload, signedPayload, signerBytes, timestampBytes)
Expand Down
1 change: 1 addition & 0 deletions cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ against the transparency log.`,
v := &verify.VerifyCommand{
RegistryOptions: o.Registry,
CertVerifyOptions: o.CertVerify,
CommonVerifyOptions: o.CommonVerifyOptions,
CheckClaims: o.CheckClaims,
KeyRef: o.Key,
CertRef: o.CertVerify.Cert,
Expand Down
11 changes: 4 additions & 7 deletions pkg/cosign/bundle/protobundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,20 @@ func MakeProtobufBundle(hint string, rawCert []byte, rekorEntry *models.LogEntry
return bundle, nil
}

func MakeNewBundle(pubKey *crypto.PublicKey, rekorEntry *models.LogEntryAnon, payload, sig, signer, timestampBytes []byte) ([]byte, error) {
func MakeNewBundle(pubKey crypto.PublicKey, rekorEntry *models.LogEntryAnon, payload, sig, signer, timestampBytes []byte) ([]byte, error) {
// Determine if the signer is a certificate or not
var hint string
var rawCert []byte

if pubKey != nil {
pkixPubKey, err := x509.MarshalPKIXPublicKey(*pubKey)
cert, err := cryptoutils.UnmarshalCertificatesFromPEM(signer)
if err != nil || len(cert) == 0 {
pkixPubKey, err := x509.MarshalPKIXPublicKey(pubKey)
if err != nil {
return nil, err
}
hashedBytes := sha256.Sum256(pkixPubKey)
hint = base64.StdEncoding.EncodeToString(hashedBytes[:])
} else {
cert, err := cryptoutils.UnmarshalCertificatesFromPEM(signer)
if err != nil {
return nil, err
}
rawCert = cert[0].Raw
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ func TestSignVerifyBundle(t *testing.T) {
NewBundleFormat: true,
UseSignedTimestamps: false,
}

must(cmd.Exec(ctx, args), t)
}

func TestAttestVerify(t *testing.T) {
Expand Down
Loading