Skip to content

Commit ce02b68

Browse files
committed
[green] Stabilize supplemental source evidence
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent e4b6106 commit ce02b68

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎firmware/licenses/license-policy.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17094,7 +17094,7 @@
1709417094
"source": {
1709517095
"ref": "3.6.4@b5d87eaa6748b7a6fa70593178c08b4480e9b71e",
1709617096
"tree_path": "firmware/.esp-idf/components/mbedtls",
17097-
"tree_sha256": "0338a54ab75fa598cf77260998deb48879c326d8a785305e4d31f3e9b232a3cc",
17097+
"tree_sha256": "4366d742b5721fab1705ce58962558b25d08aa0176913e9466a3f02284d729b3",
1709817098
"url": "https://github.com/Mbed-TLS/mbedtls/tree/b5d87eaa6748b7a6fa70593178c08b4480e9b71e"
1709917099
},
1710017100
"source_spdx_expression": "(Apache-2.0 OR GPL-2.0-or-later)"

‎firmware/release-tools.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sha256 = "a1444a7f23740c44cacbce4845efb5cbcb08927878b6a3852c33a52d8b2b5da9"
1414
excluded_cves_path = "firmware/licenses/excluded-cves.yaml"
1515
excluded_cves_sha256 = "77c02542775c018c5f32c0dcb6e88050adb0e69dbcd95e84ad7be128e0f536e5"
1616
license_policy_path = "firmware/licenses/license-policy.json"
17-
license_policy_sha256 = "ea1077f5ea9d8986fa2d1522d1552508d64712e4e0e930f8837c2a19a60938a8"
17+
license_policy_sha256 = "f31f6c1b823e079ac15e810d9b982a30916f9c4670c3a6a2c2071fa166219a8f"
1818

1919
[[artifacts]]
2020
name = "esp-idf-sbom"

‎firmware/scripts/build.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
set -u
2424

25+
# Python helpers invoked by ESP-IDF must never write checkout-local bytecode.
26+
# Besides mutating the retained source tree, .pyc payloads embed host paths and
27+
# make otherwise identical license evidence depend on the checkout location.
28+
PYTHONDONTWRITEBYTECODE=1
29+
export PYTHONDONTWRITEBYTECODE
30+
2531
HERE="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd -P)"
2632
FW="$(cd "$HERE/.." && pwd -P)"
2733
REPO_ROOT="$(cd "$FW/.." && pwd -P)"

‎firmware/scripts/release_bundle.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,43 @@ def _audit_sha256_tree(path: Path) -> str:
24092409
return digest.hexdigest()
24102410

24112411

2412+
def _audit_python_cache_artifact(relative: Path) -> bool:
2413+
return "__pycache__" in relative.parts or relative.suffix.lower() in {
2414+
".pyc",
2415+
".pyo",
2416+
}
2417+
2418+
2419+
def _audit_sha256_source_tree(
2420+
path: Path,
2421+
*,
2422+
reject_python_cache: bool = False,
2423+
) -> str:
2424+
"""Hash source bytes canonically without host-generated Python caches."""
2425+
2426+
_require(path.is_dir(), "reviewed source tree is missing: %s" % path)
2427+
digest = hashlib.sha256()
2428+
for item in sorted(path.rglob("*")):
2429+
_require(not item.is_symlink(), "reviewed source tree contains a symlink")
2430+
if not item.is_file():
2431+
continue
2432+
relative_path = item.relative_to(path)
2433+
if _audit_python_cache_artifact(relative_path):
2434+
_require(
2435+
not reject_python_cache,
2436+
"reviewed source tree contains Python cache artifact: %s"
2437+
% relative_path.as_posix(),
2438+
)
2439+
continue
2440+
relative = relative_path.as_posix().encode("utf-8")
2441+
value = item.read_bytes()
2442+
digest.update(len(relative).to_bytes(8, "big"))
2443+
digest.update(relative)
2444+
digest.update(len(value).to_bytes(8, "big"))
2445+
digest.update(value)
2446+
return digest.hexdigest()
2447+
2448+
24122449
def _audit_artifact_requirements(artifact: dict[str, Any]) -> list[str]:
24132450
value = artifact.get("requires")
24142451
_require(isinstance(value, list), "locked artifact requires must be an array")
@@ -4145,7 +4182,7 @@ def _audit_v2_source(
41454182
path = repo_root / relative
41464183
_audit_no_symlink_components(repo_root, path, "%s source tree" % label)
41474184
_require(
4148-
_audit_sha256_tree(path) == digest,
4185+
_audit_sha256_source_tree(path, reject_python_cache=True) == digest,
41494186
"%s source tree changed" % label,
41504187
)
41514188
return copy.deepcopy(record)

0 commit comments

Comments
 (0)