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

switch to uploading DSSE types to rekor instead of intoto #3113

Merged
merged 3 commits into from
Aug 15, 2023
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
2 changes: 1 addition & 1 deletion cmd/cosign/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *AttestCommand) Exec(ctx context.Context, imageRef string) error {
}
if shouldUpload {
bundle, err := uploadToTlog(ctx, sv, c.RekorURL, func(r *client.Rekor, b []byte) (*models.LogEntryAnon, error) {
return cosign.TLogUploadInTotoAttestation(ctx, r, signedPayload, b)
return cosign.TLogUploadDSSEEnvelope(ctx, r, signedPayload, b)
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/cosign/cli/attest/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
if err != nil {
return err
}
entry, err := cosign.TLogUploadInTotoAttestation(ctx, rekorClient, sig, rekorBytes)
entry, err := cosign.TLogUploadDSSEEnvelope(ctx, rekorClient, sig, rekorBytes)
if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/cosign/tlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func GetTlogEntry(ctx context.Context, rekorClient *client.Rekor, entryUUID stri
return nil, errors.New("empty response")
}

func proposedEntry(b64Sig string, payload, pubKey []byte) ([]models.ProposedEntry, error) {
func proposedEntries(b64Sig string, payload, pubKey []byte) ([]models.ProposedEntry, error) {
var proposedEntry []models.ProposedEntry
signature, err := base64.StdEncoding.DecodeString(b64Sig)
if err != nil {
Expand All @@ -380,11 +380,15 @@ func proposedEntry(b64Sig string, payload, pubKey []byte) ([]models.ProposedEntr
// The fact that there's no signature (or empty rather), implies
// that this is an Attestation that we're verifying.
if len(signature) == 0 {
e, err := intotoEntry(context.Background(), payload, pubKey)
intotoEntry, err := intotoEntry(context.Background(), payload, pubKey)
if err != nil {
return nil, err
}
proposedEntry = []models.ProposedEntry{e}
dsseEntry, err := dsseEntry(context.Background(), payload, pubKey)
if err != nil {
return nil, err
}
proposedEntry = []models.ProposedEntry{dsseEntry, intotoEntry}
} else {
sha256CheckSum := sha256.New()
if _, err := sha256CheckSum.Write(payload); err != nil {
Expand All @@ -404,12 +408,12 @@ func FindTlogEntry(ctx context.Context, rekorClient *client.Rekor,
b64Sig string, payload, pubKey []byte) ([]models.LogEntryAnon, error) {
searchParams := entries.NewSearchLogQueryParamsWithContext(ctx)
searchLogQuery := models.SearchLogQuery{}
proposedEntry, err := proposedEntry(b64Sig, payload, pubKey)
proposedEntries, err := proposedEntries(b64Sig, payload, pubKey)
if err != nil {
return nil, err
}

searchLogQuery.SetEntries(proposedEntry)
searchLogQuery.SetEntries(proposedEntries)

searchParams.SetEntry(&searchLogQuery)
resp, err := rekorClient.Entries.SearchLogQuery(searchParams)
Expand Down
1 change: 1 addition & 0 deletions pkg/cosign/tlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
)

func TestGetRekorPubKeys(t *testing.T) {
t.Setenv("TUF_ROOT", t.TempDir())
keys, err := GetRekorPubs(context.Background())
if err != nil {
t.Fatalf("Unexpected error calling GetRekorPubs, expected nil: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cosign/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestVerifyImageSignatureWithNoChain(t *testing.T) {
signature, _ := privKey.Sign(rand.Reader, h[:], crypto.SHA256)

// Create a fake bundle
pe, _ := proposedEntry(base64.StdEncoding.EncodeToString(signature), payload, pemLeaf)
pe, _ := proposedEntries(base64.StdEncoding.EncodeToString(signature), payload, pemLeaf)
entry, _ := rtypes.UnmarshalEntry(pe[0])
leaf, _ := entry.Canonicalize(ctx)
rekorBundle := CreateTestBundle(ctx, t, sv, leaf)
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestVerifyImageSignatureWithInvalidPublicKeyType(t *testing.T) {
signature, _ := privKey.Sign(rand.Reader, h[:], crypto.SHA256)

// Create a fake bundle
pe, _ := proposedEntry(base64.StdEncoding.EncodeToString(signature), payload, pemLeaf)
pe, _ := proposedEntries(base64.StdEncoding.EncodeToString(signature), payload, pemLeaf)
entry, _ := rtypes.UnmarshalEntry(pe[0])
leaf, _ := entry.Canonicalize(ctx)
rekorBundle := CreateTestBundle(ctx, t, sv, leaf)
Expand Down
Loading