Skip to content

Commit e0c3fec

Browse files
committed
chore: use maven hashes as reference only; add pypi integration test
Signed-off-by: Ben Selwyn-Smith <[email protected]>
1 parent ed82caa commit e0c3fec

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/macaron/slsa_analyzer/package_registry/maven_central_registry.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,16 @@ def get_artifact_hash(self, purl: PackageURL, hash_algorithm: Any) -> str | None
282282
if not file_name:
283283
return None
284284

285-
# Maven supports but does not require a sha256 hash of uploaded artifacts. Check that first.
285+
# Maven supports but does not require a sha256 hash of uploaded artifacts.
286286
artifact_url = self.registry_url + "/" + artifact_path + "/" + file_name
287287
sha256_url = artifact_url + ".sha256"
288288
logger.debug("Search for artifact hash using URL: %s", [sha256_url, artifact_url])
289289

290290
response = send_get_http_raw(sha256_url, {})
291-
if response and response.text:
292-
logger.debug("Found hash of artifact: %s", response.text)
293-
return response.text
291+
sha256_hash = None
292+
if response and (sha256_hash := response.text):
293+
# As Maven hashes are user provided and not verified they serve as a reference only.
294+
logger.debug("Found hash of artifact: %s", sha256_hash)
294295

295296
try:
296297
response = requests.get(artifact_url, stream=True, timeout=40)
@@ -313,5 +314,9 @@ def get_artifact_hash(self, purl: PackageURL, hash_algorithm: Any) -> str | None
313314
return None
314315

315316
artifact_hash: str = hash_algorithm.hexdigest()
317+
if sha256_hash and artifact_hash != sha256_hash:
318+
logger.debug("Artifact hash and discovered hash do not match: %s != %s", artifact_hash, sha256_hash)
319+
return None
320+
316321
logger.debug("Computed hash of artifact: %s", artifact_hash)
317322
return artifact_hash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Copyright (c) 2024 - 2025, Oracle and/or its affiliates. All rights reserved. */
2+
/* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. */
3+
4+
#include "prelude.dl"
5+
6+
Policy("test_policy", component_id, "") :-
7+
check_passed(component_id, "mcn_provenance_available_1").
8+
9+
apply_policy_to("test_policy", component_id) :-
10+
is_component(component_id, "pkg:pypi/[email protected]").
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 - 2025, Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
description: |
5+
Discovering attestation of a PyPI artifact on GitHub
6+
7+
tags:
8+
- macaron-python-package
9+
10+
steps:
11+
- name: Run macaron analyze
12+
kind: analyze
13+
options:
14+
command_args:
15+
- -purl
16+
- pkg:pypi/[email protected]
17+
- name: Run macaron verify-policy to verify passed/failed checks
18+
kind: verify
19+
options:
20+
policy: policy.dl

0 commit comments

Comments
 (0)