Skip to content

Commit

Permalink
Fix panic for DSSE canonicalization (#1923)
Browse files Browse the repository at this point in the history
Handles if the array of signatures contains missing data.

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
  • Loading branch information
haydentherapper authored Dec 20, 2023
1 parent 0793130 commit 6020532
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/types/dsse/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ func (v *V001Entry) Canonicalize(_ context.Context) ([]byte, error) {
ProposedContent: nil, // this is explicitly done as we don't want to canonicalize the envelope
}

for _, s := range canonicalEntry.Signatures {
if s.Signature == nil {
return nil, errors.New("canonical entry missing required signature")
}
}

sort.Slice(canonicalEntry.Signatures, func(i, j int) bool {
return *canonicalEntry.Signatures[i].Signature < *canonicalEntry.Signatures[j].Signature
})
Expand Down
9 changes: 9 additions & 0 deletions pkg/types/dsse/v0.0.1/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,12 @@ func TestInsertable(t *testing.T) {
})
}
}

func TestCanonicalizeHandlesInvalidInput(t *testing.T) {
v := &V001Entry{}
v.DSSEObj.Signatures = []*models.DSSEV001SchemaSignaturesItems0{{Signature: nil}, {Signature: nil}}
_, err := v.Canonicalize(context.TODO())
if err == nil {
t.Fatalf("expected error canonicalizing invalid input")
}
}

0 comments on commit 6020532

Please sign in to comment.