@@ -107,38 +107,6 @@ def _find_provenance(self, discovery_functions: list[partial[list[InTotoPayload]
107
107
logger .debug ("No provenance found." )
108
108
return []
109
109
110
- def verify_provenance (self , purl : PackageURL , provenance : list [InTotoPayload ]) -> bool :
111
- """Verify the passed provenance.
112
-
113
- Parameters
114
- ----------
115
- purl: PackageURL
116
- The PURL of the analysis target.
117
- provenance: list[InTotoPayload]
118
- The list of provenance.
119
-
120
- Returns
121
- -------
122
- bool
123
- True if the provenance could be verified, or False otherwise.
124
- """
125
- if determine_abstract_purl_type (purl ) == AbstractPurlType .REPOSITORY :
126
- # Do not perform default verification for repository type targets.
127
- return False
128
-
129
- verification_function = None
130
-
131
- if purl .type == "npm" :
132
- verification_function = partial (verify_npm_provenance , purl , provenance )
133
-
134
- # TODO other verification functions go here.
135
-
136
- if verification_function :
137
- return verification_function ()
138
-
139
- logger .debug ("Provenance verification not supported for PURL type: %s" , purl .type )
140
- return False
141
-
142
110
143
111
def find_npm_provenance (purl : PackageURL , registry : NPMRegistry ) -> list [InTotoPayload ]:
144
112
"""Find and download the NPM based provenance for the passed PURL.
@@ -213,72 +181,6 @@ def find_npm_provenance(purl: PackageURL, registry: NPMRegistry) -> list[InTotoP
213
181
return []
214
182
215
183
216
- def verify_npm_provenance (purl : PackageURL , provenance : list [InTotoPayload ]) -> bool :
217
- """Compare the unsigned payload subject digest with the signed payload digest, if available.
218
-
219
- Parameters
220
- ----------
221
- purl: PackageURL
222
- The PURL of the analysis target.
223
- provenance: list[InTotoPayload]
224
- The provenances to verify.
225
-
226
- Returns
227
- -------
228
- bool
229
- True if the provenance was verified, or False otherwise.
230
- """
231
- if len (provenance ) != 2 :
232
- logger .debug ("Expected unsigned and signed provenance." )
233
- return False
234
-
235
- signed_subjects = provenance [1 ].statement .get ("subject" )
236
- if not signed_subjects :
237
- return False
238
-
239
- unsigned_subjects = provenance [0 ].statement .get ("subject" )
240
- if not unsigned_subjects :
241
- return False
242
-
243
- found_signed_subject = None
244
- for signed_subject in signed_subjects :
245
- name = signed_subject .get ("name" )
246
- if name and name == str (purl ):
247
- found_signed_subject = signed_subject
248
- break
249
-
250
- if not found_signed_subject :
251
- return False
252
-
253
- found_unsigned_subject = None
254
- for unsigned_subject in unsigned_subjects :
255
- name = unsigned_subject .get ("name" )
256
- if name and name == str (purl ):
257
- found_unsigned_subject = unsigned_subject
258
- break
259
-
260
- if not found_unsigned_subject :
261
- return False
262
-
263
- signed_digest = found_signed_subject .get ("digest" )
264
- unsigned_digest = found_unsigned_subject .get ("digest" )
265
- if not (signed_digest and unsigned_digest ):
266
- return False
267
-
268
- # For signed and unsigned to match, the digests must be identical.
269
- if signed_digest != unsigned_digest :
270
- return False
271
-
272
- key = list (signed_digest .keys ())[0 ]
273
- logger .debug (
274
- "Verified provenance against signed companion. Signed: %s, Unsigned: %s." ,
275
- signed_digest [key ][:7 ],
276
- unsigned_digest [key ][:7 ],
277
- )
278
-
279
- return True
280
-
281
-
282
184
def find_gav_provenance (purl : PackageURL , registry : JFrogMavenRegistry ) -> list [InTotoPayload ]:
283
185
"""Find and download the GAV based provenance for the passed PURL.
284
186
@@ -377,7 +279,9 @@ def find_gav_provenance(purl: PackageURL, registry: JFrogMavenRegistry) -> list[
377
279
return provenances [:1 ]
378
280
379
281
380
- def find_provenance_from_ci (analyze_ctx : AnalyzeContext , git_obj : Git | None ) -> InTotoPayload | None :
282
+ def find_provenance_from_ci (
283
+ analyze_ctx : AnalyzeContext , git_obj : Git | None , download_path : str
284
+ ) -> InTotoPayload | None :
381
285
"""Try to find provenance from CI services of the repository.
382
286
383
287
Note that we stop going through the CI services once we encounter a CI service
@@ -389,9 +293,11 @@ def find_provenance_from_ci(analyze_ctx: AnalyzeContext, git_obj: Git | None) ->
389
293
Parameters
390
294
----------
391
295
analyze_ctx: AnalyzeContext
392
- The contenxt of the ongoing analysis.
296
+ The context of the ongoing analysis.
393
297
git_obj: Git | None
394
298
The Pydriller Git object representing the repository, if any.
299
+ download_path: str
300
+ The pre-existing location to download discovered files to.
395
301
396
302
Returns
397
303
-------
@@ -468,66 +374,63 @@ def find_provenance_from_ci(analyze_ctx: AnalyzeContext, git_obj: Git | None) ->
468
374
ci_info ["provenance_assets" ].extend (provenance_assets )
469
375
470
376
# Download the provenance assets and load the provenance payloads.
471
- download_provenances_from_github_actions_ci_service (
472
- ci_info ,
473
- )
377
+ download_provenances_from_ci_service (ci_info , download_path )
474
378
475
379
# TODO consider how to handle multiple payloads here.
476
380
return ci_info ["provenances" ][0 ].payload if ci_info ["provenances" ] else None
477
381
478
382
return None
479
383
480
384
481
- def download_provenances_from_github_actions_ci_service (ci_info : CIInfo ) -> None :
385
+ def download_provenances_from_ci_service (ci_info : CIInfo , download_path : str ) -> None :
482
386
"""Download provenances from GitHub Actions.
483
387
484
388
Parameters
485
389
----------
486
390
ci_info: CIInfo,
487
391
A ``CIInfo`` instance that holds a GitHub Actions git service object.
392
+ download_path: str
393
+ The pre-existing location to download discovered files to.
488
394
"""
489
395
ci_service = ci_info ["service" ]
490
396
prov_assets = ci_info ["provenance_assets" ]
491
-
397
+ if not os .path .isdir (download_path ):
398
+ logger .debug ("Download location is not a valid directory." )
399
+ return
492
400
try :
493
- with tempfile .TemporaryDirectory () as temp_path :
494
- downloaded_provs = []
495
- for prov_asset in prov_assets :
496
- # Check the size before downloading.
497
- if prov_asset .size_in_bytes > defaults .getint (
498
- "slsa.verifier" ,
499
- "max_download_size" ,
500
- fallback = 1000000 ,
501
- ):
502
- logger .info (
503
- "Skip verifying the provenance %s: asset size too large." ,
504
- prov_asset .name ,
505
- )
506
- continue
401
+ downloaded_provs = []
402
+ for prov_asset in prov_assets :
403
+ # Check the size before downloading.
404
+ if prov_asset .size_in_bytes > defaults .getint ("slsa.verifier" , "max_download_size" , fallback = 1000000 ):
405
+ logger .info (
406
+ "Skip verifying the provenance %s: asset size too large." ,
407
+ prov_asset .name ,
408
+ )
409
+ continue
507
410
508
- provenance_filepath = os .path .join (temp_path , prov_asset .name )
411
+ provenance_filepath = os .path .join (download_path , prov_asset .name )
509
412
510
- if not ci_service .api_client .download_asset (
511
- prov_asset .url ,
512
- provenance_filepath ,
513
- ):
514
- logger .debug (
515
- "Could not download the provenance %s. Skip verifying..." ,
516
- prov_asset .name ,
517
- )
518
- continue
413
+ if not ci_service .api_client .download_asset (
414
+ prov_asset .url ,
415
+ provenance_filepath ,
416
+ ):
417
+ logger .debug (
418
+ "Could not download the provenance %s. Skip verifying..." ,
419
+ prov_asset .name ,
420
+ )
421
+ continue
519
422
520
- # Read the provenance.
521
- try :
522
- payload = load_provenance_payload (provenance_filepath )
523
- except LoadIntotoAttestationError as error :
524
- logger .error ("Error logging provenance: %s" , error )
525
- continue
423
+ # Read the provenance.
424
+ try :
425
+ payload = load_provenance_payload (provenance_filepath )
426
+ except LoadIntotoAttestationError as error :
427
+ logger .error ("Error logging provenance: %s" , error )
428
+ continue
526
429
527
- # Add the provenance file.
528
- downloaded_provs .append (SLSAProvenanceData (payload = payload , asset = prov_asset ))
430
+ # Add the provenance file.
431
+ downloaded_provs .append (SLSAProvenanceData (payload = payload , asset = prov_asset ))
529
432
530
- # Persist the provenance payloads into the CIInfo object.
531
- ci_info ["provenances" ] = downloaded_provs
433
+ # Persist the provenance payloads into the CIInfo object.
434
+ ci_info ["provenances" ] = downloaded_provs
532
435
except OSError as error :
533
436
logger .error ("Error while storing provenance in the temporary directory: %s" , error )
0 commit comments