11//
2- // Copyright 2021 The Sigstore Authors.
2+ // Copyright 2022 The Sigstore Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -86,7 +86,7 @@ func (v V002Entry) IndexKeys() ([]string, error) {
8686 return nil , err
8787 }
8888
89- result = append (result , keyObj .EmailAddresses ()... )
89+ result = append (result , keyObj .Subjects ()... )
9090 }
9191
9292 payloadKey := strings .ToLower (fmt .Sprintf ("%s:%s" , * v .IntotoObj .Content .PayloadHash .Algorithm , * v .IntotoObj .Content .PayloadHash .Value ))
@@ -98,11 +98,11 @@ func (v V002Entry) IndexKeys() ([]string, error) {
9898 hashkey := strings .ToLower (fmt .Sprintf ("%s:%s" , * v .IntotoObj .Content .Hash .Algorithm , * v .IntotoObj .Content .Hash .Value ))
9999 result = append (result , hashkey )
100100
101- if v .IntotoObj .Content .Envelope .Payload == "" {
101+ if * v .IntotoObj .Content .Envelope .Payload == "" {
102102 log .Logger .Info ("IntotoObj DSSE payload is empty" )
103103 return result , nil
104104 }
105- decodedPayload , err := base64 .StdEncoding .DecodeString (string (v .IntotoObj .Content .Envelope .Payload ))
105+ decodedPayload , err := base64 .StdEncoding .DecodeString (string (* v .IntotoObj .Content .Envelope .Payload ))
106106 if err != nil {
107107 return result , fmt .Errorf ("could not decode envelope payload: %w" , err )
108108 }
@@ -152,7 +152,7 @@ func parseSlsaPredicate(p []byte) (*in_toto.ProvenanceStatement, error) {
152152func (v * V002Entry ) Unmarshal (pe models.ProposedEntry ) error {
153153 it , ok := pe .(* models.Intoto )
154154 if ! ok {
155- return errors .New ("cannot unmarshal non Intoto v0.0.1 type" )
155+ return errors .New ("cannot unmarshal non Intoto v0.0.2 type" )
156156 }
157157
158158 var err error
@@ -165,12 +165,12 @@ func (v *V002Entry) Unmarshal(pe models.ProposedEntry) error {
165165 return err
166166 }
167167
168- if string (v .IntotoObj .Content .Envelope .Payload ) == "" {
169- return nil
168+ if string (* v .IntotoObj .Content .Envelope .Payload ) == "" {
169+ return errors . New ( "DSSE envelope does not contain a payload" )
170170 }
171171
172172 env := & dsse.Envelope {
173- Payload : string (v .IntotoObj .Content .Envelope .Payload ),
173+ Payload : string (* v .IntotoObj .Content .Envelope .Payload ),
174174 PayloadType : * v .IntotoObj .Content .Envelope .PayloadType ,
175175 }
176176
@@ -190,13 +190,12 @@ func (v *V002Entry) Unmarshal(pe models.ProposedEntry) error {
190190
191191 v .env = * env
192192
193- decodedPayload , err := base64 .StdEncoding .DecodeString (string (v .IntotoObj .Content .Envelope .Payload ))
193+ decodedPayload , err := base64 .StdEncoding .DecodeString (string (* v .IntotoObj .Content .Envelope .Payload ))
194194 if err != nil {
195195 return fmt .Errorf ("could not decode envelope payload: %w" , err )
196196 }
197197
198- paeEncodedPayload := dsse .PAE (* v .IntotoObj .Content .Envelope .PayloadType , decodedPayload )
199- h := sha256 .Sum256 (paeEncodedPayload )
198+ h := sha256 .Sum256 (decodedPayload )
200199 v .IntotoObj .Content .PayloadHash = & models.IntotoV002SchemaContentPayloadHash {
201200 Algorithm : swag .String (models .IntotoV002SchemaContentPayloadHashAlgorithmSha256 ),
202201 Value : swag .String (hex .EncodeToString (h [:])),
@@ -209,12 +208,17 @@ func (v *V002Entry) Canonicalize(ctx context.Context) ([]byte, error) {
209208
210209 canonicalEntry := models.IntotoV002Schema {
211210 Content : & models.IntotoV002SchemaContent {
212- Envelope : v . IntotoObj . Content . Envelope ,
213- Hash : v . IntotoObj . Content . Hash ,
214- PayloadHash : v . IntotoObj . Content . PayloadHash ,
211+ Envelope : & models. IntotoV002SchemaContentEnvelope {} ,
212+ Hash : & models. IntotoV002SchemaContentHash {} ,
213+ PayloadHash : & models. IntotoV002SchemaContentPayloadHash {} ,
215214 },
216215 }
217216
217+ canonicalEntry .Content .Envelope .PayloadType = v .IntotoObj .Content .Envelope .PayloadType
218+ canonicalEntry .Content .Envelope .Signatures = v .IntotoObj .Content .Envelope .Signatures
219+ canonicalEntry .Content .Hash = v .IntotoObj .Content .Hash
220+ canonicalEntry .Content .PayloadHash = v .IntotoObj .Content .PayloadHash
221+
218222 itObj := models.Intoto {}
219223 itObj .APIVersion = swag .String (APIVERSION )
220224 itObj .Spec = & canonicalEntry
@@ -237,7 +241,11 @@ func (v *V002Entry) AttestationKeyValue() (string, []byte) {
237241 log .Logger .Infof ("Skipping attestation storage, size %d is greater than max %d" , storageSize , viper .GetInt ("max_attestation_size" ))
238242 return "" , nil
239243 }
240- attBytes , _ := base64 .StdEncoding .DecodeString (v .env .Payload )
244+ attBytes , err := base64 .StdEncoding .DecodeString (v .env .Payload )
245+ if err != nil {
246+ log .Logger .Infof ("could not decode envelope payload: %w" , err )
247+ return "" , nil
248+ }
241249 return v .AttestationKey (), attBytes
242250}
243251
@@ -279,8 +287,12 @@ func (v *verifier) Verify(data, sig []byte) error {
279287
280288func (v V002Entry ) CreateFromArtifactProperties (_ context.Context , props types.ArtifactProperties ) (models.ProposedEntry , error ) {
281289 returnVal := models.Intoto {}
282- re := V002Entry {}
283-
290+ re := V002Entry {
291+ IntotoObj : models.IntotoV002Schema {
292+ Content : & models.IntotoV002SchemaContent {
293+ Envelope : & models.IntotoV002SchemaContentEnvelope {},
294+ },
295+ }}
284296 var err error
285297 artifactBytes := props .ArtifactBytes
286298 if artifactBytes == nil {
@@ -334,7 +346,7 @@ func (v V002Entry) CreateFromArtifactProperties(_ context.Context, props types.A
334346 return nil , err
335347 }
336348
337- re .IntotoObj .Content .Envelope .Payload = env .Payload
349+ re .IntotoObj .Content .Envelope .Payload = swag . String ( env .Payload )
338350 re .IntotoObj .Content .Envelope .PayloadType = & env .PayloadType
339351
340352 for _ , sig := range env .Signatures {
0 commit comments