Skip to content

Commit 47d33ac

Browse files
committed
added updated based on linked PRs
Signed-off-by: pxp928 <parth.psu@gmail.com>
1 parent 4c10b1a commit 47d33ac

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pkg/types/intoto/intoto.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ func (it *BaseIntotoType) CreateProposedEntry(ctx context.Context, version strin
7272
func (it BaseIntotoType) DefaultVersion() string {
7373
return "0.0.2"
7474
}
75+
76+
// SupportedVersions returns the supported versions for this type;
77+
// it deliberately omits 0.0.1 from the list of supported versions as that
78+
// version did not persist signatures inside the log entry
79+
func (it BaseIntotoType) SupportedVersions() []string {
80+
return []string{"0.0.2"}
81+
}

pkg/types/intoto/intoto_schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"description": "Intoto for Rekord objects",
66
"type": "object",
77
"oneOf": [
8+
{
9+
"$ref": "v0.0.1/intoto_v0_0_1_schema.json"
10+
},
811
{
912
"$ref": "v0.0.2/intoto_v0_0_2_schema.json"
1013
}

pkg/types/intoto/v0.0.2/entry_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package intoto
1717

1818
import (
19+
"bytes"
20+
"context"
1921
"crypto"
2022
"crypto/ecdsa"
2123
"crypto/elliptic"
@@ -33,13 +35,16 @@ import (
3335
"strings"
3436
"testing"
3537

38+
"github.com/go-openapi/runtime"
3639
"github.com/go-openapi/strfmt"
3740
"github.com/go-openapi/swag"
3841
"github.com/google/go-cmp/cmp"
42+
"github.com/google/go-cmp/cmp/cmpopts"
3943
"github.com/in-toto/in-toto-golang/in_toto"
4044
slsa "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2"
4145
"github.com/secure-systems-lab/go-securesystemslib/dsse"
4246
"github.com/sigstore/rekor/pkg/generated/models"
47+
"github.com/sigstore/rekor/pkg/types"
4348
"github.com/sigstore/sigstore/pkg/signature"
4449
"go.uber.org/goleak"
4550
)
@@ -297,6 +302,35 @@ func TestV002Entry_Unmarshal(t *testing.T) {
297302
if !reflect.DeepEqual(got, want) {
298303
t.Errorf("V002Entry.IndexKeys() = %v, want %v", got, want)
299304
}
305+
payloadBytes, _ := v.env.DecodeB64Payload()
306+
payloadSha := sha256.Sum256(payloadBytes)
307+
payloadHash := hex.EncodeToString(payloadSha[:])
308+
309+
canonicalBytes, err := v.Canonicalize(context.Background())
310+
if err != nil {
311+
t.Errorf("error canonicalizing entry: %v", err)
312+
}
313+
314+
pe, err := models.UnmarshalProposedEntry(bytes.NewReader(canonicalBytes), runtime.JSONConsumer())
315+
if err != nil {
316+
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tt.name, err)
317+
}
318+
canonicalEntry, err := types.UnmarshalEntry(pe)
319+
if err != nil {
320+
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tt.name, err)
321+
}
322+
canonicalV002 := canonicalEntry.(*V002Entry)
323+
fmt.Printf("%v", canonicalV002.IntotoObj.Content)
324+
if *canonicalV002.IntotoObj.Content.Hash.Value != *tt.it.Content.Hash.Value {
325+
t.Errorf("envelope hashes do not match post canonicalization: %v %v", *canonicalV002.IntotoObj.Content.Hash.Value, *tt.it.Content.Hash.Value)
326+
}
327+
if canonicalV002.AttestationKey() != "" && *canonicalV002.IntotoObj.Content.PayloadHash.Value != payloadHash {
328+
t.Errorf("payload hashes do not match post canonicalization: %v %v", canonicalV002.IntotoObj.Content.PayloadHash.Value, payloadHash)
329+
}
330+
canonicalIndexKeys, _ := canonicalV002.IndexKeys()
331+
if !cmp.Equal(got, canonicalIndexKeys, cmpopts.SortSlices(func(x, y string) bool { return x < y })) {
332+
t.Errorf("index keys from hydrated object do not match those generated from canonicalized (and re-hydrated) object: %v %v", got, canonicalIndexKeys)
333+
}
300334

301335
return nil
302336
}

0 commit comments

Comments
 (0)