Skip to content

Commit e4b6106

Browse files
committed
[red] Reject Python cache contaminated source evidence
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent c13548d commit e4b6106

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

‎docs/specifications/firmware/TDD.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,10 @@ PBLE/1 **conformance** tests run against an **in-memory fake transport** shared
11551155
toolchain-distribution license bytes from the trusted ESP-IDF download cache,
11561156
exact metadata/cache/install binding with distinct archive and version roots,
11571157
absence of host-absolute paths in receipts, and profile-specific zero-input
1158-
not-shipped proof.
1158+
not-shipped proof. Supplemental source-tree digests exclude Python bytecode
1159+
cache artifacts while the audit rejects any such artifacts in the retained
1160+
checkout; release builds force bytecode generation off so checkout-local
1161+
absolute paths cannot contaminate otherwise identical source evidence.
11591162
- **size:** enforce the total application-image ceiling and derived
11601163
factory-partition headroom floor during build/candidate validation. Continue
11611164
structural application-fit checks on all three source targets, including

‎tests/firmware_tests/host/test_release_hardening.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def __init__(self):
746746
done
747747
printf '\n'
748748
} >> "$PYBLE_MAKE_LOG"
749-
printf '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n' \
749+
printf '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n' \
750750
"${CFLAGS_EXTRA-}" \
751751
"${EXTRA_CPPFLAGS-}" \
752752
"${CFLAGS-}" \
@@ -757,7 +757,8 @@ def __init__(self):
757757
"${MAKEFLAGS-}" \
758758
"${MFLAGS-}" \
759759
"${GNUMAKEFLAGS-}" \
760-
"${MAKEOVERRIDES-}" >> "$PYBLE_MAKE_ENV_LOG"
760+
"${MAKEOVERRIDES-}" \
761+
"${PYTHONDONTWRITEBYTECODE-}" >> "$PYBLE_MAKE_ENV_LOG"
761762
printf '%s\n' "${MICROPY_MPYCROSS-}" \
762763
>> "$PYBLE_MPY_CROSS_ENV_LOG"
763764
output=""
@@ -973,7 +974,7 @@ def test_port_build_uses_only_stable_source_prefix_maps(self):
973974
)
974975
environments = fixture.make_environments()
975976
self.assertEqual(
976-
environments[0],
977+
environments[0][:-1],
977978
("", "", "", "", "", "", "", "", "", "", ""),
978979
"ambient compiler flags must not influence the rebuilt compiler",
979980
)
@@ -1000,7 +1001,7 @@ def test_port_build_uses_only_stable_source_prefix_maps(self):
10001001
1,
10011002
)
10021003
self.assertEqual(
1003-
environments,
1004+
[environment[:-1] for environment in environments],
10041005
[("", "", "", "", "", "", "", "", "", "", "")] * 3,
10051006
"submodule configuration and the final application build must "
10061007
"share exact runner-owned path maps; ambient flags may not be "
@@ -1009,6 +1010,21 @@ def test_port_build_uses_only_stable_source_prefix_maps(self):
10091010
finally:
10101011
fixture.cleanup()
10111012

1013+
def test_build_disables_python_bytecode_cache_generation(self):
1014+
fixture = BuildScriptFixture()
1015+
try:
1016+
completed = fixture.build()
1017+
self.assertEqual(completed.returncode, 0, completed.stdout)
1018+
environments = fixture.make_environments()
1019+
self.assertTrue(environments)
1020+
self.assertEqual(
1021+
[environment[-1] for environment in environments],
1022+
["1"] * len(environments),
1023+
"every build phase must prevent checkout-local Python caches",
1024+
)
1025+
finally:
1026+
fixture.cleanup()
1027+
10121028
def test_port_build_reuses_the_explicitly_built_host_mpy_cross(self):
10131029
fixture = BuildScriptFixture()
10141030
try:

‎tests/firmware_tests/host/test_release_license_policy_v2_hardening.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,33 @@ def test_supplemental_relationship_is_exactly_depends_on(self):
461461
)
462462
self.assert_rejected()
463463

464+
def test_supplemental_source_hash_excludes_but_audit_rejects_python_caches(self):
465+
source_hash = RELEASE._audit_sha256_source_tree
466+
source_tree = self.fixture.mbedtls_tree
467+
expected = source_hash(source_tree)
468+
469+
cache = source_tree / "mbedcrypto" / "__pycache__" / "config.cpython-313.pyc"
470+
legacy_cache = source_tree / "mbedcrypto" / "legacy.pyc"
471+
cache.parent.mkdir(parents=True)
472+
cache.write_bytes(b"cache containing /first/checkout/path\n")
473+
legacy_cache.write_bytes(b"legacy cache containing /first/checkout/path\n")
474+
self.assertEqual(source_hash(source_tree), expected)
475+
cache.write_bytes(b"cache containing /second/checkout/path\n")
476+
legacy_cache.write_bytes(b"legacy cache containing /second/checkout/path\n")
477+
self.assertEqual(source_hash(source_tree), expected)
478+
self.assert_rejected()
479+
480+
cache.unlink()
481+
legacy_cache.unlink()
482+
cache.parent.rmdir()
483+
real_source = source_tree / "mbedcrypto" / "mbedcrypto.c"
484+
real_source.write_text(
485+
real_source.read_text(encoding="utf-8") + "// mutation\n",
486+
encoding="utf-8",
487+
)
488+
self.assertNotEqual(source_hash(source_tree), expected)
489+
self.assert_rejected()
490+
464491
def test_observed_input_with_symlink_ancestor_is_rejected(self):
465492
identifier = "core--esp32-4mb--application"
466493
observed = copy.deepcopy(self.fixture.observed_inputs)

0 commit comments

Comments
 (0)