@@ -112,7 +112,6 @@ func (r *RekorVSARetriever) searchForImageDigest(ctx context.Context, imageDiges
112112 log .Debugf ("Calling client.SearchIndex" )
113113 entries , err := r .client .SearchIndex (ctx , query )
114114 if err != nil {
115- log .Debugf ("SearchIndex returned error: %v" , err )
116115 return nil , fmt .Errorf ("failed to search Rekor index: %w" , err )
117116 }
118117
@@ -241,66 +240,7 @@ func (r *RekorVSARetriever) classifyEntryKind(entry models.LogEntryAnon) string
241240 return "unknown"
242241}
243242
244- // extractDSSEEnvelopeFromEntry extracts the DSSE envelope from a Rekor entry
245- func (r * RekorVSARetriever ) extractDSSEEnvelopeFromEntry (entry * models.LogEntryAnon ) ([]byte , error ) {
246- // Determine entry type first
247- entryKind := r .classifyEntryKind (* entry )
248-
249- // Try to extract from attestation data first
250- if entry .Attestation != nil && entry .Attestation .Data != nil {
251- attestationData , err := base64 .StdEncoding .DecodeString (string (entry .Attestation .Data ))
252- if err == nil {
253- // Check if this contains a DSSE envelope
254- var attestation map [string ]interface {}
255- if err := json .Unmarshal (attestationData , & attestation ); err == nil {
256- if _ , hasPayload := attestation ["payload" ]; hasPayload {
257- // For intoto entries, payload is sufficient (signatures not required)
258- if entryKind == "intoto" {
259- return attestationData , nil
260- }
261- // For DSSE entries, require both payload and signatures
262- if _ , hasSignatures := attestation ["signatures" ]; hasSignatures {
263- return attestationData , nil
264- }
265- }
266- }
267- }
268- }
269-
270- // Try to extract from body field
271- if entry .Body != nil {
272- body , err := r .decodeBodyJSON (* entry )
273- if err == nil {
274- // Look for content.envelope structure
275- if content , ok := body ["content" ].(map [string ]interface {}); ok {
276- if envelope , ok := content ["envelope" ].(map [string ]interface {}); ok {
277- if _ , hasPayload := envelope ["payload" ]; hasPayload {
278- // For intoto entries, payload is sufficient (signatures not required)
279- if entryKind == "intoto" {
280- // Return the envelope as JSON
281- envelopeBytes , err := json .Marshal (envelope )
282- if err == nil {
283- return envelopeBytes , nil
284- }
285- }
286- // For DSSE entries, require both payload and signatures
287- if _ , hasSignatures := envelope ["signatures" ]; hasSignatures {
288- // Return the envelope as JSON
289- envelopeBytes , err := json .Marshal (envelope )
290- if err == nil {
291- return envelopeBytes , nil
292- }
293- }
294- }
295- }
296- }
297- }
298- }
299-
300- return nil , fmt .Errorf ("could not extract DSSE envelope from entry" )
301- }
302-
303- // RetrieveVSA retrieves VSA data as a DSSE envelope for a given image digest
243+ // RetrieveVSA retrieves the latest VSA data as a DSSE envelope for a given image digest
304244// This is the main method used by validation functions to get VSA data for signature verification
305245func (r * RekorVSARetriever ) RetrieveVSA (ctx context.Context , imageDigest string ) (* ssldsse.Envelope , error ) {
306246 if imageDigest == "" {
@@ -324,11 +264,11 @@ func (r *RekorVSARetriever) RetrieveVSA(ctx context.Context, imageDigest string)
324264 // Search for entries containing the image digest
325265 entries , err := r .searchForImageDigest (ctx , imageDigest )
326266 if err != nil {
327- return nil , fmt .Errorf ("failed to search for image digest: %w" , err )
267+ return nil , fmt .Errorf ("failed to search Rekor for image digest: %w" , err )
328268 }
329269
330270 if len (entries ) == 0 {
331- return nil , fmt .Errorf ("no entries found for image digest: %s" , imageDigest )
271+ return nil , fmt .Errorf ("no entries found in Rekor for image digest: %s" , imageDigest )
332272 }
333273
334274 // Find all in-toto 0.0.2 entries
@@ -410,6 +350,10 @@ func (r *RekorVSARetriever) buildDSSEEnvelopeFromIntotoV002(entry models.LogEntr
410350 return nil , fmt .Errorf ("envelope does not contain signatures" )
411351 }
412352
353+ if len (signaturesInterface ) == 0 {
354+ return nil , fmt .Errorf ("envelope contains empty signatures array" )
355+ }
356+
413357 var signatures []ssldsse.Signature
414358 for i , sigInterface := range signaturesInterface {
415359 sigMap , ok := sigInterface .(map [string ]interface {})
@@ -418,21 +362,27 @@ func (r *RekorVSARetriever) buildDSSEEnvelopeFromIntotoV002(entry models.LogEntr
418362 }
419363
420364 sig := ssldsse.Signature {}
365+
366+ // Extract sig field (required) - only support standard field
421367 if sigHex , ok := sigMap ["sig" ].(string ); ok {
422368 sig .Sig = sigHex
423- } else if sigHex , ok := sigMap ["signature" ].(string ); ok {
424- sig .Sig = sigHex
425369 } else {
426- continue
370+ return nil , fmt . Errorf ( "signature %d missing required 'sig' field" , i )
427371 }
428372
373+ // Extract keyid field (optional)
429374 if keyid , ok := sigMap ["keyid" ].(string ); ok {
430375 sig .KeyID = keyid
431376 }
432377
433378 signatures = append (signatures , sig )
434379 }
435380
381+ // Validate that we have at least one valid signature
382+ if len (signatures ) == 0 {
383+ return nil , fmt .Errorf ("no valid signatures found in envelope" )
384+ }
385+
436386 // Build the ssldsse.Envelope
437387 envelope := & ssldsse.Envelope {
438388 PayloadType : payloadType ,
0 commit comments