From 7f5fd99d94de2aaf7f5460ccca9f2b020a056301 Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 00:46:41 +0530 Subject: [PATCH 01/25] build: pin Gradle distribution and stop logging generated env values --- android/gradle/wrapper/gradle-wrapper.properties | 1 + appcenter-pre-build.sh | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index d4081da476..a54add3199 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531 networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/appcenter-pre-build.sh b/appcenter-pre-build.sh index 6adc321a73..5ea1c45f04 100644 --- a/appcenter-pre-build.sh +++ b/appcenter-pre-build.sh @@ -4,5 +4,4 @@ ENV_WHITELIST=${ENV_WHITELIST:-"^RN_"} printf "Creating an .env file with the following whitelist:\n" printf "%s\n" $ENV_WHITELIST set | egrep -e $ENV_WHITELIST | sed 's/^RN_//g' > .env -printf "\n.env created with contents:\n\n" -cat .env \ No newline at end of file +printf "\n.env created.\n" From 32d42583d1de984e357dbd3e396bd4f2f708d0ea Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 00:46:46 +0530 Subject: [PATCH 02/25] docs: add Android payload comparison and reproducibility evidence --- reproducibility/README.md | 130 +++++++++++++++++++ scripts/compare-android-apks.py | 178 +++++++++++++++++++++++++++ scripts/test_compare_android_apks.py | 149 ++++++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 reproducibility/README.md create mode 100755 scripts/compare-android-apks.py create mode 100644 scripts/test_compare_android_apks.py diff --git a/reproducibility/README.md b/reproducibility/README.md new file mode 100644 index 0000000000..424766716d --- /dev/null +++ b/reproducibility/README.md @@ -0,0 +1,130 @@ +# Android reproducibility status + +This directory records the inputs needed to compare a Bitcoin Keeper Android +release with a build from its public source. The comparison tool in +[`scripts/compare-android-apks.py`](../scripts/compare-android-apks.py) is an +inspection aid. It is **not** a WalletScrutiny build script, and this repository +does not yet establish a reproducibility verdict for v2.6.3. + +## v2.6.3 reference and measured result + +The public source tag is [`v2.6.3`](https://github.com/KeeperCommunity/bitcoin-keeper/releases/tag/v2.6.3), +commit `872cbc4b16ddcb0a8f3b5b1d7ebcde28e06ed096`. The GitHub release APK +`Bitcoin_Keeper_v2.6.3.apk` has SHA-256 +`a20d934ebd80ece779d3c171c7906bb4aff010337989ec1b826cab55c50eba46`. +Its package is `io.hexawallet.bitcoinkeeper`, version `2.6.3`, version code +`626`. + +An isolated build of that tag with a placeholder production configuration and +the checked-in debug signing key produced a valid 2.6.3 APK. Its SHA-256 was +`cc4102251a11cbbfa104808adc4906a3a0e3b2efd9a14ab0785d66f5c9d5143b`. +Comparing uncompressed APK entries found **1,424 matching payload entries and +192 differences**: one manifest, one baseline profile, one Hermes bundle, five +DEX files, 56 native libraries, and 128 resources. The placeholder +configuration and different build environment can affect these files. This is +a diagnostic mismatch, not evidence that the published binary was built from +different source. The measured result and remaining work are tracked in +[#6097](https://github.com/KeeperCommunity/bitcoin-keeper/issues/6097). + +For an SDK 33, arm64-v8a, xxhdpi, English-only profile, the four official +Play-generated APKs were also retrieved and verified. All 42 corresponding +code entries (six DEX files, Hermes, and 35 arm64 libraries) match the GitHub +release APK byte for byte. This establishes published-channel code parity for +that profile, not a rebuild from public source. A rebuilt AAB and split-set +comparison are still needed. + +| Play split | SHA-256 | +| --- | --- | +| SDK 29+ base | `e384b966359aa4937bf4353316ddda471adf1e17f6bb08fe53f9945e8ea9bc1d` | +| arm64-v8a | `11740257e813455501301d5dc0f9870dc476e15947d912523e051d9a3400ab8c` | +| xxhdpi | `da3b93b89e98cff52bbea6c593fc26193139d53f400139ebd44ac51118f08195` | +| English | `a5cae92f6e9c2d725bcf8fc3ebcfb397573fda38e1413dde7e40c395430f0a73` | + +## Compare two APKs + +Run with Python 3 and no extra packages: + +```sh +python3 scripts/compare-android-apks.py published.apk rebuilt.apk > comparison.json +``` + +Exit code 0 means all **uncompressed ZIP file entries** match after the narrow +signing exceptions below. Exit code 1 means at least one payload difference; +exit code 2 means invalid input. JSON includes whole-APK SHA-256 hashes, entry +counts, and every changed, added, or removed file path. ZIP directory records, +compression, entry order, and APK v2/v3 signing blocks are outside this payload +comparison. The tool assumes its inputs are APKs; verify their signatures, +package names, and versions separately. + +The only exempt entries are root-level JAR/v1 signature material +(`META-INF/MANIFEST.MF`, `META-INF/*.SF`, `*.RSA`, `*.DSA`, `*.EC`) and Play's +root `stamp-cert-sha256`. Their differences still appear in +`ignored_signing_entries`. DEX, Hermes, native libraries, manifests, resource +tables and files, baseline profiles, other assets, and other `META-INF` files +remain comparison-critical. A payload match does not authenticate either +signer or prove that the APK came from the claimed source. + +Synthetic tests cover signing exceptions, each payload category, added and +removed files, duplicate ZIP paths, and CLI exit codes: + +```sh +python3 -m unittest scripts/test_compare_android_apks.py +``` + +Compare one APK with one APK. Google Play delivers APKs generated from an AAB; +a Play base split cannot be equated with a standalone GitHub APK. Play +verification needs the complete delivered split set and corresponding splits +from a rebuilt AAB, with transformations examined separately. + +## Inputs needed for an independent build + +The tagged production lane requires an ignored `.env.production`. Its exact +v2.6.3 contents are not public. Names-only inspection of the published APK +found 13 environment-derived fields in `BuildConfig`. `react-native-config` +embeds supplied environment values in Android build outputs, including fields +outside the app's TypeScript configuration object. Placeholder values cannot +support an exact payload verdict. Some fields appear credential-bearing and +require owner security review before public build inputs are released; do not +commit an unchecked production environment file. + +The source pins Gradle wrapper 8.14.3, Android Gradle Plugin 8.8.0, Android +SDK/target 36, Build Tools 35.0.0, NDK 27.1.12297006, and React Native +0.83.9. The locked Realm dependency requests CMake 3.22.1. The dependency +tree is recorded in `yarn.lock` and checked-in `patch-package` patches. The +successful diagnostic used Node +22.23.3, Yarn 1.22.22, and JDK 17.0.19; these are measured diagnostic inputs, +not a claim about the publisher's complete toolchain. A third-party recipe +still needs a digest-pinned Linux container image, exact JDK/Node/Yarn and SDK +package checksums, a fixed checkout and dependency layout, and verified build +commands. The Gradle wrapper now has a distribution checksum pin, but the +Android project has no dependency lock or verification metadata. The published +Hermes bundle contains a Node 25.9.0 +literal injected by `rn-nodeify` and a path through a sibling +`keeper-release-2.5.15/node_modules` directory. These historical build inputs +must be investigated; copying them into a future release recipe would not by +itself reproduce v2.6.3. Realm and Screens also have native executable/data +differences in the placeholder rebuild. + +For the Android-only path, the diagnostic installed JavaScript packages with +`yarn install --frozen-lockfile --ignore-scripts`, then ran the checked-in +`patch-package` patches and the Android `rn-nodeify` step before invoking +`./gradlew :app:assembleProductionRelease`. The root `setup.sh` cannot serve +as a Linux build recipe unchanged: it runs iOS CocoaPods and writes a macOS SDK +path. A future container recipe needs a Linux `local.properties`, the verified +production environment input, and a disposable signing identity. It should +also run `:app:bundleProductionRelease` for Play split comparisons. These +commands describe the diagnostic path; they are not a complete reproducible +build recipe. + +The release Fastlane lane validates time-sensitive store baselines and uploads +an AAB to Play. An independent verifier should build locally without store +access or upload. It can use a disposable signing key and compare payloads +while explicitly accounting for signing differences. A complete recipe must +then build the production APK and AAB under pinned tools and compare the +actual distributed artifacts. + +[WalletScrutiny's script rules](https://github.com/WalletScrutiny/WalletScrutinyCom/blob/master/docs/script_verifications.md) +require Docker, Podman, or Nix; a script ending in `build.sh`; a `--binary` +argument; and an adjacent `COMPARISON_RESULTS.yaml`. No such script or results +file is included here because the exact production input and complete +third-party build path have not yet been established. diff --git a/scripts/compare-android-apks.py b/scripts/compare-android-apks.py new file mode 100755 index 0000000000..e92f8fa7ca --- /dev/null +++ b/scripts/compare-android-apks.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python3 +"""Compare the uncompressed payload entries of two Android APKs. + +This is an inspection aid, not a WalletScrutiny build script or a Play attestation. +It never extracts archive entries to the filesystem. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +import hashlib +import json +from pathlib import Path +import re +import sys +import zipfile + + +CHUNK_SIZE = 1024 * 1024 +MAX_ENTRIES = 100_000 +MAX_ENTRY_BYTES = 2 * 1024**3 +MAX_TOTAL_BYTES = 4 * 1024**3 + +# APK Signature Scheme v2/v3 blocks are outside ZIP entries. These names cover +# only root-level JAR/v1 signature material plus Play's certificate stamp. +JAR_SIGNATURE = re.compile(r"^META-INF/[^/]+\.(?:SF|RSA|DSA|EC)$") +DEX_FILE = re.compile(r"(?:^|/)classes\d*\.dex$") + + +def is_signing_only(name: str) -> bool: + return ( + name == "META-INF/MANIFEST.MF" + or name == "stamp-cert-sha256" + or JAR_SIGNATURE.fullmatch(name) is not None + ) + + +def category(name: str) -> str: + if DEX_FILE.search(name) or name.endswith(".dex"): + return "dex" + if name.startswith("assets/dexopt/") and name.endswith((".prof", ".profm")): + return "baseline_profile" + if name.startswith("lib/") and name.endswith(".so"): + return "native_library" + if name.endswith((".jsbundle", ".bundle")) or ( + name.startswith("assets/") and name.endswith(".js") + ): + return "javascript_bundle" + if name == "AndroidManifest.xml": + return "manifest" + if name == "resources.arsc" or name.startswith("res/"): + return "resource" + if name.startswith("META-INF/"): + return "metadata" + if name.startswith("assets/"): + return "asset" + return "other" + + +def file_sha256(path: Path) -> str: + digest = hashlib.sha256() + with path.open("rb") as stream: + for chunk in iter(lambda: stream.read(CHUNK_SIZE), b""): + digest.update(chunk) + return digest.hexdigest() + + +def inspect_apk(path: Path) -> dict: + if not path.is_file(): + raise ValueError(f"Not a regular file: {path}") + + with zipfile.ZipFile(path) as archive: + infos = archive.infolist() + if len(infos) > MAX_ENTRIES: + raise ValueError(f"Too many ZIP entries in {path}: {len(infos)}") + + names = [info.filename for info in infos] + duplicates = sorted(name for name, count in Counter(names).items() if count > 1) + if duplicates: + raise ValueError(f"Duplicate ZIP entry names in {path}: {duplicates}") + + files = [info for info in infos if not info.is_dir()] + total_bytes = sum(info.file_size for info in files) + if total_bytes > MAX_TOTAL_BYTES: + raise ValueError(f"Declared uncompressed ZIP size exceeds limit in {path}") + + entries = {} + for info in files: + if info.file_size > MAX_ENTRY_BYTES: + raise ValueError(f"ZIP entry exceeds size limit in {path}: {info.filename}") + digest = hashlib.sha256() + measured = 0 + # Passing ZipInfo selects the exact entry; reading to EOF checks its CRC. + with archive.open(info) as stream: + for chunk in iter(lambda: stream.read(CHUNK_SIZE), b""): + measured += len(chunk) + if measured > MAX_ENTRY_BYTES: + raise ValueError(f"ZIP entry exceeds size limit in {path}: {info.filename}") + digest.update(chunk) + if measured != info.file_size: + raise ValueError(f"Incorrect ZIP entry size in {path}: {info.filename}") + entries[info.filename] = {"sha256": digest.hexdigest(), "size": measured} + + return { + "path": str(path.resolve()), + "apk_sha256": file_sha256(path), + "payload_entry_count": len(entries), + "entries": entries, + } + + +def compare(reference: dict, rebuilt: dict) -> dict: + reference_entries = reference["entries"] + rebuilt_entries = rebuilt["entries"] + differences = [] + ignored_signing_entries = [] + matching_payload_entries = 0 + + for name in sorted(reference_entries.keys() | rebuilt_entries.keys()): + before = reference_entries.get(name) + after = rebuilt_entries.get(name) + if before == after: + if not is_signing_only(name): + matching_payload_entries += 1 + continue + + status = ( + "only_reference" if after is None else + "only_rebuilt" if before is None else + "content_mismatch" + ) + detail = { + "path": name, + "status": status, + "category": "signing_only" if is_signing_only(name) else category(name), + "reference": before, + "rebuilt": after, + } + if is_signing_only(name): + ignored_signing_entries.append(detail) + else: + differences.append(detail) + + return { + "schema_version": 1, + "verdict": "match" if not differences else "mismatch", + "scope": "one APK versus one APK; uncompressed ZIP file entries", + "reference": {key: value for key, value in reference.items() if key != "entries"}, + "rebuilt": {key: value for key, value in rebuilt.items() if key != "entries"}, + "summary": { + "matching_payload_entries": matching_payload_entries, + "payload_differences": len(differences), + "ignored_signing_differences": len(ignored_signing_entries), + }, + "differences": differences, + "ignored_signing_entries": ignored_signing_entries, + } + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("reference_apk", type=Path, help="Published reference APK") + parser.add_argument("rebuilt_apk", type=Path, help="APK rebuilt from source") + args = parser.parse_args() + + try: + report = compare(inspect_apk(args.reference_apk), inspect_apk(args.rebuilt_apk)) + except (OSError, ValueError, RuntimeError, EOFError, NotImplementedError, zipfile.BadZipFile) as error: + report = {"schema_version": 1, "verdict": "invalid_input", "error": str(error)} + + json.dump(report, sys.stdout, indent=2, sort_keys=True) + sys.stdout.write("\n") + return {"match": 0, "mismatch": 1, "invalid_input": 2}[report["verdict"]] + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/test_compare_android_apks.py b/scripts/test_compare_android_apks.py new file mode 100644 index 0000000000..8841cf0092 --- /dev/null +++ b/scripts/test_compare_android_apks.py @@ -0,0 +1,149 @@ +"""Synthetic APK tests for the payload comparison aid.""" + +import contextlib +import importlib.util +import io +import json +from pathlib import Path +import sys +import tempfile +import unittest +from unittest.mock import patch +import warnings +import zipfile + + +spec = importlib.util.spec_from_file_location( + "compare_android_apks", Path(__file__).with_name("compare-android-apks.py") +) +comparator = importlib.util.module_from_spec(spec) +spec.loader.exec_module(comparator) + + +class ApkComparisonTests(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.directory = Path(temporary.name) + + def apk(self, name, entries, *, compression=zipfile.ZIP_STORED): + path = self.directory / name + with zipfile.ZipFile(path, "w", compression=compression) as archive: + for entry_name, content in entries.items(): + archive.writestr(entry_name, content) + return path + + def result(self, reference, rebuilt): + return comparator.compare( + comparator.inspect_apk(reference), comparator.inspect_apk(rebuilt) + ) + + def test_only_root_signing_material_is_excluded(self): + common = { + "classes.dex": b"same dex", + "META-INF/services/provider": b"same non-signing metadata", + } + reference = self.apk("published.apk", { + **common, + "META-INF/MANIFEST.MF": b"original manifest digest", + "META-INF/CERT.SF": b"original signature file", + "META-INF/CERT.RSA": b"original certificate", + "stamp-cert-sha256": b"original stamp", + }) + rebuilt = self.apk("rebuilt.apk", { + **common, + "META-INF/MANIFEST.MF": b"different manifest digest", + "META-INF/CERT.SF": b"different signature file", + "META-INF/CERT.RSA": b"different certificate", + "stamp-cert-sha256": b"different stamp", + }, compression=zipfile.ZIP_DEFLATED) + + result = self.result(reference, rebuilt) + self.assertEqual(result["verdict"], "match") + self.assertEqual(result["summary"], { + "matching_payload_entries": 2, + "payload_differences": 0, + "ignored_signing_differences": 4, + }) + self.assertNotEqual(result["reference"]["apk_sha256"], result["rebuilt"]["apk_sha256"]) + + def test_every_executable_and_resource_category_remains_critical(self): + entries = { + "AndroidManifest.xml": "manifest", + "resources.arsc": "resource", + "res/drawable/icon.png": "resource", + "classes.dex": "dex", + "assets/index.android.bundle": "javascript_bundle", + "lib/arm64-v8a/librealm.so": "native_library", + "assets/dexopt/baseline.prof": "baseline_profile", + "META-INF/com.android.tools.build.gradle/app-metadata.properties": "metadata", + } + reference = self.apk("published.apk", {name: b"old" for name in entries}) + rebuilt = self.apk("rebuilt.apk", {name: b"new" for name in entries}) + + result = self.result(reference, rebuilt) + self.assertEqual(result["verdict"], "mismatch") + self.assertEqual(result["summary"]["payload_differences"], len(entries)) + self.assertEqual(result["summary"]["ignored_signing_differences"], 0) + self.assertEqual( + {entry["path"]: entry["category"] for entry in result["differences"]}, + entries, + ) + self.assertTrue(all(entry["status"] == "content_mismatch" for entry in result["differences"])) + + def test_added_removed_and_nested_signature_named_entries_are_reported(self): + reference = self.apk("published.apk", { + "classes.dex": b"same", + "assets/META-INF/CERT.RSA": b"old nested asset", + "assets/retired.dat": b"removed", + }) + rebuilt = self.apk("rebuilt.apk", { + "classes.dex": b"same", + "assets/META-INF/CERT.RSA": b"new nested asset", + "assets/added.dat": b"added", + }) + + result = self.result(reference, rebuilt) + self.assertEqual(result["verdict"], "mismatch") + self.assertEqual(result["summary"]["matching_payload_entries"], 1) + self.assertEqual(result["summary"]["payload_differences"], 3) + self.assertEqual(result["ignored_signing_entries"], []) + self.assertEqual( + {entry["path"]: entry["status"] for entry in result["differences"]}, + { + "assets/META-INF/CERT.RSA": "content_mismatch", + "assets/retired.dat": "only_reference", + "assets/added.dat": "only_rebuilt", + }, + ) + + def test_duplicate_zip_paths_are_rejected(self): + path = self.directory / "duplicate.apk" + with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + with zipfile.ZipFile(path, "w") as archive: + archive.writestr("classes.dex", b"first") + archive.writestr("classes.dex", b"second") + with self.assertRaisesRegex(ValueError, "Duplicate ZIP entry names"): + comparator.inspect_apk(path) + + def test_cli_exit_codes_and_machine_readable_reports(self): + reference = self.apk("published.apk", {"classes.dex": b"same"}) + rebuilt = self.apk("rebuilt.apk", {"classes.dex": b"different"}) + invalid = self.directory / "invalid.apk" + invalid.write_bytes(b"not an APK") + + for candidate, expected_code, expected_verdict in ( + (reference, 0, "match"), + (rebuilt, 1, "mismatch"), + (invalid, 2, "invalid_input"), + ): + with self.subTest(candidate=candidate.name), patch.object( + sys, "argv", ["compare-android-apks.py", str(reference), str(candidate)] + ), contextlib.redirect_stdout(io.StringIO()) as output: + self.assertEqual(comparator.main(), expected_code) + self.assertEqual(json.loads(output.getvalue())["verdict"], expected_verdict) + + +if __name__ == "__main__": + unittest.main() From b7df207aff4ef75037c0d5c044e1cd9a02db61c7 Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 12:30:57 +0530 Subject: [PATCH 03/25] build: validate Android reproducibility inputs before release builds --- .github/workflows/test.yml | 3 + reproducibility/README.md | 34 ++++ reproducibility/android-inputs.json | 17 ++ reproducibility/test_verify_android_inputs.py | 74 +++++++ reproducibility/verify-android-inputs.py | 190 ++++++++++++++++++ 5 files changed, 318 insertions(+) create mode 100644 reproducibility/android-inputs.json create mode 100644 reproducibility/test_verify_android_inputs.py create mode 100644 reproducibility/verify-android-inputs.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5d6104f0ae..6ddc8b6716 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,3 +54,6 @@ jobs: - name: Run tests run: npm run test + + - name: Test Android reproducibility tools + run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py diff --git a/reproducibility/README.md b/reproducibility/README.md index 424766716d..975a5c613c 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -128,3 +128,37 @@ require Docker, Podman, or Nix; a script ending in `build.sh`; a `--binary` argument; and an adjacent `COMPARISON_RESULTS.yaml`. No such script or results file is included here because the exact production input and complete third-party build path have not yet been established. + +## Fail closed on future build inputs + +`android-inputs.json` pins the Node, Yarn, JDK, Gradle wrapper, lockfile, and +Android SDK package versions chosen for the next independent build attempt. +These are **chosen future inputs**, not a reconstruction of the v2.6.3 +publisher's environment. Before any production build, run: + +```sh +python3 reproducibility/verify-android-inputs.py \ + --source-commit \ + --env-file /path/to/reviewed/.env.production \ + --approved-env-names /path/to/reviewed/approved-env-names.txt \ + --android-sdk-root /path/to/android-sdk +``` + +The approved names file contains exactly one reviewed environment key per line +and no values. It must come from the release review. The checker rejects +missing or extra names, a dirty or wrong source checkout, changed dependency +hashes, mismatched tool versions, missing SDK packages, a symlinked +`node_modules` root, and links from dependencies to files outside the checkout. +It does not output environment values. A local dependency install is necessary; +linking to a sibling `node_modules` directory recreates an observed historical +build-path dependency and fails this check. + +This check does not yet pin the container image, Android command-line tools +download, Maven artifacts, or every transitive native input. It does not run +the build or compare a binary and is not a WalletScrutiny `build.sh`. The exact +production environment names and values still need release-owner review before +any public recipe or verdict. Run its focused tests with: + +```sh +python3 -m unittest reproducibility/test_verify_android_inputs.py +``` diff --git a/reproducibility/android-inputs.json b/reproducibility/android-inputs.json new file mode 100644 index 0000000000..ca7f711647 --- /dev/null +++ b/reproducibility/android-inputs.json @@ -0,0 +1,17 @@ +{ + "node": "22.23.3", + "yarn": "1.22.22", + "java": "17.0.19", + "yarn_lock_sha256": "b257e6d81f2850ca1c12ce3ddb559d39cd3113a51c09a9eb71ca11c81bf5a245", + "gradle_wrapper_jar_sha256": "0336f591bc0ec9aa0c9988929b93ecc916b3c1d52aed202c7381db144aa0ef15", + "gradle_distribution_sha256": "bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531", + "android_packages": { + "build-tools/35.0.0": "35.0.0", + "ndk/27.1.12297006": "27.1.12297006", + "cmake/3.22.1": "3.22.1" + }, + "android_platform": { + "path": "platforms/android-36", + "revision": "2" + } +} diff --git a/reproducibility/test_verify_android_inputs.py b/reproducibility/test_verify_android_inputs.py new file mode 100644 index 0000000000..35f206ab7b --- /dev/null +++ b/reproducibility/test_verify_android_inputs.py @@ -0,0 +1,74 @@ +import importlib.util +from pathlib import Path +import tempfile +import unittest + + +SCRIPT = Path(__file__).with_name("verify-android-inputs.py") +SPEC = importlib.util.spec_from_file_location("verify_android_inputs", SCRIPT) +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) + + +class AndroidInputTests(unittest.TestCase): + def test_unapproved_environment_name_is_rejected_without_value(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + env = root / ".env.production" + approved = root / "approved-env-names.txt" + env.write_text("ENVIRONMENT=production\nUNREVIEWED_TOKEN=private-example-value\n") + approved.write_text("ENVIRONMENT\n") + with self.assertRaises(MODULE.InputError) as caught: + MODULE.check_env_names(env, approved) + self.assertIn("UNREVIEWED_TOKEN", str(caught.exception)) + self.assertNotIn("private-example-value", str(caught.exception)) + + def test_missing_or_duplicate_approved_name_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + env = root / ".env.production" + approved = root / "approved-env-names.txt" + env.write_text("ENVIRONMENT=production\n") + approved.write_text("ENVIRONMENT\nRELAY\n") + with self.assertRaisesRegex(MODULE.InputError, "missing environment names: RELAY"): + MODULE.check_env_names(env, approved) + approved.write_text("ENVIRONMENT\nENVIRONMENT\n") + with self.assertRaisesRegex(MODULE.InputError, "duplicate approved name"): + MODULE.check_env_names(env, approved) + + def test_external_or_root_dependency_symlink_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + outside = root / "outside" + outside.mkdir() + dependencies = root / "checkout/node_modules" + dependencies.parent.mkdir() + dependencies.symlink_to(outside, target_is_directory=True) + with self.assertRaisesRegex(MODULE.InputError, "real directory"): + MODULE.check_local_dependencies(dependencies.parent) + dependencies.unlink() + dependencies.mkdir() + (dependencies / "escaped").symlink_to(outside, target_is_directory=True) + with self.assertRaisesRegex(MODULE.InputError, "outside this checkout"): + MODULE.check_local_dependencies(dependencies.parent) + + def test_internal_dependency_symlink_is_allowed(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + dependencies = root / "node_modules" + package = dependencies / "some-package" + package.mkdir(parents=True) + bin_directory = dependencies / ".bin" + bin_directory.mkdir() + (bin_directory / "some-package").symlink_to(package, target_is_directory=True) + MODULE.check_local_dependencies(root) + + def test_sdk_revision_accepts_android_property_spacing(self): + with tempfile.TemporaryDirectory() as temporary: + package = Path(temporary) + (package / "source.properties").write_text("Pkg.Revision = 3.22.1\n") + self.assertEqual(MODULE.sdk_revision(package), "3.22.1") + + +if __name__ == "__main__": + unittest.main() diff --git a/reproducibility/verify-android-inputs.py b/reproducibility/verify-android-inputs.py new file mode 100644 index 0000000000..914acf978f --- /dev/null +++ b/reproducibility/verify-android-inputs.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 +"""Fail closed on known path, configuration, and toolchain drift before an Android build. + +This is an input check, not a complete build recipe or reproducibility verdict. +Environment values are never printed or written to an output file. +""" + +import argparse +import hashlib +import json +import os +from pathlib import Path +import re +import subprocess +import sys + + +class InputError(Exception): + pass + + +KEY_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$") +ASSIGNMENT_RE = re.compile(r"^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=") + + +def sha256(path): + digest = hashlib.sha256() + with path.open("rb") as source: + for chunk in iter(lambda: source.read(1024 * 1024), b""): + digest.update(chunk) + return digest.hexdigest() + + +def read_env_names(path): + """Read only names; deliberately never retain or show the values.""" + names = set() + for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1): + stripped = line.strip() + if not stripped or stripped.startswith("#"): + continue + match = ASSIGNMENT_RE.match(stripped) + if not match: + raise InputError(f"invalid environment assignment at line {line_number}") + name = match.group(1) + if name in names: + raise InputError(f"duplicate environment name: {name}") + names.add(name) + return names + + +def read_approved_names(path): + names = set() + for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1): + name = line.strip() + if not name or name.startswith("#"): + continue + if not KEY_RE.fullmatch(name): + raise InputError(f"invalid approved name at line {line_number}") + if name in names: + raise InputError(f"duplicate approved name: {name}") + names.add(name) + if not names: + raise InputError("approved environment name list is empty") + return names + + +def check_env_names(env_file, approved_names_file): + actual = read_env_names(env_file) + approved = read_approved_names(approved_names_file) + unexpected = sorted(actual - approved) + missing = sorted(approved - actual) + if unexpected or missing: + parts = [] + if unexpected: + parts.append("unexpected environment names: " + ", ".join(unexpected)) + if missing: + parts.append("missing environment names: " + ", ".join(missing)) + raise InputError("; ".join(parts)) + + +def check_local_dependencies(repo): + dependencies = repo / "node_modules" + if dependencies.is_symlink() or not dependencies.is_dir(): + raise InputError("node_modules must be a real directory inside this checkout") + root = dependencies.resolve() + for current, directories, files in os.walk(dependencies, followlinks=False): + for name in directories + files: + path = Path(current) / name + if path.is_symlink(): + try: + target = path.resolve(strict=True) + except (OSError, RuntimeError): + raise InputError("node_modules contains a broken or cyclic symlink") from None + if not target.is_relative_to(root): + raise InputError("node_modules contains a symlink outside this checkout") + + +def run(*command, cwd=None): + try: + result = subprocess.run(command, cwd=cwd, check=True, capture_output=True, text=True) + except (OSError, subprocess.CalledProcessError): + raise InputError(f"cannot run required command: {command[0]}") from None + return result.stdout + result.stderr + + +def check_source(repo, commit): + if not re.fullmatch(r"[0-9a-f]{40}", commit): + raise InputError("expected source commit must be a full 40-character SHA") + actual = run("git", "rev-parse", "HEAD", cwd=repo).strip() + if actual != commit: + raise InputError("checkout HEAD differs from expected source commit") + if run("git", "status", "--porcelain=v1", "--untracked-files=normal", cwd=repo).strip(): + raise InputError("source checkout has uncommitted files") + + +def check_hash(path, expected, label): + if not path.is_file() or sha256(path) != expected: + raise InputError(f"{label} differs from the pinned hash") + + +def check_gradle_distribution(repo, expected): + wrapper = (repo / "android/gradle/wrapper/gradle-wrapper.properties").read_text(encoding="utf-8") + if f"distributionSha256Sum={expected}" not in wrapper.splitlines(): + raise InputError("Gradle distribution checksum differs from the pinned hash") + + +def sdk_revision(path): + properties = path / "source.properties" + if not properties.is_file(): + raise InputError(f"Android SDK package missing: {path.name}") + for line in properties.read_text(encoding="utf-8").splitlines(): + match = re.fullmatch(r"Pkg\.Revision\s*=\s*(\S+)\s*", line) + if match: + return match.group(1) + raise InputError(f"Android SDK package has no revision: {path.name}") + + +def check_toolchain(inputs, sdk_root): + node = run("node", "--version").strip().removeprefix("v") + yarn = run("yarn", "--version").strip() + java_output = run("java", "-XshowSettings:properties", "-version") + java_match = re.search(r"^\s*java\.version\s*=\s*(\S+)\s*$", java_output, re.MULTILINE) + if (node, yarn, java_match.group(1) if java_match else None) != ( + inputs["node"], inputs["yarn"], inputs["java"] + ): + raise InputError("Node, Yarn, or JDK version differs from pinned Android inputs") + for package, revision in inputs["android_packages"].items(): + if sdk_revision(sdk_root / package) != revision: + raise InputError(f"Android SDK package revision differs: {package}") + platform = inputs["android_platform"] + if sdk_revision(sdk_root / platform["path"]) != platform["revision"]: + raise InputError("Android platform revision differs from pinned Android inputs") + if not (sdk_root / platform["path"] / "android.jar").is_file(): + raise InputError("pinned Android platform is missing") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--repo", type=Path, default=Path(__file__).resolve().parent.parent) + parser.add_argument("--source-commit", required=True) + parser.add_argument("--env-file", type=Path, required=True) + parser.add_argument("--approved-env-names", type=Path, required=True) + parser.add_argument("--android-sdk-root", type=Path, default=None) + args = parser.parse_args() + repo = args.repo.resolve() + sdk_root = args.android_sdk_root or os.environ.get("ANDROID_HOME") or os.environ.get("ANDROID_SDK_ROOT") + if not sdk_root: + raise InputError("ANDROID_HOME or ANDROID_SDK_ROOT is required") + sdk_root = Path(sdk_root).resolve() + inputs = json.loads((repo / "reproducibility/android-inputs.json").read_text(encoding="utf-8")) + check_source(repo, args.source_commit) + check_hash(repo / "yarn.lock", inputs["yarn_lock_sha256"], "yarn.lock") + check_hash( + repo / "android/gradle/wrapper/gradle-wrapper.jar", + inputs["gradle_wrapper_jar_sha256"], + "Gradle wrapper JAR", + ) + check_gradle_distribution(repo, inputs["gradle_distribution_sha256"]) + check_local_dependencies(repo) + check_env_names(args.env_file, args.approved_env_names) + check_toolchain(inputs, sdk_root) + print("Android build inputs verified; this is not a reproducibility verdict.") + + +if __name__ == "__main__": + try: + main() + except (InputError, OSError, ValueError, KeyError, json.JSONDecodeError) as error: + print(f"Android input check failed: {error}", file=sys.stderr) + sys.exit(1) From 19b3e2070112c12dd1161f5c3a902d36a7bcaf0e Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 12:35:41 +0530 Subject: [PATCH 04/25] build: track provisional Android environment name allowlist --- reproducibility/README.md | 8 ++++--- reproducibility/android-inputs.json | 11 ++++++++- reproducibility/test_verify_android_inputs.py | 13 ++++------ reproducibility/verify-android-inputs.py | 24 ++++++++----------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/reproducibility/README.md b/reproducibility/README.md index 975a5c613c..6e92902d53 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -140,12 +140,14 @@ publisher's environment. Before any production build, run: python3 reproducibility/verify-android-inputs.py \ --source-commit \ --env-file /path/to/reviewed/.env.production \ - --approved-env-names /path/to/reviewed/approved-env-names.txt \ --android-sdk-root /path/to/android-sdk ``` -The approved names file contains exactly one reviewed environment key per line -and no values. It must come from the release review. The checker rejects +The tracked manifest contains seven source-audited environment names and no +values. This is a **provisional future-release allowlist**: the GasFree pause +in draft PR #7037 and integration checks for four candidate omissions must be +reviewed before using it for a release. Changing the list requires a tracked +source change. The checker rejects missing or extra names, a dirty or wrong source checkout, changed dependency hashes, mismatched tool versions, missing SDK packages, a symlinked `node_modules` root, and links from dependencies to files outside the checkout. diff --git a/reproducibility/android-inputs.json b/reproducibility/android-inputs.json index ca7f711647..14c9bfc290 100644 --- a/reproducibility/android-inputs.json +++ b/reproducibility/android-inputs.json @@ -13,5 +13,14 @@ "android_platform": { "path": "platforms/android-36", "revision": "2" - } + }, + "environment_names": [ + "CHANNEL_URL", + "ENVIRONMENT", + "HEXA_ID_MAINNET", + "HEXA_ID_TESTNET", + "RELAY", + "SIGNING_SERVER_MAINNET", + "SIGNING_SERVER_TESTNET" + ] } diff --git a/reproducibility/test_verify_android_inputs.py b/reproducibility/test_verify_android_inputs.py index 35f206ab7b..ad629ccd4b 100644 --- a/reproducibility/test_verify_android_inputs.py +++ b/reproducibility/test_verify_android_inputs.py @@ -15,11 +15,9 @@ def test_unapproved_environment_name_is_rejected_without_value(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) env = root / ".env.production" - approved = root / "approved-env-names.txt" env.write_text("ENVIRONMENT=production\nUNREVIEWED_TOKEN=private-example-value\n") - approved.write_text("ENVIRONMENT\n") with self.assertRaises(MODULE.InputError) as caught: - MODULE.check_env_names(env, approved) + MODULE.check_env_names(env, ["ENVIRONMENT"]) self.assertIn("UNREVIEWED_TOKEN", str(caught.exception)) self.assertNotIn("private-example-value", str(caught.exception)) @@ -27,14 +25,11 @@ def test_missing_or_duplicate_approved_name_is_rejected(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) env = root / ".env.production" - approved = root / "approved-env-names.txt" env.write_text("ENVIRONMENT=production\n") - approved.write_text("ENVIRONMENT\nRELAY\n") with self.assertRaisesRegex(MODULE.InputError, "missing environment names: RELAY"): - MODULE.check_env_names(env, approved) - approved.write_text("ENVIRONMENT\nENVIRONMENT\n") - with self.assertRaisesRegex(MODULE.InputError, "duplicate approved name"): - MODULE.check_env_names(env, approved) + MODULE.check_env_names(env, ["ENVIRONMENT", "RELAY"]) + with self.assertRaisesRegex(MODULE.InputError, "duplicate pinned environment name"): + MODULE.check_env_names(env, ["ENVIRONMENT", "ENVIRONMENT"]) def test_external_or_root_dependency_symlink_is_rejected(self): with tempfile.TemporaryDirectory() as temporary: diff --git a/reproducibility/verify-android-inputs.py b/reproducibility/verify-android-inputs.py index 914acf978f..08e0fcc775 100644 --- a/reproducibility/verify-android-inputs.py +++ b/reproducibility/verify-android-inputs.py @@ -48,25 +48,22 @@ def read_env_names(path): return names -def read_approved_names(path): +def expected_env_names(expected): + if not isinstance(expected, list) or not expected: + raise InputError("pinned environment name list is missing or empty") names = set() - for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1): - name = line.strip() - if not name or name.startswith("#"): - continue - if not KEY_RE.fullmatch(name): - raise InputError(f"invalid approved name at line {line_number}") + for name in expected: + if not isinstance(name, str) or not KEY_RE.fullmatch(name): + raise InputError("invalid pinned environment name") if name in names: - raise InputError(f"duplicate approved name: {name}") + raise InputError(f"duplicate pinned environment name: {name}") names.add(name) - if not names: - raise InputError("approved environment name list is empty") return names -def check_env_names(env_file, approved_names_file): +def check_env_names(env_file, expected_names): actual = read_env_names(env_file) - approved = read_approved_names(approved_names_file) + approved = expected_env_names(expected_names) unexpected = sorted(actual - approved) missing = sorted(approved - actual) if unexpected or missing: @@ -159,7 +156,6 @@ def main(): parser.add_argument("--repo", type=Path, default=Path(__file__).resolve().parent.parent) parser.add_argument("--source-commit", required=True) parser.add_argument("--env-file", type=Path, required=True) - parser.add_argument("--approved-env-names", type=Path, required=True) parser.add_argument("--android-sdk-root", type=Path, default=None) args = parser.parse_args() repo = args.repo.resolve() @@ -177,7 +173,7 @@ def main(): ) check_gradle_distribution(repo, inputs["gradle_distribution_sha256"]) check_local_dependencies(repo) - check_env_names(args.env_file, args.approved_env_names) + check_env_names(args.env_file, inputs["environment_names"]) check_toolchain(inputs, sdk_root) print("Android build inputs verified; this is not a reproducibility verdict.") From 43921065c5277071354188ee71638204b191bd84 Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 21:59:08 +0530 Subject: [PATCH 05/25] reproducibility: audit public APK build values without disclosure --- reproducibility/README.md | 36 ++++ reproducibility/audit-apk-build-values.py | 196 ++++++++++++++++++ .../test_audit_apk_build_values.py | 133 ++++++++++++ 3 files changed, 365 insertions(+) create mode 100644 reproducibility/audit-apk-build-values.py create mode 100644 reproducibility/test_audit_apk_build_values.py diff --git a/reproducibility/README.md b/reproducibility/README.md index 6e92902d53..db9170b135 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -123,6 +123,42 @@ while explicitly accounting for signing differences. A complete recipe must then build the production APK and AAB under pinned tools and compare the actual distributed artifacts. +## Check the seven future build values against a public APK + +The seven names in `android-inputs.json` are already present as string +resources in the authenticated public v2.6.3 APK. The +[`audit-apk-build-values.py`](audit-apk-build-values.py) tool checks that an +APK matches a supplied SHA-256, that each of those seven fields has one plain +production value, and optionally that a seven-field candidate `.env` file +matches them exactly. It prints field names on a mismatch but never prints, +exports, or writes their values. It ignores all other historical APK fields, +including old credential-bearing fields. Keep any candidate environment file +outside Git. + +The expected digest must come from a trusted release check, not from the same +untrusted APK being inspected. For the PGP-verified +[v2.6.3 GitHub release APK](https://github.com/KeeperCommunity/bitcoin-keeper/releases/tag/v2.6.3), +run: + +```sh +python3 reproducibility/audit-apk-build-values.py \ + --apk /path/to/Bitcoin_Keeper_v2.6.3.apk \ + --expected-apk-sha256 a20d934ebd80ece779d3c171c7906bb4aff010337989ec1b826cab55c50eba46 \ + --aapt2 /path/to/android-sdk/build-tools/35.0.0/aapt2 \ + --env-file /path/outside/repository/to/candidate.env +``` + +Omit `--env-file` to check APK field presence only. Candidate entries must be +simple `KEY=value` lines with exactly the seven approved names. A mismatch can +indicate an intentional endpoint or identifier change; the release engineer +must confirm it before using that candidate. This check neither reconstructs +the complete historical v2.6.3 `.env.production` nor proves that a release was +built from public source. Run its focused tests with: + +```sh +python3 -m unittest reproducibility/test_audit_apk_build_values.py +``` + [WalletScrutiny's script rules](https://github.com/WalletScrutiny/WalletScrutinyCom/blob/master/docs/script_verifications.md) require Docker, Podman, or Nix; a script ending in `build.sh`; a `--binary` argument; and an adjacent `COMPARISON_RESULTS.yaml`. No such script or results diff --git a/reproducibility/audit-apk-build-values.py b/reproducibility/audit-apk-build-values.py new file mode 100644 index 0000000000..dc3caa0a11 --- /dev/null +++ b/reproducibility/audit-apk-build-values.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python3 +"""Check the seven public Android build inputs against an authenticated APK. + +Values stay in memory. Neither successful results nor errors print or write them. +This is a configuration audit, not a source reproducibility verdict. +""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path +import re +import shutil +import subprocess +import sys +from urllib.parse import urlsplit + + +FIELDS = ( + "CHANNEL_URL", + "ENVIRONMENT", + "HEXA_ID_MAINNET", + "HEXA_ID_TESTNET", + "RELAY", + "SIGNING_SERVER_MAINNET", + "SIGNING_SERVER_TESTNET", +) +FIELD_SET = set(FIELDS) +NAME_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$") +SHA256_RE = re.compile(r"^[0-9a-fA-F]{64}$") +RESOURCE_RE = re.compile(r"^\s*resource\s+0x[0-9a-fA-F]+\s+string/([A-Za-z_][A-Za-z0-9_]*)\s*$") +ANY_RESOURCE_RE = re.compile(r"^\s*resource\s+0x[0-9a-fA-F]+\s+") +DEFAULT_VALUE_RE = re.compile(r'^\s*\((?:default)?\)\s+"([^"\\]*)"\s*$') +ASSIGNMENT_RE = re.compile(r"^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(\S+)\s*$") + + +class AuditError(Exception): + """An error whose message contains no build value.""" + + +def check_tracked_allowlist() -> None: + manifest = Path(__file__).with_name("android-inputs.json") + try: + inputs = json.loads(manifest.read_text(encoding="utf-8")) + except (OSError, UnicodeError, ValueError): + raise AuditError("cannot read the tracked Android input manifest") from None + if inputs.get("environment_names") != list(FIELDS): + raise AuditError("audited field names differ from the tracked Android allowlist") + + +def sha256(path: Path) -> str: + digest = hashlib.sha256() + with path.open("rb") as source: + for chunk in iter(lambda: source.read(1024 * 1024), b""): + digest.update(chunk) + return digest.hexdigest() + + +def verify_apk_hash(path: Path, expected: str) -> None: + if not SHA256_RE.fullmatch(expected): + raise AuditError("expected APK SHA-256 must have 64 hex characters") + try: + if not path.is_file() or sha256(path) != expected.lower(): + raise AuditError("APK does not match the expected SHA-256") + except OSError: + raise AuditError("cannot read APK") from None + + +def run_aapt2(aapt2: str, apk: Path) -> str: + try: + result = subprocess.run( + [aapt2, "dump", "resources", str(apk)], + capture_output=True, + text=True, + check=False, + ) + except (OSError, UnicodeError): + raise AuditError("could not inspect APK resources with aapt2") from None + if result.returncode != 0: + # aapt2 output can contain APK data, so never echo stdout or stderr. + raise AuditError("aapt2 could not inspect APK resources") + return result.stdout + + +def validate_field(name: str, value: str) -> None: + if not value or any(char.isspace() for char in value): + raise AuditError(f"APK field has an unsupported value: {name}") + if name == "ENVIRONMENT": + if value != "PRODUCTION": + raise AuditError("APK environment is not production") + elif name.startswith("HEXA_ID_"): + if not re.fullmatch(r"[0-9a-fA-F]{64}", value): + raise AuditError(f"APK field is not a 64-character identifier: {name}") + else: + try: + parsed = urlsplit(value) + valid = parsed.scheme == "https" and bool(parsed.hostname) + valid = valid and not parsed.username and not parsed.password + valid = valid and not parsed.query and not parsed.fragment + except ValueError: + valid = False + if not valid: + raise AuditError(f"APK field is not a simple HTTPS URL: {name}") + + +def read_apk_fields(resource_dump: str) -> dict[str, str]: + lines = resource_dump.splitlines() + positions: dict[str, list[int]] = {name: [] for name in FIELDS} + for index, line in enumerate(lines): + match = RESOURCE_RE.fullmatch(line) + if match and match.group(1) in positions: + positions[match.group(1)].append(index) + + values = {} + for name in FIELDS: + found = positions[name] + if len(found) != 1: + raise AuditError(f"APK must contain exactly one string resource named {name}") + start = found[0] + 1 + end = next( + (index for index in range(start, len(lines)) if ANY_RESOURCE_RE.match(lines[index])), + len(lines), + ) + defaults = [ + match.group(1) + for line in lines[start:end] + if (match := DEFAULT_VALUE_RE.fullmatch(line)) + ] + if len(defaults) != 1: + raise AuditError(f"APK must contain one plain default value for {name}") + validate_field(name, defaults[0]) + values[name] = defaults[0] + return values + + +def read_candidate_env(path: Path) -> dict[str, str]: + try: + lines = path.read_text(encoding="utf-8").splitlines() + except (OSError, UnicodeError): + raise AuditError("cannot read candidate environment file") from None + values = {} + for number, line in enumerate(lines, 1): + stripped = line.strip() + if not stripped or stripped.startswith("#"): + continue + match = ASSIGNMENT_RE.fullmatch(stripped) + if not match: + raise AuditError(f"candidate environment line {number} must be simple KEY=value") + name, value = match.groups() + if not NAME_RE.fullmatch(name): + raise AuditError(f"candidate environment line {number} has an invalid name") + if name in values: + raise AuditError(f"duplicate candidate environment name at line {number}") + values[name] = value + return values + + +def compare_fields(apk_fields: dict[str, str], candidate: dict[str, str]) -> list[str]: + if set(apk_fields) != FIELD_SET: + raise AuditError("APK field set is incomplete") + if set(candidate) != FIELD_SET: + raise AuditError("candidate environment must contain exactly the seven audited names") + return [name for name in FIELDS if apk_fields[name] != candidate[name]] + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--apk", type=Path, required=True) + parser.add_argument("--expected-apk-sha256", required=True) + parser.add_argument("--env-file", type=Path, help="optional seven-field candidate environment") + parser.add_argument("--aapt2", default=shutil.which("aapt2")) + args = parser.parse_args() + if not args.aapt2: + raise AuditError("aapt2 is required; pass --aapt2 or add it to PATH") + check_tracked_allowlist() + verify_apk_hash(args.apk, args.expected_apk_sha256) + apk_fields = read_apk_fields(run_aapt2(args.aapt2, args.apk)) + print("APK matches the supplied SHA-256 and contains all seven audited build fields.") + if args.env_file: + different = compare_fields(apk_fields, read_candidate_env(args.env_file)) + if different: + print("Candidate differs from APK for: " + ", ".join(different)) + return 1 + print("Candidate environment matches the APK for all seven fields.") + print("This is a value audit, not a source reproducibility verdict.") + return 0 + + +if __name__ == "__main__": + try: + sys.exit(main()) + except AuditError as error: + print(f"Android build value audit failed: {error}", file=sys.stderr) + sys.exit(2) diff --git a/reproducibility/test_audit_apk_build_values.py b/reproducibility/test_audit_apk_build_values.py new file mode 100644 index 0000000000..ac8614537e --- /dev/null +++ b/reproducibility/test_audit_apk_build_values.py @@ -0,0 +1,133 @@ +import contextlib +import hashlib +import importlib.util +import io +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest +from unittest import mock + + +SCRIPT = Path(__file__).with_name("audit-apk-build-values.py") +SPEC = importlib.util.spec_from_file_location("audit_apk_build_values", SCRIPT) +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) + +VALUES = { + "CHANNEL_URL": "https://channel.example.test/", + "ENVIRONMENT": "PRODUCTION", + "HEXA_ID_MAINNET": "a" * 64, + "HEXA_ID_TESTNET": "b" * 64, + "RELAY": "https://relay.example.test/", + "SIGNING_SERVER_MAINNET": "https://sign.example.test/", + "SIGNING_SERVER_TESTNET": "https://test-sign.example.test/", +} +PRIVATE_FIXTURE = "never-print-this-fixture-value" + + +def resource_dump(values=VALUES): + rows = ["Package Group 0 id=0x7f package=io.example"] + for index, (name, value) in enumerate(values.items()): + rows.extend( + [f" resource 0x7f110{index:03x} string/{name}", f' () "{value}"'] + ) + rows.extend( + [" resource 0x7f110100 string/OTHER_FIELD", f' () "{PRIVATE_FIXTURE}"'] + ) + return "\n".join(rows) + + +class BuildValueAuditTests(unittest.TestCase): + def test_seven_audited_names_match_tracked_allowlist(self): + MODULE.check_tracked_allowlist() + + def test_apk_fields_and_candidate_match_without_other_resources(self): + actual = MODULE.read_apk_fields(resource_dump()) + self.assertEqual(actual, VALUES) + self.assertEqual(MODULE.compare_fields(actual, VALUES), []) + self.assertNotIn("OTHER_FIELD", actual) + + def test_apk_resource_missing_duplicate_or_ambiguous_is_rejected(self): + missing = {key: value for key, value in VALUES.items() if key != "RELAY"} + with self.assertRaisesRegex(MODULE.AuditError, "exactly one.*RELAY"): + MODULE.read_apk_fields(resource_dump(missing)) + duplicate = resource_dump() + '\n resource 0x7f110200 string/RELAY\n () "https://other.example.test/"' + with self.assertRaisesRegex(MODULE.AuditError, "exactly one.*RELAY"): + MODULE.read_apk_fields(duplicate) + ambiguous = resource_dump().replace( + ' () "https://relay.example.test/"', + ' () "https://relay.example.test/"\n () "https://other.example.test/"', + ) + with self.assertRaisesRegex(MODULE.AuditError, "one plain default value for RELAY"): + MODULE.read_apk_fields(ambiguous) + + def test_apk_values_must_have_expected_noncredential_shapes(self): + for name, value in ( + ("ENVIRONMENT", "DEVELOPMENT"), + ("HEXA_ID_MAINNET", "not-an-id"), + ("CHANNEL_URL", "http://channel.example.test/"), + ): + with self.subTest(name=name): + changed = dict(VALUES) + changed[name] = value + with self.assertRaises(MODULE.AuditError): + MODULE.read_apk_fields(resource_dump(changed)) + + def test_candidate_env_accepts_simple_values_and_rejects_extras(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "candidate.env" + path.write_text("# reviewed\n" + "\n".join(f"{k}={v}" for k, v in VALUES.items())) + self.assertEqual(MODULE.read_candidate_env(path), VALUES) + path.write_text(path.read_text() + "\nUNEXPECTED_CREDENTIAL=" + PRIVATE_FIXTURE) + candidate = MODULE.read_candidate_env(path) + with self.assertRaises(MODULE.AuditError) as caught: + MODULE.compare_fields(VALUES, candidate) + self.assertNotIn(PRIVATE_FIXTURE, str(caught.exception)) + self.assertNotIn("UNEXPECTED_CREDENTIAL", str(caught.exception)) + + def test_candidate_mismatch_reports_name_only_even_via_cli(self): + with tempfile.TemporaryDirectory() as directory: + apk = Path(directory) / "official.apk" + apk.write_bytes(b"synthetic APK identity") + expected_hash = hashlib.sha256(apk.read_bytes()).hexdigest() + env = Path(directory) / "candidate.env" + changed = dict(VALUES) + changed["RELAY"] = "https://different.example.test/" + env.write_text("\n".join(f"{k}={v}" for k, v in changed.items())) + stdout = io.StringIO() + stderr = io.StringIO() + args = [ + str(SCRIPT), "--apk", str(apk), "--expected-apk-sha256", expected_hash, + "--aapt2", "fixture-aapt2", "--env-file", str(env), + ] + with mock.patch.object(sys, "argv", args), mock.patch.object( + MODULE, "run_aapt2", return_value=resource_dump() + ), contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr): + self.assertEqual(MODULE.main(), 1) + output = stdout.getvalue() + stderr.getvalue() + self.assertIn("RELAY", output) + self.assertNotIn(changed["RELAY"], output) + self.assertNotIn(VALUES["RELAY"], output) + self.assertNotIn(PRIVATE_FIXTURE, output) + + def test_apk_digest_mismatch_is_rejected_before_resource_parsing(self): + with tempfile.TemporaryDirectory() as directory: + apk = Path(directory) / "untrusted.apk" + apk.write_bytes(b"fixture") + with self.assertRaisesRegex(MODULE.AuditError, "SHA-256"): + MODULE.verify_apk_hash(apk, "0" * 64) + + def test_aapt2_failure_never_echoes_its_output(self): + failed = subprocess.CompletedProcess( + ["aapt2"], 1, stdout=PRIVATE_FIXTURE, stderr=PRIVATE_FIXTURE + ) + with mock.patch.object(MODULE.subprocess, "run", return_value=failed): + with self.assertRaises(MODULE.AuditError) as caught: + MODULE.run_aapt2("aapt2", Path("official.apk")) + self.assertNotIn(PRIVATE_FIXTURE, str(caught.exception)) + + +if __name__ == "__main__": + unittest.main() From a862025dcafb6c5a90ee5076253752a5d751bc46 Mon Sep 17 00:00:00 2001 From: Anant Date: Thu, 8 Oct 2026 22:06:54 +0530 Subject: [PATCH 06/25] build: add containerized Android diagnostic recipe --- .../android-independent-diagnostic.yml | 38 ++++++++ reproducibility/Dockerfile.android-diagnostic | 48 +++++++++ reproducibility/README.md | 56 +++++++++-- .../android-diagnostic-in-container.sh | 92 ++++++++++++++++++ reproducibility/android-diagnostic.sh | 97 +++++++++++++++++++ 5 files changed, 323 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/android-independent-diagnostic.yml create mode 100644 reproducibility/Dockerfile.android-diagnostic create mode 100644 reproducibility/android-diagnostic-in-container.sh create mode 100644 reproducibility/android-diagnostic.sh diff --git a/.github/workflows/android-independent-diagnostic.yml b/.github/workflows/android-independent-diagnostic.yml new file mode 100644 index 0000000000..d7738f1a7c --- /dev/null +++ b/.github/workflows/android-independent-diagnostic.yml @@ -0,0 +1,38 @@ +name: Android independent diagnostic + +on: + push: + branches: + - 'codex/android-repro*' + pull_request: + branches: + - 'release/**' + - sprint + - dev + - main + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 120 + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Build diagnostic APK and AAB from a digest-pinned JDK base + run: | + bash reproducibility/android-diagnostic.sh \ + --source-commit "$GITHUB_SHA" \ + --output-dir "$RUNNER_TEMP/keeper-android-diagnostic" + + - name: Verify diagnostic output manifest + run: | + cd "$RUNNER_TEMP/keeper-android-diagnostic" + sha256sum --check SHA256SUMS + cat SHA256SUMS + test -s Bitcoin_Keeper_DIAGNOSTIC.apk + test -s Bitcoin_Keeper_DIAGNOSTIC.aab + echo 'Diagnostic build only; no distributed binary comparison or reproducibility verdict.' diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic new file mode 100644 index 0000000000..15d21fff6d --- /dev/null +++ b/reproducibility/Dockerfile.android-diagnostic @@ -0,0 +1,48 @@ +# Diagnostic Linux toolchain for an independent Android build attempt. +# This amd64 image digest is for eclipse-temurin:17.0.19_10-jdk-jammy. +# Pinning the base image does not yet pin Ubuntu apt or SDK Maven downloads. +FROM --platform=linux/amd64 eclipse-temurin:17.0.19_10-jdk-jammy@sha256:b76a309b3dfa907458b4ef428edfcfb37920a5ce0e9c6bc77798a54e039a8330 AS java-node-yarn + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates curl git python3 unzip xz-utils \ + && rm -rf /var/lib/apt/lists/* + +ARG NODE_VERSION=22.23.3 +ARG NODE_SHA256=df450af89261115ef9f9e3830c3eeb2cc9213b63c720b1af623cb5dcbe2e02de +ARG YARN_VERSION=1.22.22 +ARG YARN_SHA256=88268464199d1611fcf73ce9c0a6c4d44c7d5363682720d8506f6508addf36a0 + +RUN curl -LfsS "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -o /tmp/node.tar.xz \ + && echo "${NODE_SHA256} /tmp/node.tar.xz" | sha256sum -c - \ + && mkdir -p /opt/node \ + && tar -xJf /tmp/node.tar.xz -C /opt/node --strip-components=1 \ + && rm /tmp/node.tar.xz \ + && curl -LfsS "https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz" -o /tmp/yarn.tar.gz \ + && echo "${YARN_SHA256} /tmp/yarn.tar.gz" | sha256sum -c - \ + && mkdir -p /opt/yarn \ + && tar -xzf /tmp/yarn.tar.gz -C /opt/yarn --strip-components=1 \ + && rm /tmp/yarn.tar.gz + +FROM java-node-yarn AS android-sdk + +ARG COMMANDLINE_TOOLS_BUILD=13114758 +ARG COMMANDLINE_TOOLS_SHA256=7ec965280a073311c339e571cd5de778b9975026cfcbe79f2b1cdcb1e15317ee + +ENV ANDROID_SDK_ROOT=/opt/android-sdk \ + ANDROID_HOME=/opt/android-sdk \ + PATH=/opt/node/bin:/opt/yarn/bin:/opt/android-sdk/cmdline-tools/latest/bin:/opt/android-sdk/platform-tools:${PATH} + +RUN curl -LfsS "https://dl.google.com/android/repository/commandlinetools-linux-${COMMANDLINE_TOOLS_BUILD}_latest.zip" -o /tmp/android-commandline-tools.zip \ + && echo "${COMMANDLINE_TOOLS_SHA256} /tmp/android-commandline-tools.zip" | sha256sum -c - \ + && mkdir -p "${ANDROID_SDK_ROOT}/cmdline-tools" \ + && unzip -q /tmp/android-commandline-tools.zip -d "${ANDROID_SDK_ROOT}/cmdline-tools" \ + && mv "${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools" "${ANDROID_SDK_ROOT}/cmdline-tools/latest" \ + && rm /tmp/android-commandline-tools.zip \ + && sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" --licenses < <(yes) > /dev/null \ + && sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" \ + 'platforms;android-36' 'build-tools;35.0.0' \ + 'ndk;27.1.12297006' 'cmake;3.22.1' + +WORKDIR /workspace/keeper diff --git a/reproducibility/README.md b/reproducibility/README.md index db9170b135..584d3d18ed 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -6,6 +6,47 @@ release with a build from its public source. The comparison tool in inspection aid. It is **not** a WalletScrutiny build script, and this repository does not yet establish a reproducibility verdict for v2.6.3. +## Independent Linux diagnostic build + +[`android-diagnostic.sh`](android-diagnostic.sh) builds a production-flavor APK +and AAB in a disposable Linux container using deliberately invalid service +endpoints and the checked-in debug signing key. It needs Docker, a clean +checkout without `node_modules`, and an empty output directory outside the +checkout. Run it with the exact source commit you intend to inspect: + +```sh +bash reproducibility/android-diagnostic.sh \ + --source-commit "$(git rev-parse HEAD)" \ + --output-dir /tmp/keeper-android-diagnostic +``` + +The script records the toolchain image ID and writes only the diagnostic APK, +AAB, and their `SHA256SUMS` to the output directory. It never writes a +`COMPARISON_RESULTS.yaml` or reports a reproducibility verdict. Its CI workflow +builds on a clean Ubuntu runner when a `codex/android-repro*` branch is pushed +or a pull request targets a main development or release branch. No release +artifact is uploaded by that workflow. + +The container uses a digest-pinned **linux/amd64** Temurin JDK 17.0.19 base. +Node 22.23.3, Yarn 1.22.22, and Android command-line tools downloads have +checked SHA-256 hashes. The existing input checker then verifies the exact +Node, Yarn, Java, Android SDK package revisions, Gradle wrapper hash, lockfile +hash, environment **names**, and local dependency layout before Gradle builds. +Gradle and Yarn caches and Gradle's Maven-local home are isolated inside each +container run. The Android SDK packages are selected by version and checked by +revision, but their archive bytes are not yet pinned. Ubuntu apt packages, +Maven artifacts, and transitive native downloads also lack recorded hashes. +Those are remaining build-input gaps. The script is therefore an independent +**diagnostic build path**, not a final WalletScrutiny recipe. + +The placeholder configuration cannot establish whether a distributed APK or +Play split matches this source. The seven-name environment allowlist in +`android-inputs.json` remains provisional: this source still references +GasFree and exchange configuration, including `LETS_EXCHANGE_BASE_URL`, and +`react-native-config` can embed every supplied key. The actual release input +set must be reviewed before building for comparison. Do not substitute the +development defaults or treat this diagnostic APK as a usable release. + ## v2.6.3 reference and measured result The public source tag is [`v2.6.3`](https://github.com/KeeperCommunity/bitcoin-keeper/releases/tag/v2.6.3), @@ -161,9 +202,9 @@ python3 -m unittest reproducibility/test_audit_apk_build_values.py [WalletScrutiny's script rules](https://github.com/WalletScrutiny/WalletScrutinyCom/blob/master/docs/script_verifications.md) require Docker, Podman, or Nix; a script ending in `build.sh`; a `--binary` -argument; and an adjacent `COMPARISON_RESULTS.yaml`. No such script or results -file is included here because the exact production input and complete -third-party build path have not yet been established. +argument; and an adjacent `COMPARISON_RESULTS.yaml`. The diagnostic script +above intentionally has a different interface and no results file because the +exact production input and complete third-party comparison are not established. ## Fail closed on future build inputs @@ -179,11 +220,10 @@ python3 reproducibility/verify-android-inputs.py \ --android-sdk-root /path/to/android-sdk ``` -The tracked manifest contains seven source-audited environment names and no -values. This is a **provisional future-release allowlist**: the GasFree pause -in draft PR #7037 and integration checks for four candidate omissions must be -reviewed before using it for a release. Changing the list requires a tracked -source change. The checker rejects +The tracked manifest contains seven environment names and no values. This is a +**provisional future-release allowlist**: GasFree and exchange configuration +still exist in this source, and candidate omissions need review before using it +for a release. Changing the list requires a tracked source change. The checker rejects missing or extra names, a dirty or wrong source checkout, changed dependency hashes, mismatched tool versions, missing SDK packages, a symlinked `node_modules` root, and links from dependencies to files outside the checkout. diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh new file mode 100644 index 0000000000..685931be18 --- /dev/null +++ b/reproducibility/android-diagnostic-in-container.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo=/workspace/keeper +cd "$repo" +[[ -n ${KEEPER_SOURCE_COMMIT:-} ]] || { echo 'Expected source commit is missing.' >&2; exit 1; } +[[ $(git rev-parse HEAD) == "$KEEPER_SOURCE_COMMIT" ]] || { + echo 'Checkout HEAD differs from the requested source commit.' >&2 + exit 1 +} +[[ -z $(git status --porcelain=v1 --untracked-files=normal) ]] || { + echo 'Source checkout must be clean.' >&2 + exit 1 +} +[[ ! -e node_modules && ! -L node_modules ]] || { + echo 'This build needs an empty dependency tree.' >&2 + exit 1 +} + +assert_tracked_source_clean() { + if ! git diff --quiet -- . || ! git diff --cached --quiet -- .; then + echo 'Build tooling changed tracked source files.' >&2 + exit 1 + fi +} + +export GRADLE_USER_HOME=/tmp/keeper-gradle +export YARN_CACHE_FOLDER=/tmp/keeper-yarn +export ANDROID_USER_HOME=/tmp/keeper-android-user +export GRADLE_OPTS='-Duser.home=/tmp/keeper-user' +mkdir -p "$GRADLE_USER_HOME" "$YARN_CACHE_FOLDER" "$ANDROID_USER_HOME" \ + /tmp/keeper-user "$HOME" "$NPM_CONFIG_CACHE" "$XDG_CACHE_HOME" + +diagnostic_env=$(mktemp /tmp/keeper-diagnostic.XXXXXX) +trap 'rm -f "$diagnostic_env"' EXIT +cat > "$diagnostic_env" <<'EOF' +CHANNEL_URL=https://example.invalid/ +ENVIRONMENT=PRODUCTION +HEXA_ID_MAINNET=0000000000000000000000000000000000000000000000000000000000000000 +HEXA_ID_TESTNET=0000000000000000000000000000000000000000000000000000000000000000 +RELAY=https://example.invalid/ +SIGNING_SERVER_MAINNET=https://example.invalid/ +SIGNING_SERVER_TESTNET=https://example.invalid/ +EOF + +yarn install --frozen-lockfile --ignore-scripts --non-interactive +python3 reproducibility/verify-android-inputs.py \ + --source-commit "$KEEPER_SOURCE_COMMIT" \ + --env-file "$diagnostic_env" \ + --android-sdk-root "$ANDROID_SDK_ROOT" + +./node_modules/.bin/patch-package +./node_modules/.bin/rn-nodeify --install buffer,events,process,stream,inherits,path,assert,crypto --hack --yarn +assert_tracked_source_clean +printf 'sdk.dir=%s\n' "$ANDROID_SDK_ROOT" > android/local.properties + +export ENVFILE="$diagnostic_env" +export KEEPER_ANDROID_KEYSTORE="$repo/android/app/debug.keystore" +export STORE_PASSWORD=android +export KEY_ALIAS=androiddebugkey +export KEY_PASSWORD=android +( + cd android + ./gradlew :app:assembleProductionRelease :app:bundleProductionRelease --no-daemon --console=plain +) +assert_tracked_source_clean + +apk=android/app/build/outputs/apk/production/release/app-production-release.apk +aab=android/app/build/outputs/bundle/productionRelease/app-production-release.aab +test -s "$apk" +test -s "$aab" +"$ANDROID_SDK_ROOT/build-tools/35.0.0/apksigner" verify "$apk" +badging=$("$ANDROID_SDK_ROOT/build-tools/35.0.0/aapt2" dump badging "$apk") +version=$(node -p 'require("./release/version.json").version') +version_code=$(node -p 'require("./release/version.json").androidVersionCode') +grep -Fq "package: name='io.hexawallet.bitcoinkeeper' versionCode='$version_code' versionName='$version'" <<< "$badging" +jarsigner -verify -verbose -certs "$aab" > /tmp/keeper-aab-signature.log 2>&1 +grep -Fxq 'jar verified.' /tmp/keeper-aab-signature.log +if grep -Fq '? = unsigned entry' /tmp/keeper-aab-signature.log; then + echo 'Diagnostic AAB contains unsigned entries.' >&2 + exit 1 +fi +unzip -tq "$apk" >/dev/null +unzip -tq "$aab" >/dev/null + +cp "$apk" /output/Bitcoin_Keeper_DIAGNOSTIC.apk +cp "$aab" /output/Bitcoin_Keeper_DIAGNOSTIC.aab +( + cd /output + sha256sum Bitcoin_Keeper_DIAGNOSTIC.apk Bitcoin_Keeper_DIAGNOSTIC.aab > SHA256SUMS +) +echo 'Diagnostic APK/AAB built with placeholder values and debug signing; no reproducibility verdict.' diff --git a/reproducibility/android-diagnostic.sh b/reproducibility/android-diagnostic.sh new file mode 100644 index 0000000000..fa50c1bd6a --- /dev/null +++ b/reproducibility/android-diagnostic.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Build diagnostic APK/AAB with placeholder configuration in a Linux container. +# This script does not compare a published binary or report reproducibility. +set -euo pipefail + +usage() { + cat <<'EOF' +Usage: reproducibility/android-diagnostic.sh --source-commit SHA --output-dir DIR + +Builds a diagnostic Android APK and AAB with dummy service values and the +checked-in debug signing key. DIR must be outside the source checkout and empty. +Requires Docker and a clean, disposable source checkout with no node_modules. +EOF +} + +source_commit='' +output_dir='' +while (($#)); do + case "$1" in + --source-commit) + (($# >= 2)) || { usage >&2; exit 2; } + source_commit=$2 + shift 2 + ;; + --output-dir) + (($# >= 2)) || { usage >&2; exit 2; } + output_dir=$2 + shift 2 + ;; + --help|-h) + usage + exit 0 + ;; + *) + usage >&2 + exit 2 + ;; + esac +done + +[[ $source_commit =~ ^[0-9a-f]{40}$ && -n $output_dir ]] || { usage >&2; exit 2; } +command -v docker >/dev/null || { echo 'Docker is required.' >&2; exit 1; } + +repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +[[ $(git -C "$repo" rev-parse HEAD) == "$source_commit" ]] || { + echo 'Checkout HEAD differs from the requested source commit.' >&2 + exit 1 +} +[[ -z $(git -C "$repo" status --porcelain=v1 --untracked-files=normal) ]] || { + echo 'Source checkout must be clean.' >&2 + exit 1 +} +[[ ! -e "$repo/node_modules" && ! -L "$repo/node_modules" ]] || { + echo 'Use a disposable checkout without node_modules.' >&2 + exit 1 +} + +mkdir -p "$output_dir" +output_dir=$(cd "$output_dir" && pwd -P) +case "$output_dir/" in + "$repo/"*) echo 'Output directory must be outside the source checkout.' >&2; exit 1 ;; +esac +[[ -z $(find "$output_dir" -mindepth 1 -maxdepth 1 -print -quit) ]] || { + echo 'Output directory must be empty.' >&2 + exit 1 +} + +image="keeper-android-diagnostic:${source_commit:0:12}-$$" +docker build --platform linux/amd64 \ + -f "$repo/reproducibility/Dockerfile.android-diagnostic" \ + -t "$image" "$repo/reproducibility" + +# A Git worktree has a .git file pointing into its parent repository. Expose +# that metadata read-only at the same path so the input checker can verify HEAD. +git_common_dir=$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir) +git_mount=() +case "$git_common_dir/" in + "$repo/"*) ;; + *) git_mount=(--mount "type=bind,source=$git_common_dir,target=$git_common_dir,readonly") ;; +esac + +echo "Diagnostic source commit: $source_commit" +echo "Diagnostic toolchain image: $(docker image inspect --format '{{.Id}}' "$image")" +docker run --rm --platform linux/amd64 \ + --user "$(id -u):$(id -g)" \ + --mount "type=bind,source=$repo,target=/workspace/keeper" \ + --mount "type=bind,source=$output_dir,target=/output" \ + "${git_mount[@]}" \ + --env "KEEPER_SOURCE_COMMIT=$source_commit" \ + --env 'HOME=/tmp/keeper-home' \ + --env 'NPM_CONFIG_CACHE=/tmp/keeper-npm' \ + --env 'XDG_CACHE_HOME=/tmp/keeper-xdg-cache' \ + --env 'GIT_OPTIONAL_LOCKS=0' \ + --env 'GIT_CONFIG_COUNT=1' \ + --env 'GIT_CONFIG_KEY_0=safe.directory' \ + --env 'GIT_CONFIG_VALUE_0=/workspace/keeper' \ + "$image" bash /workspace/keeper/reproducibility/android-diagnostic-in-container.sh From 962e506947851cd27903ce425b14d8d56520b54e Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:03:38 +0530 Subject: [PATCH 07/25] fix: sign sprint diagnostic build with debug key --- .github/workflows/android-independent-diagnostic.yml | 4 ++++ reproducibility/android-diagnostic-in-container.sh | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android-independent-diagnostic.yml b/.github/workflows/android-independent-diagnostic.yml index d7738f1a7c..ffd750b944 100644 --- a/.github/workflows/android-independent-diagnostic.yml +++ b/.github/workflows/android-independent-diagnostic.yml @@ -14,6 +14,10 @@ on: permissions: contents: read +concurrency: + group: android-independent-${{ github.event.pull_request.head.ref || github.ref_name }} + cancel-in-progress: true + jobs: build: runs-on: ubuntu-24.04 diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh index 685931be18..4704ed95a3 100644 --- a/reproducibility/android-diagnostic-in-container.sh +++ b/reproducibility/android-diagnostic-in-container.sh @@ -55,13 +55,14 @@ assert_tracked_source_clean printf 'sdk.dir=%s\n' "$ANDROID_SDK_ROOT" > android/local.properties export ENVFILE="$diagnostic_env" -export KEEPER_ANDROID_KEYSTORE="$repo/android/app/debug.keystore" -export STORE_PASSWORD=android -export KEY_ALIAS=androiddebugkey -export KEY_PASSWORD=android ( cd android - ./gradlew :app:assembleProductionRelease :app:bundleProductionRelease --no-daemon --console=plain + ./gradlew :app:assembleProductionRelease :app:bundleProductionRelease \ + -PMYAPP_RELEASE_STORE_FILE="$repo/android/app/debug.keystore" \ + -PMYAPP_RELEASE_STORE_PASSWORD=android \ + -PMYAPP_RELEASE_KEY_ALIAS=androiddebugkey \ + -PMYAPP_RELEASE_KEY_PASSWORD=android \ + --no-daemon --console=plain ) assert_tracked_source_clean From cc15f593b62689267168a2405b318876c91947e0 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:09:07 +0530 Subject: [PATCH 08/25] ci: produce temporary sprint lockfile candidate --- .github/workflows/repro-lock-candidate.yml | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/repro-lock-candidate.yml diff --git a/.github/workflows/repro-lock-candidate.yml b/.github/workflows/repro-lock-candidate.yml new file mode 100644 index 0000000000..7bc78a97aa --- /dev/null +++ b/.github/workflows/repro-lock-candidate.yml @@ -0,0 +1,30 @@ +name: Repro lock candidate + +on: + push: + branches: + - codex/android-repro-independent-20261008 + +permissions: + contents: read + +jobs: + lock: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22.23.3 + - name: Resolve the sprint manifest with pinned Yarn + run: | + npm install --global yarn@1.22.22 + yarn install --ignore-scripts --non-interactive --no-progress + sha256sum yarn.lock + git diff --stat -- yarn.lock + - uses: actions/upload-artifact@v4 + with: + name: sprint-yarn-lock-candidate + path: yarn.lock + retention-days: 1 From 37986274ee0593ad55ed8d8ff5814306073cdbd6 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:15:14 +0530 Subject: [PATCH 09/25] ci: expose lockfile patch from clean runner --- .github/workflows/repro-lock-candidate.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/repro-lock-candidate.yml b/.github/workflows/repro-lock-candidate.yml index 7bc78a97aa..e3f61a2caa 100644 --- a/.github/workflows/repro-lock-candidate.yml +++ b/.github/workflows/repro-lock-candidate.yml @@ -23,6 +23,9 @@ jobs: yarn install --ignore-scripts --non-interactive --no-progress sha256sum yarn.lock git diff --stat -- yarn.lock + printf 'PATCH_DATA:' + git diff -- yarn.lock | base64 -w0 + printf '\n' - uses: actions/upload-artifact@v4 with: name: sprint-yarn-lock-candidate From a137db160446083ddb4e1e870bb2b021cf7cf302 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:19:47 +0530 Subject: [PATCH 10/25] fix: reconcile sprint lockfile and verify Android output version --- .github/workflows/repro-lock-candidate.yml | 33 ---- .../android-diagnostic-in-container.sh | 25 ++- reproducibility/android-inputs.json | 2 +- yarn.lock | 184 ++---------------- 4 files changed, 39 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/repro-lock-candidate.yml diff --git a/.github/workflows/repro-lock-candidate.yml b/.github/workflows/repro-lock-candidate.yml deleted file mode 100644 index e3f61a2caa..0000000000 --- a/.github/workflows/repro-lock-candidate.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Repro lock candidate - -on: - push: - branches: - - codex/android-repro-independent-20261008 - -permissions: - contents: read - -jobs: - lock: - runs-on: ubuntu-24.04 - timeout-minutes: 30 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 22.23.3 - - name: Resolve the sprint manifest with pinned Yarn - run: | - npm install --global yarn@1.22.22 - yarn install --ignore-scripts --non-interactive --no-progress - sha256sum yarn.lock - git diff --stat -- yarn.lock - printf 'PATCH_DATA:' - git diff -- yarn.lock | base64 -w0 - printf '\n' - - uses: actions/upload-artifact@v4 - with: - name: sprint-yarn-lock-candidate - path: yarn.lock - retention-days: 1 diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh index 4704ed95a3..bbf5803db4 100644 --- a/reproducibility/android-diagnostic-in-container.sh +++ b/reproducibility/android-diagnostic-in-container.sh @@ -72,9 +72,28 @@ test -s "$apk" test -s "$aab" "$ANDROID_SDK_ROOT/build-tools/35.0.0/apksigner" verify "$apk" badging=$("$ANDROID_SDK_ROOT/build-tools/35.0.0/aapt2" dump badging "$apk") -version=$(node -p 'require("./release/version.json").version') -version_code=$(node -p 'require("./release/version.json").androidVersionCode') -grep -Fq "package: name='io.hexawallet.bitcoinkeeper' versionCode='$version_code' versionName='$version'" <<< "$badging" +version_fields=$(python3 - <<'PY' +import json +from pathlib import Path + +metadata = json.loads(Path('android/app/build/outputs/apk/production/release/output-metadata.json').read_text()) +elements = metadata['elements'] +if metadata['applicationId'] != 'io.hexawallet.bitcoinkeeper' or len(elements) != 1: + raise SystemExit('Unexpected Android APK output metadata') +element = elements[0] +if not isinstance(element['versionCode'], int) or not isinstance(element['versionName'], str) or not element['versionName']: + raise SystemExit('Android APK output metadata has no valid version') +print(element['versionCode']) +print(element['versionName']) +PY +) +version_code=${version_fields%%$'\n'*} +version_name=${version_fields#*$'\n'} +[[ $version_code =~ ^[0-9]+$ && -n $version_name && $version_name != "$version_fields" ]] || { + echo 'Android APK output metadata has no valid version.' >&2 + exit 1 +} +grep -Fq "package: name='io.hexawallet.bitcoinkeeper' versionCode='$version_code' versionName='$version_name'" <<< "$badging" jarsigner -verify -verbose -certs "$aab" > /tmp/keeper-aab-signature.log 2>&1 grep -Fxq 'jar verified.' /tmp/keeper-aab-signature.log if grep -Fq '? = unsigned entry' /tmp/keeper-aab-signature.log; then diff --git a/reproducibility/android-inputs.json b/reproducibility/android-inputs.json index 14c9bfc290..a9183f99a6 100644 --- a/reproducibility/android-inputs.json +++ b/reproducibility/android-inputs.json @@ -2,7 +2,7 @@ "node": "22.23.3", "yarn": "1.22.22", "java": "17.0.19", - "yarn_lock_sha256": "b257e6d81f2850ca1c12ce3ddb559d39cd3113a51c09a9eb71ca11c81bf5a245", + "yarn_lock_sha256": "2764cadd01935bfe8542d858a58e9d397ee3479633f3320f8f3dbbff20ae425a", "gradle_wrapper_jar_sha256": "0336f591bc0ec9aa0c9988929b93ecc916b3c1d52aed202c7381db144aa0ef15", "gradle_distribution_sha256": "bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531", "android_packages": { diff --git a/yarn.lock b/yarn.lock index d629fa670f..55464dae23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1296,7 +1296,7 @@ dependencies: eslint-visitor-keys "^3.4.3" -"@eslint-community/regexpp@^4.12.2", "@eslint-community/regexpp@^4.4.0", "@eslint-community/regexpp@^4.6.1": +"@eslint-community/regexpp@^4.12.2", "@eslint-community/regexpp@^4.6.1": version "4.12.2" resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.12.2.tgz#bccdf615bcf7b6e8db830ec0b8d21c9a25de597b" integrity sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew== @@ -4411,11 +4411,6 @@ dependencies: csstype "^3.0.2" -"@types/semver@^7.3.12": - version "7.7.1" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.7.1.tgz#3ce3af1a5524ef327d2da9e4fd8b6d95c8d70528" - integrity sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA== - "@types/stack-utils@^2.0.0": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8" @@ -4455,22 +4450,6 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz#aeef0328d172b9e37d9bab6dbc13b87ed88977db" - integrity sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag== - dependencies: - "@eslint-community/regexpp" "^4.4.0" - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/type-utils" "5.62.0" - "@typescript-eslint/utils" "5.62.0" - debug "^4.3.4" - graphemer "^1.4.0" - ignore "^5.2.0" - natural-compare-lite "^1.4.0" - semver "^7.3.7" - tsutils "^3.21.0" - "@typescript-eslint/eslint-plugin@^8.36.0": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.59.1.tgz#781bc6f9002982cfaf75a185240e24ad7276628a" @@ -4485,16 +4464,6 @@ natural-compare "^1.4.0" ts-api-utils "^2.5.0" -"@typescript-eslint/parser@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.62.0.tgz#1b63d082d849a2fcae8a569248fbe2ee1b8a56c7" - integrity sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA== - dependencies: - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/typescript-estree" "5.62.0" - debug "^4.3.4" - "@typescript-eslint/parser@^8.36.0": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.59.1.tgz#835d20a62350659a082a1ae2a60b822c40488905" @@ -4515,14 +4484,6 @@ "@typescript-eslint/types" "^8.59.1" debug "^4.4.3" -"@typescript-eslint/scope-manager@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c" - integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w== - dependencies: - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/visitor-keys" "5.62.0" - "@typescript-eslint/scope-manager@8.59.1": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.59.1.tgz#ed90d054fc3db2d0c81464db3a953a94fb85bb58" @@ -4536,16 +4497,6 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.59.1.tgz#ba2a779a444f1d5cb92a606f9b209d239fd4cab1" integrity sha512-/0nEyPbX7gRsk0Uwfe4ALwwgxuA66d/l2mhRDNlAvaj4U3juhUtJNq0DsY8M2AYwwb9rEq2hrC3IcIcEt++iJA== -"@typescript-eslint/type-utils@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.62.0.tgz#286f0389c41681376cdad96b309cedd17d70346a" - integrity sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew== - dependencies: - "@typescript-eslint/typescript-estree" "5.62.0" - "@typescript-eslint/utils" "5.62.0" - debug "^4.3.4" - tsutils "^3.21.0" - "@typescript-eslint/type-utils@8.59.1": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.59.1.tgz#9c83d3f2ed9187a815e8120f72c08317e513e409" @@ -4557,29 +4508,11 @@ debug "^4.4.3" ts-api-utils "^2.5.0" -"@typescript-eslint/types@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f" - integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ== - "@typescript-eslint/types@8.59.1", "@typescript-eslint/types@^8.59.1": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.59.1.tgz#c1d014d3f03a97e0113a8899fc9d4e45a7fb0ca9" integrity sha512-ZDCjgccSdYPw5Bxh+my4Z0lJU96ZDN7jbBzvmEn0FZx3RtU1C7VWl6NbDx94bwY3V5YsgwRzJPOgeY2Q/nLG8A== -"@typescript-eslint/typescript-estree@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b" - integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA== - dependencies: - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/visitor-keys" "5.62.0" - debug "^4.3.4" - globby "^11.1.0" - is-glob "^4.0.3" - semver "^7.3.7" - tsutils "^3.21.0" - "@typescript-eslint/typescript-estree@8.59.1": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.59.1.tgz#4391fadf98a22c869c5b6522dbf4e491e53e351a" @@ -4595,20 +4528,6 @@ tinyglobby "^0.2.15" ts-api-utils "^2.5.0" -"@typescript-eslint/utils@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86" - integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ== - dependencies: - "@eslint-community/eslint-utils" "^4.2.0" - "@types/json-schema" "^7.0.9" - "@types/semver" "^7.3.12" - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/typescript-estree" "5.62.0" - eslint-scope "^5.1.1" - semver "^7.3.7" - "@typescript-eslint/utils@8.59.1", "@typescript-eslint/utils@^8.0.0": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.59.1.tgz#cf6204d69701bbbc5b150f98c18aeef0a42c10bd" @@ -4619,14 +4538,6 @@ "@typescript-eslint/types" "8.59.1" "@typescript-eslint/typescript-estree" "8.59.1" -"@typescript-eslint/visitor-keys@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e" - integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw== - dependencies: - "@typescript-eslint/types" "5.62.0" - eslint-visitor-keys "^3.3.0" - "@typescript-eslint/visitor-keys@8.59.1": version "8.59.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.59.1.tgz#b5cba576287a3eeb0b400b62813189abcc3f976a" @@ -5014,11 +4925,6 @@ array-includes@^3.1.6, array-includes@^3.1.8: is-string "^1.1.1" math-intrinsics "^1.1.0" -array-union@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" - integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== - array.prototype.findlast@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/array.prototype.findlast/-/array.prototype.findlast-1.2.5.tgz#3e4fbcb30a15a7f5bf64cf2faae22d139c2e4904" @@ -6598,13 +6504,6 @@ dijkstrajs@^1.0.1: resolved "https://registry.yarnpkg.com/dijkstrajs/-/dijkstrajs-1.0.3.tgz#4c8dbdea1f0f6478bff94d9c49c784d623e4fc23" integrity sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA== -dir-glob@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" - integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA== - dependencies: - path-type "^4.0.0" - doctrine@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" @@ -6902,7 +6801,7 @@ es-errors@^1.3.0: resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f" integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== -es-iterator-helpers@^1.1.0, es-iterator-helpers@^1.2.1: +es-iterator-helpers@^1.2.1: version "1.3.2" resolved "https://registry.yarnpkg.com/es-iterator-helpers/-/es-iterator-helpers-1.3.2.tgz#8f4ff1f3603cbd09fbdb72c747a679779a65cc7f" integrity sha512-HVLACW1TppGYjJ8H6/jqH/pqOtKRw6wMlrB23xfExmFWxFquAIWCmwoLsOyN96K4a5KbmOf5At9ZUO3GZbetAw== @@ -7120,11 +7019,6 @@ eslint-plugin-jsx-a11y@6.10.2: safe-regex-test "^1.0.3" string.prototype.includes "^2.0.1" -eslint-plugin-react-hooks@4.6.2: - version "4.6.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.2.tgz#c829eb06c0e6f484b3fbb85a97e57784f328c596" - integrity sha512-QzliNJq4GinDBcD8gPB5v0wh6g8q3SUi6EFF0x8N/BL9PoVs0atuGc47ozMRyOWAKdwaZ5OnbOEa3WR+dSGKuQ== - eslint-plugin-react-hooks@^7.0.1: version "7.1.1" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-7.1.1.tgz#e6742cad75d970c0a3f30d7d3fa80a4784f55927" @@ -7141,38 +7035,21 @@ eslint-plugin-react-native-globals@^0.1.1: resolved "https://registry.yarnpkg.com/eslint-plugin-react-native-globals/-/eslint-plugin-react-native-globals-0.1.2.tgz#ee1348bc2ceb912303ce6bdbd22e2f045ea86ea2" integrity sha512-9aEPf1JEpiTjcFAmmyw8eiIXmcNZOqaZyHO77wgm0/dWfT/oxC1SrIq8ET38pMxHYrcB6Uew+TzUVsBeczF88g== -eslint-plugin-react-native@4.1.0, eslint-plugin-react-native@^4.0.0: +eslint-plugin-react-native@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react-native/-/eslint-plugin-react-native-4.1.0.tgz#5343acd3b2246bc1b857ac38be708f070d18809f" integrity sha512-QLo7rzTBOl43FvVqDdq5Ql9IoElIuTdjrz9SKAXCvULvBoRZ44JGSkx9z4999ZusCsb4rK3gjS8gOGyeYqZv2Q== dependencies: eslint-plugin-react-native-globals "^0.1.1" -eslint-plugin-react@7.37.2: - version "7.37.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.37.2.tgz#cd0935987876ba2900df2f58339f6d92305acc7a" - integrity sha512-EsTAnj9fLVr/GZleBLFbj/sSuXeWmp1eXIN60ceYnZveqEaUCyW4X+Vh4WTdUhCkW4xutXYqTXCUSyqD4rB75w== +eslint-plugin-react-native@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-react-native/-/eslint-plugin-react-native-5.0.0.tgz#2ee990ba4967c557183b31121578547fb5c02d5d" + integrity sha512-VyWlyCC/7FC/aONibOwLkzmyKg4j9oI8fzrk9WYNs4I8/m436JuOTAFwLvEn1CVvc7La4cPfbCyspP4OYpP52Q== dependencies: - array-includes "^3.1.8" - array.prototype.findlast "^1.2.5" - array.prototype.flatmap "^1.3.2" - array.prototype.tosorted "^1.1.4" - doctrine "^2.1.0" - es-iterator-helpers "^1.1.0" - estraverse "^5.3.0" - hasown "^2.0.2" - jsx-ast-utils "^2.4.1 || ^3.0.0" - minimatch "^3.1.2" - object.entries "^1.1.8" - object.fromentries "^2.0.8" - object.values "^1.2.0" - prop-types "^15.8.1" - resolve "^2.0.0-next.5" - semver "^6.3.1" - string.prototype.matchall "^4.0.11" - string.prototype.repeat "^1.0.0" + eslint-plugin-react-native-globals "^0.1.1" -eslint-plugin-react@^7.30.1: +eslint-plugin-react@^7.30.1, eslint-plugin-react@^7.37.5: version "7.37.5" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.37.5.tgz#2975511472bdda1b272b34d779335c9b0e877065" integrity sha512-Qteup0SqU15kdocexFNAJMvCJEfa2xUKNV4CC1xsVMrIIqEy3SQ/rqyxCWNzfrd3/ldy6HMlD2e0JDVpDg2qIA== @@ -7196,7 +7073,7 @@ eslint-plugin-react@^7.30.1: string.prototype.matchall "^4.0.12" string.prototype.repeat "^1.0.0" -eslint-scope@5.1.1, eslint-scope@^5.1.1: +eslint-scope@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== @@ -7217,7 +7094,7 @@ eslint-visitor-keys@^2.1.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== -eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: +eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: version "3.4.3" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== @@ -7446,7 +7323,7 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== -fast-glob@^3.2.9, fast-glob@^3.3.2, fast-glob@^3.3.3: +fast-glob@^3.3.2, fast-glob@^3.3.3: version "3.3.3" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.3.tgz#d06d585ce8dba90a16b0505c543c3ccfb3aeb818" integrity sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg== @@ -7946,18 +7823,6 @@ globalthis@^1.0.4: define-properties "^1.2.1" gopd "^1.0.1" -globby@^11.1.0: - version "11.1.0" - resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" - integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== - dependencies: - array-union "^2.1.0" - dir-glob "^3.0.1" - fast-glob "^3.2.9" - ignore "^5.2.0" - merge2 "^1.4.1" - slash "^3.0.0" - google-protobuf@3.21.4: version "3.21.4" resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.21.4.tgz#2f933e8b6e5e9f8edde66b7be0024b68f77da6c9" @@ -9517,7 +9382,7 @@ merge-stream@^2.0.0: resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== -merge2@^1.3.0, merge2@^1.4.1: +merge2@^1.3.0: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== @@ -10082,11 +9947,6 @@ napi-build-utils@^2.0.0: resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-2.0.0.tgz#13c22c0187fcfccce1461844136372a47ddc027e" integrity sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA== -natural-compare-lite@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" - integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -10276,7 +10136,7 @@ object.assign@^4.1.2, object.assign@^4.1.4, object.assign@^4.1.7: has-symbols "^1.1.0" object-keys "^1.1.1" -object.entries@^1.1.5, object.entries@^1.1.8, object.entries@^1.1.9: +object.entries@^1.1.5, object.entries@^1.1.9: version "1.1.9" resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.9.tgz#e4770a6a1444afb61bd39f984018b5bede25f8b3" integrity sha512-8u/hfXFRBD1O0hPUjioLhoWFHRmt6tKA4/vZPyckBr18l1KE9uHrFaFaUi8MDRTpi4uak2goyPTSNJLXX2k2Hw== @@ -11949,7 +11809,7 @@ semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.1.3, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.3, semver@^7.7.3: +semver@^7.1.3, semver@^7.3.4, semver@^7.3.5, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.3, semver@^7.7.3: version "7.7.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.4.tgz#28464e36060e991fa7a11d0279d2d3f3b57a7e8a" integrity sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA== @@ -12392,7 +12252,7 @@ string.prototype.includes@^2.0.1: define-properties "^1.2.1" es-abstract "^1.23.3" -string.prototype.matchall@^4.0.11, string.prototype.matchall@^4.0.12: +string.prototype.matchall@^4.0.12: version "4.0.12" resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.12.tgz#6c88740e49ad4956b1332a911e949583a275d4c0" integrity sha512-6CC9uyBL+/48dYizRf7H7VAYCMCNTBeM78x/VTUe9bFEaxBepPJDa1Ow99LqI/1yF7kuy7Q3cQsYMrcjGUcskA== @@ -12779,23 +12639,11 @@ tslib@2.7.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== -tslib@^1.8.1: - version "1.14.1" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" - integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== - tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.8.0, tslib@^2.8.1: version "2.8.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== -tsutils@^3.21.0: - version "3.21.0" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" - integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA== - dependencies: - tslib "^1.8.1" - tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" From 95f9a65b29666404a0599c61eb424b9e76a2ba74 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:23:47 +0530 Subject: [PATCH 11/25] ci: report Android reproducibility tools independently --- .github/workflows/test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ddc8b6716..9950c865b2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,5 +55,13 @@ jobs: - name: Run tests run: npm run test + android-reproducibility-tools: + name: Android reproducibility tools + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v7 + - name: Test Android reproducibility tools - run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py + run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py reproducibility/test_audit_apk_build_values.py From eb224a28ca900694b3723c3460af3da7671dd65d Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:14:11 +0530 Subject: [PATCH 12/25] build: pin Android SDK archive bytes for diagnostic container --- reproducibility/Dockerfile.android-diagnostic | 27 +++++++++++++++---- reproducibility/README.md | 10 ++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index 15d21fff6d..7519fe6355 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -1,6 +1,6 @@ # Diagnostic Linux toolchain for an independent Android build attempt. # This amd64 image digest is for eclipse-temurin:17.0.19_10-jdk-jammy. -# Pinning the base image does not yet pin Ubuntu apt or SDK Maven downloads. +# Ubuntu apt, Maven artifacts, and transitive native downloads remain unpinned. FROM --platform=linux/amd64 eclipse-temurin:17.0.19_10-jdk-jammy@sha256:b76a309b3dfa907458b4ef428edfcfb37920a5ce0e9c6bc77798a54e039a8330 AS java-node-yarn SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -40,9 +40,26 @@ RUN curl -LfsS "https://dl.google.com/android/repository/commandlinetools-linux- && unzip -q /tmp/android-commandline-tools.zip -d "${ANDROID_SDK_ROOT}/cmdline-tools" \ && mv "${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools" "${ANDROID_SDK_ROOT}/cmdline-tools/latest" \ && rm /tmp/android-commandline-tools.zip \ - && sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" --licenses < <(yes) > /dev/null \ - && sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" \ - 'platforms;android-36' 'build-tools;35.0.0' \ - 'ndk;27.1.12297006' 'cmake;3.22.1' + && sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" --licenses < <(yes) > /dev/null + +# These exact Linux archives and their sizes/SHA-1 appear in Google's +# repository2-1.xml. SHA-256 was computed from downloads matching that index. +# The platform package path also has extension variants; use the base rev 2 +# archive explicitly instead of resolving the moving platforms;android-36 path. +RUN set -euo pipefail \ + && download_checked_sdk_archive() { \ + local archive="$1" expected_sha256="$2" destination="$3"; \ + curl -LfsS "https://dl.google.com/android/repository/${archive}" -o /tmp/android-sdk-package.zip; \ + printf '%s %s\n' "$expected_sha256" /tmp/android-sdk-package.zip | sha256sum -c -; \ + mkdir -p "$destination"; \ + unzip -q /tmp/android-sdk-package.zip -d "$destination"; \ + rm /tmp/android-sdk-package.zip; \ + } \ + && download_checked_sdk_archive platform-36_r02.zip 37607369a28c5b640b3a7998868d45898ebcb777565a0e85f9acf36f29631d2e "${ANDROID_SDK_ROOT}/platforms" \ + && download_checked_sdk_archive build-tools_r35_linux.zip bd3a4966912eb8b30ed0d00b0cda6b6543b949d5ffe00bea54c04c81e1561d88 "${ANDROID_SDK_ROOT}/build-tools" \ + && mv "${ANDROID_SDK_ROOT}/build-tools/android-15" "${ANDROID_SDK_ROOT}/build-tools/35.0.0" \ + && download_checked_sdk_archive android-ndk-r27b-linux.zip 33e16af1a6bbabe12cad54b2117085c07eab7e4fa67cdd831805f0e94fd826c1 "${ANDROID_SDK_ROOT}/ndk" \ + && mv "${ANDROID_SDK_ROOT}/ndk/android-ndk-r27b" "${ANDROID_SDK_ROOT}/ndk/27.1.12297006" \ + && download_checked_sdk_archive cmake-3.22.1-linux.zip 9196644852a978012caf7a4067ba1898debf6cc204c3341562771e31080d6869 "${ANDROID_SDK_ROOT}/cmake/3.22.1" WORKDIR /workspace/keeper diff --git a/reproducibility/README.md b/reproducibility/README.md index 584d3d18ed..d76f095013 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -33,9 +33,13 @@ checked SHA-256 hashes. The existing input checker then verifies the exact Node, Yarn, Java, Android SDK package revisions, Gradle wrapper hash, lockfile hash, environment **names**, and local dependency layout before Gradle builds. Gradle and Yarn caches and Gradle's Maven-local home are isolated inside each -container run. The Android SDK packages are selected by version and checked by -revision, but their archive bytes are not yet pinned. Ubuntu apt packages, -Maven artifacts, and transitive native downloads also lack recorded hashes. +container run. The Android platform, Build-Tools, NDK, and CMake archives are +selected by fixed Google URLs and checked by SHA-256 before unpacking. The +archive names, sizes, and Google-published SHA-1 values were checked against +[Google's SDK repository index](https://dl.google.com/android/repository/repository2-1.xml) +before recording the SHA-256 values. The input checker also verifies their +installed revisions. Ubuntu apt packages, +Maven artifacts, and transitive native downloads still lack recorded hashes. Those are remaining build-input gaps. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. From 8d45ef56c2baf1cc142ca5ea6b70b940a0bf49e7 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:30:51 +0530 Subject: [PATCH 13/25] docs: clarify independent reproducibility next checks --- reproducibility/README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/reproducibility/README.md b/reproducibility/README.md index d76f095013..8f55ccd0f3 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -235,12 +235,28 @@ It does not output environment values. A local dependency install is necessary; linking to a sibling `node_modules` directory recreates an observed historical build-path dependency and fails this check. -This check does not yet pin the container image, Android command-line tools -download, Maven artifacts, or every transitive native input. It does not run -the build or compare a binary and is not a WalletScrutiny `build.sh`. The exact -production environment names and values still need release-owner review before -any public recipe or verdict. Run its focused tests with: +The diagnostic container pins its base image and command-line tools archive; +this checker verifies their installed versions but not every apt, Maven, or +transitive native input. It does not run the build or compare a binary and is +not a WalletScrutiny `build.sh`. Run its focused tests with: ```sh python3 -m unittest reproducibility/test_verify_android_inputs.py ``` + +## Next checks + +1. Make the clean Linux diagnostic APK/AAB build pass in CI, then repeat it + from the same commit and compare payloads and build manifests. Resolve any + changing inputs or path-sensitive output. +2. Lock the remaining apt, Maven, and native downloads and confirm that the + candidate release source consumes only the reviewed, noncredential Android + environment fields. The seven proposed values can be checked against the + public v2.6.3 APK without asking the owner to supply them. +3. For the release selected later, rebuild its exact public commit with its + reviewed production configuration. Compare the resulting APK with that + release's authenticated GitHub APK and corresponding Play splits. Investigate + every payload difference before reporting a result. +4. Once that process works end to end, publish a WalletScrutiny-compatible + `build.sh` and `COMPARISON_RESULTS.yaml`. Do not infer a match from the + diagnostic build or from package signatures alone. From ceb3b2c79e4af13c890a51023b7d1f7e1924092d Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:21:32 +0530 Subject: [PATCH 14/25] build: remove mutable Maven local repository lookup --- android/app/build.gradle | 5 ----- android/build.gradle | 1 - reproducibility/README.md | 14 ++++++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index e8ead00b0a..c4d50a557e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -155,11 +155,6 @@ android { } } - - repositories{ - mavenLocal() - } - dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation project(':react-native-iap') diff --git a/android/build.gradle b/android/build.gradle index 92bae26dc7..15075b39fb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -14,7 +14,6 @@ buildscript { repositories { google() mavenCentral() - mavenLocal() } dependencies { classpath("com.android.tools.build:gradle:8.8.0") diff --git a/reproducibility/README.md b/reproducibility/README.md index 8f55ccd0f3..53e132fa0b 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -32,14 +32,16 @@ Node 22.23.3, Yarn 1.22.22, and Android command-line tools downloads have checked SHA-256 hashes. The existing input checker then verifies the exact Node, Yarn, Java, Android SDK package revisions, Gradle wrapper hash, lockfile hash, environment **names**, and local dependency layout before Gradle builds. -Gradle and Yarn caches and Gradle's Maven-local home are isolated inside each -container run. The Android platform, Build-Tools, NDK, and CMake archives are -selected by fixed Google URLs and checked by SHA-256 before unpacking. The -archive names, sizes, and Google-published SHA-1 values were checked against +Gradle and Yarn caches and Java's user home are isolated inside each container +run. The buildscript and app do not declare `mavenLocal()` because it can resolve +dependencies from a mutable local cache outside this diagnostic path. The +Android platform, Build-Tools, NDK, and CMake archives are selected by fixed +Google URLs and checked by SHA-256 before unpacking. The archive names, sizes, +and Google-published SHA-1 values were checked against [Google's SDK repository index](https://dl.google.com/android/repository/repository2-1.xml) before recording the SHA-256 values. The input checker also verifies their -installed revisions. Ubuntu apt packages, -Maven artifacts, and transitive native downloads still lack recorded hashes. +installed revisions. Ubuntu apt packages, Maven artifacts, and transitive +native downloads still lack recorded hashes. Those are remaining build-input gaps. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. From 702d116fe537196821acdde0232a7c2b83710df4 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:33:34 +0530 Subject: [PATCH 15/25] build: register pinned SDK packages and both NDK versions --- reproducibility/Dockerfile.android-diagnostic | 19 +++++++++++++++++++ reproducibility/README.md | 12 +++++++----- reproducibility/android-inputs.json | 1 + .../build-tools-35.0.0.xml | 10 ++++++++++ .../sdk-package-metadata/cmake-3.22.1.xml | 10 ++++++++++ .../ndk-27.0.12077973.xml | 10 ++++++++++ .../ndk-27.1.12297006.xml | 10 ++++++++++ .../sdk-package-metadata/platform-36.xml | 14 ++++++++++++++ 8 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 reproducibility/sdk-package-metadata/build-tools-35.0.0.xml create mode 100644 reproducibility/sdk-package-metadata/cmake-3.22.1.xml create mode 100644 reproducibility/sdk-package-metadata/ndk-27.0.12077973.xml create mode 100644 reproducibility/sdk-package-metadata/ndk-27.1.12297006.xml create mode 100644 reproducibility/sdk-package-metadata/platform-36.xml diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index 7519fe6355..b7ca5e9e6d 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -58,8 +58,27 @@ RUN set -euo pipefail \ && download_checked_sdk_archive platform-36_r02.zip 37607369a28c5b640b3a7998868d45898ebcb777565a0e85f9acf36f29631d2e "${ANDROID_SDK_ROOT}/platforms" \ && download_checked_sdk_archive build-tools_r35_linux.zip bd3a4966912eb8b30ed0d00b0cda6b6543b949d5ffe00bea54c04c81e1561d88 "${ANDROID_SDK_ROOT}/build-tools" \ && mv "${ANDROID_SDK_ROOT}/build-tools/android-15" "${ANDROID_SDK_ROOT}/build-tools/35.0.0" \ + && download_checked_sdk_archive android-ndk-r27-linux.zip 2f17eb8bcbfdc40201c0b36e9a70826fcd2524ab7a2a235e2c71186c302da1dc "${ANDROID_SDK_ROOT}/ndk" \ + && mv "${ANDROID_SDK_ROOT}/ndk/android-ndk-r27" "${ANDROID_SDK_ROOT}/ndk/27.0.12077973" \ && download_checked_sdk_archive android-ndk-r27b-linux.zip 33e16af1a6bbabe12cad54b2117085c07eab7e4fa67cdd831805f0e94fd826c1 "${ANDROID_SDK_ROOT}/ndk" \ && mv "${ANDROID_SDK_ROOT}/ndk/android-ndk-r27b" "${ANDROID_SDK_ROOT}/ndk/27.1.12297006" \ && download_checked_sdk_archive cmake-3.22.1-linux.zip 9196644852a978012caf7a4067ba1898debf6cc204c3341562771e31080d6869 "${ANDROID_SDK_ROOT}/cmake/3.22.1" +# The archives have source.properties but no package.xml. SDK tooling needs +# local package metadata for side-by-side NDK and CMake detection in particular. +COPY sdk-package-metadata/platform-36.xml /opt/android-sdk/platforms/android-36/package.xml +COPY sdk-package-metadata/build-tools-35.0.0.xml /opt/android-sdk/build-tools/35.0.0/package.xml +COPY sdk-package-metadata/ndk-27.0.12077973.xml /opt/android-sdk/ndk/27.0.12077973/package.xml +COPY sdk-package-metadata/ndk-27.1.12297006.xml /opt/android-sdk/ndk/27.1.12297006/package.xml +COPY sdk-package-metadata/cmake-3.22.1.xml /opt/android-sdk/cmake/3.22.1/package.xml + +# Verify SDK Manager itself recognizes every manually unpacked package. This +# catches schema errors that source.properties-only revision checks would miss. +RUN sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" --list_installed > /tmp/keeper-installed-sdk-packages.txt \ + && for package in 'platforms;android-36' 'build-tools;35.0.0' \ + 'ndk;27.0.12077973' 'ndk;27.1.12297006' 'cmake;3.22.1'; do \ + grep -Fq "$package" /tmp/keeper-installed-sdk-packages.txt || { echo "SDK Manager did not recognize $package" >&2; exit 1; }; \ + done \ + && rm /tmp/keeper-installed-sdk-packages.txt + WORKDIR /workspace/keeper diff --git a/reproducibility/README.md b/reproducibility/README.md index 53e132fa0b..96c19c7d5f 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -35,13 +35,15 @@ hash, environment **names**, and local dependency layout before Gradle builds. Gradle and Yarn caches and Java's user home are isolated inside each container run. The buildscript and app do not declare `mavenLocal()` because it can resolve dependencies from a mutable local cache outside this diagnostic path. The -Android platform, Build-Tools, NDK, and CMake archives are selected by fixed -Google URLs and checked by SHA-256 before unpacking. The archive names, sizes, -and Google-published SHA-1 values were checked against +Android platform, Build-Tools, both required NDK versions, and CMake archives +are selected by fixed Google URLs and checked by SHA-256 before unpacking. The +archive names, sizes, and Google-published SHA-1 values were checked against [Google's SDK repository index](https://dl.google.com/android/repository/repository2-1.xml) before recording the SHA-256 values. The input checker also verifies their -installed revisions. Ubuntu apt packages, Maven artifacts, and transitive -native downloads still lack recorded hashes. +installed revisions. Google SDK archives lack `package.xml`, so the image adds +checked local package metadata for their exact paths and revisions. Ubuntu apt +packages, Maven artifacts, and transitive native downloads still lack recorded +hashes. Those are remaining build-input gaps. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. diff --git a/reproducibility/android-inputs.json b/reproducibility/android-inputs.json index a9183f99a6..eac1c1e6a0 100644 --- a/reproducibility/android-inputs.json +++ b/reproducibility/android-inputs.json @@ -7,6 +7,7 @@ "gradle_distribution_sha256": "bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531", "android_packages": { "build-tools/35.0.0": "35.0.0", + "ndk/27.0.12077973": "27.0.12077973", "ndk/27.1.12297006": "27.1.12297006", "cmake/3.22.1": "3.22.1" }, diff --git a/reproducibility/sdk-package-metadata/build-tools-35.0.0.xml b/reproducibility/sdk-package-metadata/build-tools-35.0.0.xml new file mode 100644 index 0000000000..6ade8aa4b7 --- /dev/null +++ b/reproducibility/sdk-package-metadata/build-tools-35.0.0.xml @@ -0,0 +1,10 @@ + + + + + 3500 + Android SDK Build-Tools 35 + + diff --git a/reproducibility/sdk-package-metadata/cmake-3.22.1.xml b/reproducibility/sdk-package-metadata/cmake-3.22.1.xml new file mode 100644 index 0000000000..a3cb6a9ae8 --- /dev/null +++ b/reproducibility/sdk-package-metadata/cmake-3.22.1.xml @@ -0,0 +1,10 @@ + + + + + 3221 + CMake 3.22.1 + + diff --git a/reproducibility/sdk-package-metadata/ndk-27.0.12077973.xml b/reproducibility/sdk-package-metadata/ndk-27.0.12077973.xml new file mode 100644 index 0000000000..bc176b299c --- /dev/null +++ b/reproducibility/sdk-package-metadata/ndk-27.0.12077973.xml @@ -0,0 +1,10 @@ + + + + + 27012077973 + NDK (Side by side) 27.0.12077973 + + diff --git a/reproducibility/sdk-package-metadata/ndk-27.1.12297006.xml b/reproducibility/sdk-package-metadata/ndk-27.1.12297006.xml new file mode 100644 index 0000000000..ad2df8f5f7 --- /dev/null +++ b/reproducibility/sdk-package-metadata/ndk-27.1.12297006.xml @@ -0,0 +1,10 @@ + + + + + 27112297006 + NDK (Side by side) 27.1.12297006 + + diff --git a/reproducibility/sdk-package-metadata/platform-36.xml b/reproducibility/sdk-package-metadata/platform-36.xml new file mode 100644 index 0000000000..0ebef44fc9 --- /dev/null +++ b/reproducibility/sdk-package-metadata/platform-36.xml @@ -0,0 +1,14 @@ + + + + + 36 + true + + + 2 + Android SDK Platform 36 + + From b5019a9e0062ad4543c3a91fd6341dfcad0eea93 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:40:15 +0530 Subject: [PATCH 16/25] fix: make pinned Android SDK readable to diagnostic builder --- reproducibility/Dockerfile.android-diagnostic | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index b7ca5e9e6d..947aad9b07 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -46,6 +46,8 @@ RUN curl -LfsS "https://dl.google.com/android/repository/commandlinetools-linux- # repository2-1.xml. SHA-256 was computed from downloads matching that index. # The platform package path also has extension variants; use the base rev 2 # archive explicitly instead of resolving the moving platforms;android-36 path. +# Some ZIP entries have owner-only read permissions. Make the SDK readable by +# the non-root user that builds the app without changing any file bytes. RUN set -euo pipefail \ && download_checked_sdk_archive() { \ local archive="$1" expected_sha256="$2" destination="$3"; \ @@ -62,7 +64,8 @@ RUN set -euo pipefail \ && mv "${ANDROID_SDK_ROOT}/ndk/android-ndk-r27" "${ANDROID_SDK_ROOT}/ndk/27.0.12077973" \ && download_checked_sdk_archive android-ndk-r27b-linux.zip 33e16af1a6bbabe12cad54b2117085c07eab7e4fa67cdd831805f0e94fd826c1 "${ANDROID_SDK_ROOT}/ndk" \ && mv "${ANDROID_SDK_ROOT}/ndk/android-ndk-r27b" "${ANDROID_SDK_ROOT}/ndk/27.1.12297006" \ - && download_checked_sdk_archive cmake-3.22.1-linux.zip 9196644852a978012caf7a4067ba1898debf6cc204c3341562771e31080d6869 "${ANDROID_SDK_ROOT}/cmake/3.22.1" + && download_checked_sdk_archive cmake-3.22.1-linux.zip 9196644852a978012caf7a4067ba1898debf6cc204c3341562771e31080d6869 "${ANDROID_SDK_ROOT}/cmake/3.22.1" \ + && chmod -R a+rX "${ANDROID_SDK_ROOT}" # The archives have source.properties but no package.xml. SDK tooling needs # local package metadata for side-by-side NDK and CMake detection in particular. From 933f41e497d4c4c0e01d5379fc00f11a1c507302 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:49:25 +0530 Subject: [PATCH 17/25] Pin diagnostic Ubuntu apt inputs to Jammy snapshot --- reproducibility/Dockerfile.android-diagnostic | 33 +++++++++++++++++-- reproducibility/README.md | 30 ++++++++++------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index 947aad9b07..4edef1d772 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -1,12 +1,39 @@ # Diagnostic Linux toolchain for an independent Android build attempt. # This amd64 image digest is for eclipse-temurin:17.0.19_10-jdk-jammy. -# Ubuntu apt, Maven artifacts, and transitive native downloads remain unpinned. +# Maven artifacts and transitive native downloads remain unpinned. FROM --platform=linux/amd64 eclipse-temurin:17.0.19_10-jdk-jammy@sha256:b76a309b3dfa907458b4ef428edfcfb37920a5ce0e9c6bc77798a54e039a8330 AS java-node-yarn SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update \ - && apt-get install -y --no-install-recommends ca-certificates curl git python3 unzip xz-utils \ +# Use a fixed Ubuntu archive state for both the requested packages and their +# transitive dependencies. The six requested versions below are from this +# snapshot's jammy-updates/main amd64 package index. +RUN set -euo pipefail \ + && test "$(dpkg --print-architecture)" = amd64 \ + && dpkg --compare-versions "$(dpkg-query -W -f='${Version}' apt)" ge 2.4.11 \ + && test -f /usr/share/keyrings/ubuntu-archive-keyring.gpg \ + && rm -f /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources \ + && printf '%s\n' \ + 'deb [arch=amd64 signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg snapshot=20261008T000000Z] http://archive.ubuntu.com/ubuntu jammy main' \ + 'deb [arch=amd64 signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg snapshot=20261008T000000Z] http://archive.ubuntu.com/ubuntu jammy-updates main' \ + 'deb [arch=amd64 signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg snapshot=20261008T000000Z] http://security.ubuntu.com/ubuntu jammy-security main' \ + > /etc/apt/sources.list \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get update \ + && apt-cache policy curl | grep -Fq 'snapshot.ubuntu.com/ubuntu/20261008T000000Z' \ + && packages=( \ + 'ca-certificates=20260601~22.04.1' \ + 'curl=7.81.0-1ubuntu1.29' \ + 'git=1:2.34.1-1ubuntu1.17' \ + 'python3=3.10.6-1~22.04.1' \ + 'unzip=6.0-26ubuntu3.2' \ + 'xz-utils=5.2.5-2ubuntu1.1' \ + ) \ + && apt-get -o APT::Get::Always-Include-Phased-Updates=true install -y --no-install-recommends "${packages[@]}" \ + && for spec in "${packages[@]}"; do \ + package="${spec%%=*}"; expected="${spec#*=}"; \ + test "$(dpkg-query -W -f='${Version}' "$package")" = "$expected"; \ + done \ && rm -rf /var/lib/apt/lists/* ARG NODE_VERSION=22.23.3 diff --git a/reproducibility/README.md b/reproducibility/README.md index 96c19c7d5f..12f271283f 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -40,11 +40,15 @@ are selected by fixed Google URLs and checked by SHA-256 before unpacking. The archive names, sizes, and Google-published SHA-1 values were checked against [Google's SDK repository index](https://dl.google.com/android/repository/repository2-1.xml) before recording the SHA-256 values. The input checker also verifies their -installed revisions. Google SDK archives lack `package.xml`, so the image adds -checked local package metadata for their exact paths and revisions. Ubuntu apt -packages, Maven artifacts, and transitive native downloads still lack recorded -hashes. -Those are remaining build-input gaps. The script is therefore an independent +installed revisions. Ubuntu packages are installed from the fixed +`20261008T000000Z` Jammy archive snapshot, with explicit versions for the six +requested packages and APT's signed metadata and package hash checks. This +also fixes the repository state used to resolve transitive apt dependencies. +The snapshot is a diagnostic input, not a claim about the publisher's build +environment. Google SDK archives lack `package.xml`, so the image adds checked +local package metadata for their exact paths and revisions. Ubuntu apt package +hashes are not recorded in this repository; Maven artifacts and transitive +native downloads also remain unpinned. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. The placeholder configuration cannot establish whether a distributed APK or @@ -239,9 +243,11 @@ It does not output environment values. A local dependency install is necessary; linking to a sibling `node_modules` directory recreates an observed historical build-path dependency and fails this check. -The diagnostic container pins its base image and command-line tools archive; -this checker verifies their installed versions but not every apt, Maven, or -transitive native input. It does not run the build or compare a binary and is +The diagnostic container pins its base image, Ubuntu apt snapshot and requested +package versions, and command-line tools archive. The Docker build checks the +snapshot source and six installed package versions. The input checker does not +verify every apt dependency hash, Maven artifact, or transitive native input. +It does not run the build or compare a binary and is not a WalletScrutiny `build.sh`. Run its focused tests with: ```sh @@ -253,10 +259,10 @@ python3 -m unittest reproducibility/test_verify_android_inputs.py 1. Make the clean Linux diagnostic APK/AAB build pass in CI, then repeat it from the same commit and compare payloads and build manifests. Resolve any changing inputs or path-sensitive output. -2. Lock the remaining apt, Maven, and native downloads and confirm that the - candidate release source consumes only the reviewed, noncredential Android - environment fields. The seven proposed values can be checked against the - public v2.6.3 APK without asking the owner to supply them. +2. Record the resolved apt dependency hashes, lock Maven and native downloads, + and confirm that the candidate release source consumes only the reviewed, + noncredential Android environment fields. The seven proposed values can be + checked against the public v2.6.3 APK without asking the owner to supply them. 3. For the release selected later, rebuild its exact public commit with its reviewed production configuration. Compare the resulting APK with that release's authenticated GitHub APK and corresponding Play splits. Investigate From 49a44556070b0388bc2b36c7641d34c43d964eb3 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:53:35 +0530 Subject: [PATCH 18/25] build: pin API 33 and platform tools in diagnostic SDK --- reproducibility/Dockerfile.android-diagnostic | 12 +++++++++--- reproducibility/README.md | 5 +++-- reproducibility/android-inputs.json | 2 ++ .../sdk-package-metadata/platform-33.xml | 15 +++++++++++++++ .../platform-tools-37.0.1.xml | 10 ++++++++++ reproducibility/test_verify_android_inputs.py | 19 +++++++++++++++++++ reproducibility/verify-android-inputs.py | 2 ++ 7 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 reproducibility/sdk-package-metadata/platform-33.xml create mode 100644 reproducibility/sdk-package-metadata/platform-tools-37.0.1.xml diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index 4edef1d772..8a0ec2d0a2 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -71,8 +71,8 @@ RUN curl -LfsS "https://dl.google.com/android/repository/commandlinetools-linux- # These exact Linux archives and their sizes/SHA-1 appear in Google's # repository2-1.xml. SHA-256 was computed from downloads matching that index. -# The platform package path also has extension variants; use the base rev 2 -# archive explicitly instead of resolving the moving platforms;android-36 path. +# Platform package paths have extension variants; select the required rev 2 +# (API 36) and rev 3 (API 33) archives rather than resolving moving paths. # Some ZIP entries have owner-only read permissions. Make the SDK readable by # the non-root user that builds the app without changing any file bytes. RUN set -euo pipefail \ @@ -85,6 +85,9 @@ RUN set -euo pipefail \ rm /tmp/android-sdk-package.zip; \ } \ && download_checked_sdk_archive platform-36_r02.zip 37607369a28c5b640b3a7998868d45898ebcb777565a0e85f9acf36f29631d2e "${ANDROID_SDK_ROOT}/platforms" \ + && download_checked_sdk_archive platform-33-ext3_r03.zip b32b10f787867987f03ae8e101d217e053a9065b7136379fb353b388379aed1d "${ANDROID_SDK_ROOT}/platforms" \ + && mv "${ANDROID_SDK_ROOT}/platforms/android-13" "${ANDROID_SDK_ROOT}/platforms/android-33" \ + && download_checked_sdk_archive platform-tools_r37.0.1-linux.zip d230f13842f60f782a8645f9c813f8f845bf36089ea7289f28c48f17979313f1 "${ANDROID_SDK_ROOT}" \ && download_checked_sdk_archive build-tools_r35_linux.zip bd3a4966912eb8b30ed0d00b0cda6b6543b949d5ffe00bea54c04c81e1561d88 "${ANDROID_SDK_ROOT}/build-tools" \ && mv "${ANDROID_SDK_ROOT}/build-tools/android-15" "${ANDROID_SDK_ROOT}/build-tools/35.0.0" \ && download_checked_sdk_archive android-ndk-r27-linux.zip 2f17eb8bcbfdc40201c0b36e9a70826fcd2524ab7a2a235e2c71186c302da1dc "${ANDROID_SDK_ROOT}/ndk" \ @@ -97,6 +100,8 @@ RUN set -euo pipefail \ # The archives have source.properties but no package.xml. SDK tooling needs # local package metadata for side-by-side NDK and CMake detection in particular. COPY sdk-package-metadata/platform-36.xml /opt/android-sdk/platforms/android-36/package.xml +COPY sdk-package-metadata/platform-33.xml /opt/android-sdk/platforms/android-33/package.xml +COPY sdk-package-metadata/platform-tools-37.0.1.xml /opt/android-sdk/platform-tools/package.xml COPY sdk-package-metadata/build-tools-35.0.0.xml /opt/android-sdk/build-tools/35.0.0/package.xml COPY sdk-package-metadata/ndk-27.0.12077973.xml /opt/android-sdk/ndk/27.0.12077973/package.xml COPY sdk-package-metadata/ndk-27.1.12297006.xml /opt/android-sdk/ndk/27.1.12297006/package.xml @@ -105,7 +110,8 @@ COPY sdk-package-metadata/cmake-3.22.1.xml /opt/android-sdk/cmake/3.22.1/package # Verify SDK Manager itself recognizes every manually unpacked package. This # catches schema errors that source.properties-only revision checks would miss. RUN sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" --list_installed > /tmp/keeper-installed-sdk-packages.txt \ - && for package in 'platforms;android-36' 'build-tools;35.0.0' \ + && for package in 'platforms;android-36' 'platforms;android-33' \ + 'platform-tools' 'build-tools;35.0.0' \ 'ndk;27.0.12077973' 'ndk;27.1.12297006' 'cmake;3.22.1'; do \ grep -Fq "$package" /tmp/keeper-installed-sdk-packages.txt || { echo "SDK Manager did not recognize $package" >&2; exit 1; }; \ done \ diff --git a/reproducibility/README.md b/reproducibility/README.md index 12f271283f..0acd958010 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -35,8 +35,9 @@ hash, environment **names**, and local dependency layout before Gradle builds. Gradle and Yarn caches and Java's user home are isolated inside each container run. The buildscript and app do not declare `mavenLocal()` because it can resolve dependencies from a mutable local cache outside this diagnostic path. The -Android platform, Build-Tools, both required NDK versions, and CMake archives -are selected by fixed Google URLs and checked by SHA-256 before unpacking. The +Android platforms, Platform-Tools, Build-Tools, both required NDK versions, +and CMake archives are selected by fixed Google URLs and checked by SHA-256 +before unpacking. The archive names, sizes, and Google-published SHA-1 values were checked against [Google's SDK repository index](https://dl.google.com/android/repository/repository2-1.xml) before recording the SHA-256 values. The input checker also verifies their diff --git a/reproducibility/android-inputs.json b/reproducibility/android-inputs.json index eac1c1e6a0..a7a2277623 100644 --- a/reproducibility/android-inputs.json +++ b/reproducibility/android-inputs.json @@ -6,6 +6,8 @@ "gradle_wrapper_jar_sha256": "0336f591bc0ec9aa0c9988929b93ecc916b3c1d52aed202c7381db144aa0ef15", "gradle_distribution_sha256": "bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531", "android_packages": { + "platforms/android-33": "3", + "platform-tools": "37.0.1", "build-tools/35.0.0": "35.0.0", "ndk/27.0.12077973": "27.0.12077973", "ndk/27.1.12297006": "27.1.12297006", diff --git a/reproducibility/sdk-package-metadata/platform-33.xml b/reproducibility/sdk-package-metadata/platform-33.xml new file mode 100644 index 0000000000..bdf5428cb8 --- /dev/null +++ b/reproducibility/sdk-package-metadata/platform-33.xml @@ -0,0 +1,15 @@ + + + + + 33 + 3 + true + + + 3 + Android SDK Platform 33 + + diff --git a/reproducibility/sdk-package-metadata/platform-tools-37.0.1.xml b/reproducibility/sdk-package-metadata/platform-tools-37.0.1.xml new file mode 100644 index 0000000000..9d0a53d950 --- /dev/null +++ b/reproducibility/sdk-package-metadata/platform-tools-37.0.1.xml @@ -0,0 +1,10 @@ + + + + + 3701 + Android SDK Platform-Tools + + diff --git a/reproducibility/test_verify_android_inputs.py b/reproducibility/test_verify_android_inputs.py index ad629ccd4b..86aa089e69 100644 --- a/reproducibility/test_verify_android_inputs.py +++ b/reproducibility/test_verify_android_inputs.py @@ -2,6 +2,7 @@ from pathlib import Path import tempfile import unittest +from unittest.mock import patch SCRIPT = Path(__file__).with_name("verify-android-inputs.py") @@ -64,6 +65,24 @@ def test_sdk_revision_accepts_android_property_spacing(self): (package / "source.properties").write_text("Pkg.Revision = 3.22.1\n") self.assertEqual(MODULE.sdk_revision(package), "3.22.1") + def test_additional_android_platform_needs_jar(self): + with tempfile.TemporaryDirectory() as temporary: + sdk = Path(temporary) + platform = sdk / "platforms/android-33" + platform.mkdir(parents=True) + (platform / "source.properties").write_text("Pkg.Revision=3\n") + inputs = { + "node": "22.23.3", + "yarn": "1.22.22", + "java": "17.0.19", + "android_packages": {"platforms/android-33": "3"}, + "android_platform": {"path": "platforms/android-36", "revision": "2"}, + } + outputs = iter(("v22.23.3", "1.22.22", "java.version = 17.0.19")) + with patch.object(MODULE, "run", side_effect=lambda *args: next(outputs)): + with self.assertRaisesRegex(MODULE.InputError, "missing android.jar"): + MODULE.check_toolchain(inputs, sdk) + if __name__ == "__main__": unittest.main() diff --git a/reproducibility/verify-android-inputs.py b/reproducibility/verify-android-inputs.py index 08e0fcc775..cd2ec6b798 100644 --- a/reproducibility/verify-android-inputs.py +++ b/reproducibility/verify-android-inputs.py @@ -144,6 +144,8 @@ def check_toolchain(inputs, sdk_root): for package, revision in inputs["android_packages"].items(): if sdk_revision(sdk_root / package) != revision: raise InputError(f"Android SDK package revision differs: {package}") + if package.startswith("platforms/") and not (sdk_root / package / "android.jar").is_file(): + raise InputError(f"Android platform is missing android.jar: {package}") platform = inputs["android_platform"] if sdk_revision(sdk_root / platform["path"]) != platform["revision"]: raise InputError("Android platform revision differs from pinned Android inputs") From 0276bf18805b8f490e413a13e55e0b16cf4f8e57 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 15:54:11 +0530 Subject: [PATCH 19/25] fix: consume complete apt policy output under pipefail --- reproducibility/Dockerfile.android-diagnostic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index 8a0ec2d0a2..afffaa2b6a 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -20,7 +20,7 @@ RUN set -euo pipefail \ > /etc/apt/sources.list \ && rm -rf /var/lib/apt/lists/* \ && apt-get update \ - && apt-cache policy curl | grep -Fq 'snapshot.ubuntu.com/ubuntu/20261008T000000Z' \ + && apt-cache policy curl | grep -F 'snapshot.ubuntu.com/ubuntu/20261008T000000Z' > /dev/null \ && packages=( \ 'ca-certificates=20260601~22.04.1' \ 'curl=7.81.0-1ubuntu1.29' \ From 4c0e4ed54051bc511464db54ecef27f3b154de03 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 16:20:59 +0530 Subject: [PATCH 20/25] ci: retain diagnostic Android ZIP entry hashes for repeat builds --- .../android-independent-diagnostic.yml | 8 ++++ .github/workflows/test.yml | 2 +- reproducibility/README.md | 13 +++-- .../android-diagnostic-in-container.sh | 5 +- .../test_write_zip_entry_hashes.py | 47 +++++++++++++++++++ reproducibility/write-zip-entry-hashes.py | 46 ++++++++++++++++++ 6 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 reproducibility/test_write_zip_entry_hashes.py create mode 100644 reproducibility/write-zip-entry-hashes.py diff --git a/.github/workflows/android-independent-diagnostic.yml b/.github/workflows/android-independent-diagnostic.yml index ffd750b944..f6eb3c2e8b 100644 --- a/.github/workflows/android-independent-diagnostic.yml +++ b/.github/workflows/android-independent-diagnostic.yml @@ -39,4 +39,12 @@ jobs: cat SHA256SUMS test -s Bitcoin_Keeper_DIAGNOSTIC.apk test -s Bitcoin_Keeper_DIAGNOSTIC.aab + test -s ZIP_ENTRY_SHA256.json echo 'Diagnostic build only; no distributed binary comparison or reproducibility verdict.' + + - name: Retain diagnostic ZIP entry hashes for repeat-build checks + uses: actions/upload-artifact@v4 + with: + name: android-diagnostic-entry-hashes-${{ github.sha }} + path: ${{ runner.temp }}/keeper-android-diagnostic/ZIP_ENTRY_SHA256.json + retention-days: 7 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9950c865b2..98eb4ccd16 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,4 +64,4 @@ jobs: uses: actions/checkout@v7 - name: Test Android reproducibility tools - run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py reproducibility/test_audit_apk_build_values.py + run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py reproducibility/test_audit_apk_build_values.py reproducibility/test_write_zip_entry_hashes.py diff --git a/reproducibility/README.md b/reproducibility/README.md index 0acd958010..33928a8de6 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -20,12 +20,17 @@ bash reproducibility/android-diagnostic.sh \ --output-dir /tmp/keeper-android-diagnostic ``` -The script records the toolchain image ID and writes only the diagnostic APK, -AAB, and their `SHA256SUMS` to the output directory. It never writes a +The script records the toolchain image ID and writes the diagnostic APK, AAB, +their `SHA256SUMS`, and a stable per-entry ZIP content hash manifest to the output +directory. The CI workflow retains only the hash manifest for seven days so +that two builds of the same commit can be compared without publishing the +diagnostic binaries. The manifest includes every non-directory ZIP entry, +including signing files, and compares their uncompressed contents; it does not +compare ZIP metadata or the APK signing block. It never writes a `COMPARISON_RESULTS.yaml` or reports a reproducibility verdict. Its CI workflow builds on a clean Ubuntu runner when a `codex/android-repro*` branch is pushed -or a pull request targets a main development or release branch. No release -artifact is uploaded by that workflow. +or a pull request targets a main development or release branch. No APK or AAB +is uploaded by that workflow. The container uses a digest-pinned **linux/amd64** Temurin JDK 17.0.19 base. Node 22.23.3, Yarn 1.22.22, and Android command-line tools downloads have diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh index bbf5803db4..65c44ee7b6 100644 --- a/reproducibility/android-diagnostic-in-container.sh +++ b/reproducibility/android-diagnostic-in-container.sh @@ -105,8 +105,11 @@ unzip -tq "$aab" >/dev/null cp "$apk" /output/Bitcoin_Keeper_DIAGNOSTIC.apk cp "$aab" /output/Bitcoin_Keeper_DIAGNOSTIC.aab +python3 reproducibility/write-zip-entry-hashes.py \ + --apk "$apk" --aab "$aab" --output /output/ZIP_ENTRY_SHA256.json ( cd /output - sha256sum Bitcoin_Keeper_DIAGNOSTIC.apk Bitcoin_Keeper_DIAGNOSTIC.aab > SHA256SUMS + sha256sum Bitcoin_Keeper_DIAGNOSTIC.apk Bitcoin_Keeper_DIAGNOSTIC.aab \ + ZIP_ENTRY_SHA256.json > SHA256SUMS ) echo 'Diagnostic APK/AAB built with placeholder values and debug signing; no reproducibility verdict.' diff --git a/reproducibility/test_write_zip_entry_hashes.py b/reproducibility/test_write_zip_entry_hashes.py new file mode 100644 index 0000000000..67441c5c27 --- /dev/null +++ b/reproducibility/test_write_zip_entry_hashes.py @@ -0,0 +1,47 @@ +import hashlib +import tempfile +import unittest +import warnings +from pathlib import Path +from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile + +from importlib.util import module_from_spec, spec_from_file_location + +SCRIPT = Path(__file__).with_name("write-zip-entry-hashes.py") +SPEC = spec_from_file_location("write_zip_entry_hashes", SCRIPT) +MODULE = module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) + + +class EntryHashTests(unittest.TestCase): + def test_manifest_ignores_zip_order_and_compression(self): + with tempfile.TemporaryDirectory() as directory: + first = Path(directory) / "first.zip" + second = Path(directory) / "second.zip" + with ZipFile(first, "w", compression=ZIP_STORED) as archive: + archive.writestr("b", b"second") + archive.writestr("a", b"first") + with ZipFile(second, "w", compression=ZIP_DEFLATED) as archive: + archive.writestr("a", b"first") + archive.writestr("b", b"second") + expected = [ + {"path": "a", "sha256": hashlib.sha256(b"first").hexdigest(), "size": 5}, + {"path": "b", "sha256": hashlib.sha256(b"second").hexdigest(), "size": 6}, + ] + self.assertEqual(MODULE.entry_hashes(first), expected) + self.assertEqual(MODULE.entry_hashes(second), expected) + + def test_duplicate_entry_is_rejected(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "duplicate.zip" + with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + with ZipFile(path, "w") as archive: + archive.writestr("same", b"first") + archive.writestr("same", b"second") + with self.assertRaisesRegex(ValueError, "Duplicate ZIP entry"): + MODULE.entry_hashes(path) + + +if __name__ == "__main__": + unittest.main() diff --git a/reproducibility/write-zip-entry-hashes.py b/reproducibility/write-zip-entry-hashes.py new file mode 100644 index 0000000000..8785c6b2d0 --- /dev/null +++ b/reproducibility/write-zip-entry-hashes.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Write a stable content-hash manifest for a diagnostic APK and AAB.""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path +from zipfile import ZipFile + + +def entry_hashes(path: Path) -> list[dict[str, str | int]]: + entries = [] + seen = set() + with ZipFile(path) as archive: + for entry in archive.infolist(): + if entry.is_dir(): + continue + if entry.filename in seen: + raise ValueError(f"Duplicate ZIP entry: {entry.filename}") + seen.add(entry.filename) + digest = hashlib.sha256() + size = 0 + with archive.open(entry) as stream: + for block in iter(lambda: stream.read(1024 * 1024), b""): + digest.update(block) + size += len(block) + if size != entry.file_size: + raise ValueError(f"Incorrect ZIP entry size: {entry.filename}") + entries.append({"path": entry.filename, "sha256": digest.hexdigest(), "size": size}) + return sorted(entries, key=lambda entry: entry["path"]) + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--apk", required=True, type=Path) + parser.add_argument("--aab", required=True, type=Path) + parser.add_argument("--output", required=True, type=Path) + args = parser.parse_args() + result = {"apk": entry_hashes(args.apk), "aab": entry_hashes(args.aab)} + args.output.write_text(json.dumps(result, sort_keys=True, separators=(",", ":")) + "\n") + + +if __name__ == "__main__": + main() From ac3322592fc935091461e1c820d908e162dd7e6d Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 17:17:31 +0530 Subject: [PATCH 21/25] build: verify Gradle artifacts with reviewed SHA-256 metadata --- android/gradle/verification-metadata.xml | 14440 ++++++++++++++++ reproducibility/README.md | 40 +- .../android-diagnostic-in-container.sh | 3 +- 3 files changed, 14474 insertions(+), 9 deletions(-) create mode 100644 android/gradle/verification-metadata.xml diff --git a/android/gradle/verification-metadata.xml b/android/gradle/verification-metadata.xml new file mode 100644 index 0000000000..73220bbeee --- /dev/null +++ b/android/gradle/verification-metadata.xml @@ -0,0 +1,14440 @@ + + + + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/reproducibility/README.md b/reproducibility/README.md index 33928a8de6..f5ce88147d 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -53,10 +53,23 @@ also fixes the repository state used to resolve transitive apt dependencies. The snapshot is a diagnostic input, not a claim about the publisher's build environment. Google SDK archives lack `package.xml`, so the image adds checked local package metadata for their exact paths and revisions. Ubuntu apt package -hashes are not recorded in this repository; Maven artifacts and transitive -native downloads also remain unpinned. The script is therefore an independent +hashes are not recorded in this repository; transitive native downloads also +remain unpinned. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. +The diagnostic Gradle command uses strict SHA-256 dependency verification from +[`android/gradle/verification-metadata.xml`](../android/gradle/verification-metadata.xml). +The candidate was collected by a clean production-flavor APK/AAB build at +commit `9320a1fccd6ce3142697957b48cf3a91f7b852d9` in +[CI run 37919910907](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37919910907). +It records 3,513 artifact checksums for 1,944 components. It also accepts two +observed Google/Maven Central byte variants of the deprecated empty +`com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api` marker; +their JAR contents match and neither POM declares dependencies. This file +checks downloaded Gradle artifacts, not dependency version choices, Yarn +packages, or native downloads outside Gradle. A fresh strict build must pass +before treating the candidate as validated, and changes need review. + The placeholder configuration cannot establish whether a distributed APK or Play split matches this source. The seven-name environment allowlist in `android-inputs.json` remains provisional: this source still references @@ -155,8 +168,9 @@ successful diagnostic used Node not a claim about the publisher's complete toolchain. A third-party recipe still needs a digest-pinned Linux container image, exact JDK/Node/Yarn and SDK package checksums, a fixed checkout and dependency layout, and verified build -commands. The Gradle wrapper now has a distribution checksum pin, but the -Android project has no dependency lock or verification metadata. The published +commands. The Gradle wrapper has a distribution checksum pin and the +diagnostic path has candidate verification metadata, but the Android project +does not lock every dependency version. The published Hermes bundle contains a Node 25.9.0 literal injected by `rn-nodeify` and a path through a sibling `keeper-release-2.5.15/node_modules` directory. These historical build inputs @@ -182,6 +196,14 @@ while explicitly accounting for signing differences. A complete recipe must then build the production APK and AAB under pinned tools and compare the actual distributed artifacts. +For a future release, record the exact source state after Fastlane updates +`versionCode`, the actual `ENVFILE` path and reviewed configuration +revision or fingerprint, and the build invocation. The lane can fetch a +configuration file from a moving branch, while the package script sets +`ENVFILE=.env.production`; the historical file consumed by v2.6.3 is not +established by its source tag alone. Inspect the built package fields to +confirm the release inputs without publishing credential values. + ## Check the seven future build values against a public APK The seven names in `android-inputs.json` are already present as string @@ -252,7 +274,8 @@ build-path dependency and fails this check. The diagnostic container pins its base image, Ubuntu apt snapshot and requested package versions, and command-line tools archive. The Docker build checks the snapshot source and six installed package versions. The input checker does not -verify every apt dependency hash, Maven artifact, or transitive native input. +verify every apt dependency hash or transitive native input; Gradle checks +resolved external artifacts against its separate metadata file. It does not run the build or compare a binary and is not a WalletScrutiny `build.sh`. Run its focused tests with: @@ -262,10 +285,11 @@ python3 -m unittest reproducibility/test_verify_android_inputs.py ## Next checks -1. Make the clean Linux diagnostic APK/AAB build pass in CI, then repeat it - from the same commit and compare payloads and build manifests. Resolve any +1. Repeat the passing clean Linux diagnostic APK/AAB build from the same + commit and compare ZIP entry hashes and build manifests. Resolve any changing inputs or path-sensitive output. -2. Record the resolved apt dependency hashes, lock Maven and native downloads, +2. Validate Gradle verification metadata in a fresh strict build, record the + resolved apt dependency hashes, lock version choices and native downloads, and confirm that the candidate release source consumes only the reviewed, noncredential Android environment fields. The seven proposed values can be checked against the public v2.6.3 APK without asking the owner to supply them. diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh index 65c44ee7b6..4661c10523 100644 --- a/reproducibility/android-diagnostic-in-container.sh +++ b/reproducibility/android-diagnostic-in-container.sh @@ -57,7 +57,8 @@ printf 'sdk.dir=%s\n' "$ANDROID_SDK_ROOT" > android/local.properties export ENVFILE="$diagnostic_env" ( cd android - ./gradlew :app:assembleProductionRelease :app:bundleProductionRelease \ + ./gradlew --dependency-verification strict \ + :app:assembleProductionRelease :app:bundleProductionRelease \ -PMYAPP_RELEASE_STORE_FILE="$repo/android/app/debug.keystore" \ -PMYAPP_RELEASE_STORE_PASSWORD=android \ -PMYAPP_RELEASE_KEY_ALIAS=androiddebugkey \ From 2e3bf65b529b4401b46b35d4e8a485af210bbf8a Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 17:54:02 +0530 Subject: [PATCH 22/25] docs: record strict Android diagnostic verification --- reproducibility/Dockerfile.android-diagnostic | 3 ++- reproducibility/README.md | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index afffaa2b6a..d011a284e3 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -1,6 +1,7 @@ # Diagnostic Linux toolchain for an independent Android build attempt. # This amd64 image digest is for eclipse-temurin:17.0.19_10-jdk-jammy. -# Maven artifacts and transitive native downloads remain unpinned. +# Gradle artifacts are checked by the project's verification metadata; +# transitive native downloads outside Gradle remain unpinned. FROM --platform=linux/amd64 eclipse-temurin:17.0.19_10-jdk-jammy@sha256:b76a309b3dfa907458b4ef428edfcfb37920a5ce0e9c6bc77798a54e039a8330 AS java-node-yarn SHELL ["/bin/bash", "-o", "pipefail", "-c"] diff --git a/reproducibility/README.md b/reproducibility/README.md index f5ce88147d..ab7ebfa9eb 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -67,8 +67,12 @@ observed Google/Maven Central byte variants of the deprecated empty `com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api` marker; their JAR contents match and neither POM declares dependencies. This file checks downloaded Gradle artifacts, not dependency version choices, Yarn -packages, or native downloads outside Gradle. A fresh strict build must pass -before treating the candidate as validated, and changes need review. +packages, or native downloads outside Gradle. A fresh strict build passed at +PR merge commit `a9abf22a2fcf79bd8523957777b71cbd1ac55185` in +[CI run 37925955899](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37925955899), +validating this metadata for the diagnostic path. Its checksum baseline was +generated from the earlier clean build; that does not independently +authenticate every publisher artifact. Changes to the metadata need review. The placeholder configuration cannot establish whether a distributed APK or Play split matches this source. The seven-name environment allowlist in From f90bd142af9f31378f8a0ff11ed726d7835482df Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 18:05:01 +0530 Subject: [PATCH 23/25] docs: record same-source Android payload comparison --- reproducibility/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/reproducibility/README.md b/reproducibility/README.md index ab7ebfa9eb..f5dd1fcad8 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -32,6 +32,24 @@ builds on a clean Ubuntu runner when a `codex/android-repro*` branch is pushed or a pull request targets a main development or release branch. No APK or AAB is uploaded by that workflow. +Two independent clean builds of the exact source commit +`594397ec4212d91ba06bfaa5f473574cc54c4f6d` passed in +[run 37920600243](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37920600243) +and [run 37925672723](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37925672723). +Their retained manifests are byte-for-byte identical (SHA-256 +`390ebdd7481de40ed7d0850a25e5de65ff69edd307507b4978b0a6416b128670`): +all 1,610 APK entries and 1,698 AAB entries have the same uncompressed size +and content hash. The whole AAB is also identical (SHA-256 +`f08727ab342ef8a1b9740cbcdbaa3fc62ae2f0fb022cb06b40e2c78f970effc0`). +The whole APK differs between the runs (`d95ea56f9a8ede9e271bb39bd768685bb723693d3c6aa7214ab6559867b14a7c` +versus `dcb43bdf361306b29cf1b48efade55b253c0dd7e82d3c6a0372fe0e48979437a`), +so its differing bytes are outside the uncompressed entry contents, such as +ZIP packaging metadata or the APK signing block. The workflow did not retain +the APKs, so the exact byte locations remain unmeasured. The two generated +toolchain image IDs also differ, despite the same pinned base image and runner +image version. This is repeat-build evidence for the placeholder diagnostic, +not a comparison with a distributed release. + The container uses a digest-pinned **linux/amd64** Temurin JDK 17.0.19 base. Node 22.23.3, Yarn 1.22.22, and Android command-line tools downloads have checked SHA-256 hashes. The existing input checker then verifies the exact From 5a6a1ead6b14a9054c34de28bd2885458d576389 Mon Sep 17 00:00:00 2001 From: Anant Date: Fri, 9 Oct 2026 19:00:16 +0530 Subject: [PATCH 24/25] docs: locate diagnostic APK byte variance in SDK metadata --- reproducibility/README.md | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/reproducibility/README.md b/reproducibility/README.md index f5dd1fcad8..1547c91b1b 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -44,11 +44,32 @@ and content hash. The whole AAB is also identical (SHA-256 The whole APK differs between the runs (`d95ea56f9a8ede9e271bb39bd768685bb723693d3c6aa7214ab6559867b14a7c` versus `dcb43bdf361306b29cf1b48efade55b253c0dd7e82d3c6a0372fe0e48979437a`), so its differing bytes are outside the uncompressed entry contents, such as -ZIP packaging metadata or the APK signing block. The workflow did not retain -the APKs, so the exact byte locations remain unmeasured. The two generated -toolchain image IDs also differ, despite the same pinned base image and runner -image version. This is repeat-build evidence for the placeholder diagnostic, -not a comparison with a distributed release. +ZIP packaging metadata or the APK signing block. Those two APKs were not +retained, so their exact differing bytes cannot be localized. The two +generated toolchain image IDs also differ, despite the same pinned base image +and runner image version. + +A separate, temporary two-build experiment at the same source commit +`ae55ef108cee65ea2843ab51eae281dbd3ff2393` retained the placeholder, +debug-signed APKs for byte inspection in +[run 37931298363](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37931298363) +and [run 37931306963](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37931306963). +Their whole-file SHA-256 values differed (`4c0d312215775d58c73b83992ebef519d4a720dd11ff1e4611c2c51a7f7c1681` +versus `0df5a7ef40c16106d125cab2474a7ccf9404ad575b88978310ac9b26ea7f2cc6`), +but every compressed ZIP entry, local and central header, ZIP end record, and +APK v2 signature pair matched byte for byte. Only 15,481 bytes in the +15,555-byte signing-block pair `0x504b4453` differed. Android Gradle Plugin +8.8.0 [names this pair](https://dl.google.com/dl/android/maven2/com/android/tools/build/apkzlib/8.8.0/apkzlib-8.8.0-sources.jar) +as SDK dependency information and [encrypts its data](https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.8.0/gradle-8.8.0-sources.jar) +before packaging; the public v2.6.3 APK also contains it. The temporary APK +artifacts expire after one day; the hashes and changed region are recorded +here. [Android's documentation](https://developer.android.com/build/dependencies#dependency-information-for-play-console) +says Play Console uses this metadata for SDK and dependency warnings and +recommends keeping it. A future released-binary comparison should inspect +this precise expected difference while still requiring app contents and all +other relevant package data to match. These measurements establish only +repeat-build behavior under placeholder settings, not a match to a +distributed release. The container uses a digest-pinned **linux/amd64** Temurin JDK 17.0.19 base. Node 22.23.3, Yarn 1.22.22, and Android command-line tools downloads have From c12dcdc4a332110e22ca84a1e7f1dc832fd9fe37 Mon Sep 17 00:00:00 2001 From: Antuz tap Date: Mon, 12 Oct 2026 06:31:00 +0000 Subject: [PATCH 25/25] reproducibility: authenticate release evidence and verify native inputs --- .../android-independent-diagnostic.yml | 14 +- .github/workflows/test.yml | 2 +- patches/realm+12.15.0.patch | 120 ++++++ reproducibility/Dockerfile.android-diagnostic | 9 +- reproducibility/README.md | 184 ++++++++- .../android-diagnostic-in-container.sh | 7 +- reproducibility/audit-android-source.py | 301 +++++++++++++++ reproducibility/inspect-apk-container.py | 364 ++++++++++++++++++ reproducibility/test_audit_android_source.py | 169 ++++++++ reproducibility/test_inspect_apk_container.py | 285 ++++++++++++++ 10 files changed, 1437 insertions(+), 18 deletions(-) create mode 100644 patches/realm+12.15.0.patch create mode 100644 reproducibility/audit-android-source.py create mode 100644 reproducibility/inspect-apk-container.py create mode 100644 reproducibility/test_audit_android_source.py create mode 100644 reproducibility/test_inspect_apk_container.py diff --git a/.github/workflows/android-independent-diagnostic.yml b/.github/workflows/android-independent-diagnostic.yml index f6eb3c2e8b..017dbcde96 100644 --- a/.github/workflows/android-independent-diagnostic.yml +++ b/.github/workflows/android-independent-diagnostic.yml @@ -40,11 +40,21 @@ jobs: test -s Bitcoin_Keeper_DIAGNOSTIC.apk test -s Bitcoin_Keeper_DIAGNOSTIC.aab test -s ZIP_ENTRY_SHA256.json + test -s APK_CONTAINER.json + test -s SOURCE_INPUT_AUDIT.json + test -s APT_PACKAGE_SHA256SUMS + test -s DPKG_PACKAGES.tsv echo 'Diagnostic build only; no distributed binary comparison or reproducibility verdict.' - - name: Retain diagnostic ZIP entry hashes for repeat-build checks + - name: Retain diagnostic hashes and input evidence for repeat-build checks uses: actions/upload-artifact@v4 with: name: android-diagnostic-entry-hashes-${{ github.sha }} - path: ${{ runner.temp }}/keeper-android-diagnostic/ZIP_ENTRY_SHA256.json + path: | + ${{ runner.temp }}/keeper-android-diagnostic/ZIP_ENTRY_SHA256.json + ${{ runner.temp }}/keeper-android-diagnostic/APK_CONTAINER.json + ${{ runner.temp }}/keeper-android-diagnostic/SOURCE_INPUT_AUDIT.json + ${{ runner.temp }}/keeper-android-diagnostic/APT_PACKAGE_SHA256SUMS + ${{ runner.temp }}/keeper-android-diagnostic/DPKG_PACKAGES.tsv + ${{ runner.temp }}/keeper-android-diagnostic/SHA256SUMS retention-days: 7 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98eb4ccd16..480a2f94df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,4 +64,4 @@ jobs: uses: actions/checkout@v7 - name: Test Android reproducibility tools - run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py reproducibility/test_audit_apk_build_values.py reproducibility/test_write_zip_entry_hashes.py + run: python3 -B -m unittest scripts/test_compare_android_apks.py reproducibility/test_verify_android_inputs.py reproducibility/test_audit_apk_build_values.py reproducibility/test_write_zip_entry_hashes.py reproducibility/test_inspect_apk_container.py reproducibility/test_audit_android_source.py diff --git a/patches/realm+12.15.0.patch b/patches/realm+12.15.0.patch new file mode 100644 index 0000000000..e2928e7718 --- /dev/null +++ b/patches/realm+12.15.0.patch @@ -0,0 +1,120 @@ +diff --git a/node_modules/realm/prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake b/node_modules/realm/prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake +--- a/node_modules/realm/prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake ++++ b/node_modules/realm/prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake +@@ -31,1 +31,22 @@ ++ # Pin Android OpenSSL downloads outside Gradle dependency verification. ++ # These are independently observed archive hashes, not historical release provenance. ++ set(_realm_download_verification_args) ++ if(ANDROID AND dep_name STREQUAL "openssl") ++ if(NOT dep_version STREQUAL "3.3.1") ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency version") ++ endif() ++ if(_target_architecture STREQUAL "armeabi-v7a") ++ set(_realm_expected_sha256 "f7ca33cda546c05ad9c258add4f98b6f8f9764d0883d868d93579b1bc2a80ac4") ++ elseif(_target_architecture STREQUAL "arm64-v8a") ++ set(_realm_expected_sha256 "54e4581c4b123d7f04842a6cec3f153838e8a52c9b162b2a2233efd868247610") ++ elseif(_target_architecture STREQUAL "x86") ++ set(_realm_expected_sha256 "f03642845c924a4f4c5e934494b10e3658dbaab5874339a0fe37b661e80adce8") ++ elseif(_target_architecture STREQUAL "x86_64") ++ set(_realm_expected_sha256 "ff64787be7ee2e29fef1d8341ff543f6d8aaa291a8fc7c2e3849d82a8c2ae6fa") ++ else() ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency architecture") ++ endif() ++ set(_realm_download_verification_args EXPECTED_HASH "SHA256=${_realm_expected_sha256}") ++ endif() ++ + if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/include.cmake) +@@ -33,2 +54,2 @@ + message(STATUS "Getting ${DEP_URL}...") +- file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" STATUS download_status) ++ file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" ${_realm_download_verification_args} STATUS download_status) +diff --git a/node_modules/realm/prebuilds/android/armeabi-v7a/share/cmake/Realm/AcquireRealmDependency.cmake b/node_modules/realm/prebuilds/android/armeabi-v7a/share/cmake/Realm/AcquireRealmDependency.cmake +--- a/node_modules/realm/prebuilds/android/armeabi-v7a/share/cmake/Realm/AcquireRealmDependency.cmake ++++ b/node_modules/realm/prebuilds/android/armeabi-v7a/share/cmake/Realm/AcquireRealmDependency.cmake +@@ -31,1 +31,22 @@ ++ # Pin Android OpenSSL downloads outside Gradle dependency verification. ++ # These are independently observed archive hashes, not historical release provenance. ++ set(_realm_download_verification_args) ++ if(ANDROID AND dep_name STREQUAL "openssl") ++ if(NOT dep_version STREQUAL "3.3.1") ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency version") ++ endif() ++ if(_target_architecture STREQUAL "armeabi-v7a") ++ set(_realm_expected_sha256 "f7ca33cda546c05ad9c258add4f98b6f8f9764d0883d868d93579b1bc2a80ac4") ++ elseif(_target_architecture STREQUAL "arm64-v8a") ++ set(_realm_expected_sha256 "54e4581c4b123d7f04842a6cec3f153838e8a52c9b162b2a2233efd868247610") ++ elseif(_target_architecture STREQUAL "x86") ++ set(_realm_expected_sha256 "f03642845c924a4f4c5e934494b10e3658dbaab5874339a0fe37b661e80adce8") ++ elseif(_target_architecture STREQUAL "x86_64") ++ set(_realm_expected_sha256 "ff64787be7ee2e29fef1d8341ff543f6d8aaa291a8fc7c2e3849d82a8c2ae6fa") ++ else() ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency architecture") ++ endif() ++ set(_realm_download_verification_args EXPECTED_HASH "SHA256=${_realm_expected_sha256}") ++ endif() ++ + if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/include.cmake) +@@ -33,2 +54,2 @@ + message(STATUS "Getting ${DEP_URL}...") +- file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" STATUS download_status) ++ file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" ${_realm_download_verification_args} STATUS download_status) +diff --git a/node_modules/realm/prebuilds/android/x86/share/cmake/Realm/AcquireRealmDependency.cmake b/node_modules/realm/prebuilds/android/x86/share/cmake/Realm/AcquireRealmDependency.cmake +--- a/node_modules/realm/prebuilds/android/x86/share/cmake/Realm/AcquireRealmDependency.cmake ++++ b/node_modules/realm/prebuilds/android/x86/share/cmake/Realm/AcquireRealmDependency.cmake +@@ -31,1 +31,22 @@ ++ # Pin Android OpenSSL downloads outside Gradle dependency verification. ++ # These are independently observed archive hashes, not historical release provenance. ++ set(_realm_download_verification_args) ++ if(ANDROID AND dep_name STREQUAL "openssl") ++ if(NOT dep_version STREQUAL "3.3.1") ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency version") ++ endif() ++ if(_target_architecture STREQUAL "armeabi-v7a") ++ set(_realm_expected_sha256 "f7ca33cda546c05ad9c258add4f98b6f8f9764d0883d868d93579b1bc2a80ac4") ++ elseif(_target_architecture STREQUAL "arm64-v8a") ++ set(_realm_expected_sha256 "54e4581c4b123d7f04842a6cec3f153838e8a52c9b162b2a2233efd868247610") ++ elseif(_target_architecture STREQUAL "x86") ++ set(_realm_expected_sha256 "f03642845c924a4f4c5e934494b10e3658dbaab5874339a0fe37b661e80adce8") ++ elseif(_target_architecture STREQUAL "x86_64") ++ set(_realm_expected_sha256 "ff64787be7ee2e29fef1d8341ff543f6d8aaa291a8fc7c2e3849d82a8c2ae6fa") ++ else() ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency architecture") ++ endif() ++ set(_realm_download_verification_args EXPECTED_HASH "SHA256=${_realm_expected_sha256}") ++ endif() ++ + if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/include.cmake) +@@ -33,2 +54,2 @@ + message(STATUS "Getting ${DEP_URL}...") +- file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" STATUS download_status) ++ file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" ${_realm_download_verification_args} STATUS download_status) +diff --git a/node_modules/realm/prebuilds/android/x86_64/share/cmake/Realm/AcquireRealmDependency.cmake b/node_modules/realm/prebuilds/android/x86_64/share/cmake/Realm/AcquireRealmDependency.cmake +--- a/node_modules/realm/prebuilds/android/x86_64/share/cmake/Realm/AcquireRealmDependency.cmake ++++ b/node_modules/realm/prebuilds/android/x86_64/share/cmake/Realm/AcquireRealmDependency.cmake +@@ -31,1 +31,22 @@ ++ # Pin Android OpenSSL downloads outside Gradle dependency verification. ++ # These are independently observed archive hashes, not historical release provenance. ++ set(_realm_download_verification_args) ++ if(ANDROID AND dep_name STREQUAL "openssl") ++ if(NOT dep_version STREQUAL "3.3.1") ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency version") ++ endif() ++ if(_target_architecture STREQUAL "armeabi-v7a") ++ set(_realm_expected_sha256 "f7ca33cda546c05ad9c258add4f98b6f8f9764d0883d868d93579b1bc2a80ac4") ++ elseif(_target_architecture STREQUAL "arm64-v8a") ++ set(_realm_expected_sha256 "54e4581c4b123d7f04842a6cec3f153838e8a52c9b162b2a2233efd868247610") ++ elseif(_target_architecture STREQUAL "x86") ++ set(_realm_expected_sha256 "f03642845c924a4f4c5e934494b10e3658dbaab5874339a0fe37b661e80adce8") ++ elseif(_target_architecture STREQUAL "x86_64") ++ set(_realm_expected_sha256 "ff64787be7ee2e29fef1d8341ff543f6d8aaa291a8fc7c2e3849d82a8c2ae6fa") ++ else() ++ message(FATAL_ERROR "Unreviewed Android Realm OpenSSL dependency architecture") ++ endif() ++ set(_realm_download_verification_args EXPECTED_HASH "SHA256=${_realm_expected_sha256}") ++ endif() ++ + if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/include.cmake) +@@ -33,2 +54,2 @@ + message(STATUS "Getting ${DEP_URL}...") +- file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" STATUS download_status) ++ file(DOWNLOAD "${DEP_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/${dep_name}.tar.gz" ${_realm_download_verification_args} STATUS download_status) diff --git a/reproducibility/Dockerfile.android-diagnostic b/reproducibility/Dockerfile.android-diagnostic index d011a284e3..757a807033 100644 --- a/reproducibility/Dockerfile.android-diagnostic +++ b/reproducibility/Dockerfile.android-diagnostic @@ -1,7 +1,7 @@ # Diagnostic Linux toolchain for an independent Android build attempt. # This amd64 image digest is for eclipse-temurin:17.0.19_10-jdk-jammy. # Gradle artifacts are checked by the project's verification metadata; -# transitive native downloads outside Gradle remain unpinned. +# native downloads outside Gradle require their own checksum checks. FROM --platform=linux/amd64 eclipse-temurin:17.0.19_10-jdk-jammy@sha256:b76a309b3dfa907458b4ef428edfcfb37920a5ce0e9c6bc77798a54e039a8330 AS java-node-yarn SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -30,11 +30,16 @@ RUN set -euo pipefail \ 'unzip=6.0-26ubuntu3.2' \ 'xz-utils=5.2.5-2ubuntu1.1' \ ) \ - && apt-get -o APT::Get::Always-Include-Phased-Updates=true install -y --no-install-recommends "${packages[@]}" \ + && mkdir -p /opt/keeper-toolchain \ + && apt-get -o APT::Get::Always-Include-Phased-Updates=true install -y --download-only --no-install-recommends "${packages[@]}" \ + && (cd /var/cache/apt/archives && LC_ALL=C sha256sum *.deb | LC_ALL=C sort -k2) > /opt/keeper-toolchain/APT_PACKAGE_SHA256SUMS \ + && test -s /opt/keeper-toolchain/APT_PACKAGE_SHA256SUMS \ + && apt-get -o APT::Get::Always-Include-Phased-Updates=true install -y --no-download --no-install-recommends "${packages[@]}" \ && for spec in "${packages[@]}"; do \ package="${spec%%=*}"; expected="${spec#*=}"; \ test "$(dpkg-query -W -f='${Version}' "$package")" = "$expected"; \ done \ + && dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | LC_ALL=C sort > /opt/keeper-toolchain/DPKG_PACKAGES.tsv \ && rm -rf /var/lib/apt/lists/* ARG NODE_VERSION=22.23.3 diff --git a/reproducibility/README.md b/reproducibility/README.md index 1547c91b1b..bfeba2db9a 100644 --- a/reproducibility/README.md +++ b/reproducibility/README.md @@ -22,9 +22,12 @@ bash reproducibility/android-diagnostic.sh \ The script records the toolchain image ID and writes the diagnostic APK, AAB, their `SHA256SUMS`, and a stable per-entry ZIP content hash manifest to the output -directory. The CI workflow retains only the hash manifest for seven days so +directory. The CI workflow retains hash and names-only input reports for seven days so that two builds of the same commit can be compared without publishing the -diagnostic binaries. The manifest includes every non-directory ZIP entry, +diagnostic binaries. `APK_CONTAINER.json` additionally records exact ZIP region +and signing-block pair hashes; `SOURCE_INPUT_AUDIT.json` records static input +gaps. Apt archive hashes and installed package versions account for resolved +Ubuntu inputs. The entry manifest includes every non-directory ZIP entry, including signing files, and compares their uncompressed contents; it does not compare ZIP metadata or the APK signing block. It never writes a `COMPARISON_RESULTS.yaml` or reports a reproducibility verdict. Its CI workflow @@ -91,9 +94,13 @@ requested packages and APT's signed metadata and package hash checks. This also fixes the repository state used to resolve transitive apt dependencies. The snapshot is a diagnostic input, not a claim about the publisher's build environment. Google SDK archives lack `package.xml`, so the image adds checked -local package metadata for their exact paths and revisions. Ubuntu apt package -hashes are not recorded in this repository; transitive native downloads also -remain unpinned. The script is therefore an independent +local package metadata for their exact paths and revisions. Apt archive hashes +are captured before an offline `--no-download` install, followed by a complete +installed-package version list. The archive manifest is retained in CI rather +than committed as a reviewed baseline; inherited packages are covered by the +base image digest. Realm Android OpenSSL downloads now have separate checksum +checks as described below. Other native download paths still need a complete +audit. The script is therefore an independent **diagnostic build path**, not a final WalletScrutiny recipe. The diagnostic Gradle command uses strict SHA-256 dependency verification from @@ -202,9 +209,12 @@ support an exact payload verdict. Some fields appear credential-bearing and require owner security review before public build inputs are released; do not commit an unchecked production environment file. -The source pins Gradle wrapper 8.14.3, Android Gradle Plugin 8.8.0, Android +The source pins Gradle wrapper 8.14.3, directly declares Android Gradle Plugin +8.8.0, and selects Android SDK/target 36, Build Tools 35.0.0, NDK 27.1.12297006, and React Native -0.83.9. The locked Realm dependency requests CMake 3.22.1. The dependency +0.83.9. The authenticated APK actually reports AGP **8.12.0**; React Native's +Gradle plugin also requests 8.12.0. A declaration is not a resolved-version lock. +The locked Realm dependency requests CMake 3.22.1. The dependency tree is recorded in `yarn.lock` and checked-in `patch-package` patches. The successful diagnostic used Node 22.23.3, Yarn 1.22.22, and JDK 17.0.19; these are measured diagnostic inputs, @@ -317,7 +327,8 @@ build-path dependency and fails this check. The diagnostic container pins its base image, Ubuntu apt snapshot and requested package versions, and command-line tools archive. The Docker build checks the snapshot source and six installed package versions. The input checker does not -verify every apt dependency hash or transitive native input; Gradle checks +authenticate every apt/native publisher artifact or lock every dependency +version; Gradle checks resolved external artifacts against its separate metadata file. It does not run the build or compare a binary and is not a WalletScrutiny `build.sh`. Run its focused tests with: @@ -328,11 +339,11 @@ python3 -m unittest reproducibility/test_verify_android_inputs.py ## Next checks -1. Repeat the passing clean Linux diagnostic APK/AAB build from the same - commit and compare ZIP entry hashes and build manifests. Resolve any - changing inputs or path-sensitive output. +1. Validate the new input/container reports and Realm checksum patch in a fresh + strict Linux APK/AAB build. Compare retained manifests, accounting for changed + source/patch fingerprints and SDK metadata randomness. 2. Validate Gradle verification metadata in a fresh strict build, record the - resolved apt dependency hashes, lock version choices and native downloads, + reviewed apt dependency hashes, lock resolved version choices and audit native downloads, and confirm that the candidate release source consumes only the reviewed, noncredential Android environment fields. The seven proposed values can be checked against the public v2.6.3 APK without asking the owner to supply them. @@ -343,3 +354,152 @@ python3 -m unittest reproducibility/test_verify_android_inputs.py 4. Once that process works end to end, publish a WalletScrutiny-compatible `build.sh` and `COMPARISON_RESULTS.yaml`. Do not infer a match from the diagnostic build or from package signatures alone. + +## Independent continuation evidence (12 October 2026) + +The verdict remains **not established**. These checks authenticate and inspect +the released binary and tighten diagnostic inputs. They do not supply the missing +historical production configuration or perform a new release rebuild. No R4 +integration or Bitkey changes are included. + +### Release authentication and source association + +All four assets of [v2.6.3 / release 404858505](https://github.com/KeeperCommunity/bitcoin-keeper/releases/tag/v2.6.3) +were downloaded again and matched GitHub's asset sizes and SHA-256 digests. +The signed checksum and detached APK signature both verified with primary PGP +fingerprint `389F4CADA0785AC0E28A0C181BEBDE261DC3CF62`, already published in the +[April 2024 README](https://github.com/KeeperCommunity/bitcoin-keeper/blob/63a078069a9bcf1ccf696fb8f930fbc6b7c97ce9/Readme.md#pgp). +The checksum extracted from the verified signed message equaled the plain +checksum and the measured APK hash. The keyserver supplied the public key; +independent out-of-band certification of the owner's identity was not obtained. + +SDK Build Tools 35.0.0 `apksigner verify --verbose --print-certs` also passed: +one APK v2 signer, certificate SHA-256 +`bfa023d99facebafa4a9af22b9e49a13dbbfa3ee825be3da16cca9e3ea1b243a`. +The APK has package `io.hexawallet.bitcoinkeeper`, version 2.6.3, code 626, +and SHA-256 `a20d934ebd80ece779d3c171c7906bb4aff010337989ec1b826cab55c50eba46`. +The seven-field presence audit passed again without supplying an environment +file or disclosing any values. + +The source association remains weaker than artifact authentication: `v2.6.3` +is a lightweight tag at unsigned commit +`872cbc4b16ddcb0a8f3b5b1d7ebcde28e06ed096`; the release is mutable. +The APK's `META-INF/version-control-info.textproto` reports +`NO_SUPPORTED_VCS_FOUND`, with no source SHA. GitHub's attestation API returned +404 for this digest; no attestation was retrieved. None of these observations +establishes a binary-to-source build relationship. + +### Actual resolved inputs and configuration gaps + +The released APK's `app-metadata.properties` reports **AGP 8.12.0**. Its +57-byte content hash, `411dcc6d947fcbe47599c3ee9a1d9214afc6865a1c14fc5b6942a14ae6b23f3d`, +also matches the prior diagnostic APK and AAB manifests. This measures the +emitted plugin version; the source's direct 8.8.0 declaration does not describe +the full resolved classpath. Record or lock the resolved dependency graph. + +[`audit-android-source.py`](audit-android-source.py) passively reports static +configuration names, selected file hashes, Yarn integrity coverage and literal +Gradle dynamic selectors. It never reads `.env` files, resolves dependencies or +approves production configuration: + +```sh +python3 -B reproducibility/audit-android-source.py --repo /path/to/exact/source > source-audit.json +``` + +Both v2.6.3 and this branch consume 13 static configuration names. The seven-name +allowlist omits `ENC_KEY_STORAGE_IDENTIFIER`, `SENTRY_DNS`, `GASFREE_API_KEY`, +`GASFREE_API_SECRET`, `LETS_EXCHANGE_BASE_URL`, and `LETS_EXCHANGE_API_KEY`. +Do not reconstruct or publish these values unchecked. The tagged source's +audited build-file/patch fingerprint is +`eb01ddfe4088a95d3cebf7fc48a7c450c7455596a140e832278858d528d01c8b`; +its Yarn lock SHA-256 is +`b257e6d81f2850ca1c12ce3ddb559d39cd3113a51c09a9eb71ca11c81bf5a245`. +This fingerprint covers the auditor's listed files, not the entire source tree +or historical configuration. The diagnostic branch's lockfile and Android version +differ from v2.6.3, so it is not an exact-release comparison candidate. + +The tagged Yarn lock has 1,711 entries / 1,706 valid SHA-512 SRI fields; this +branch has 1,695 / 1,690. Both lack SRI for `cktap-protocol-react-native`, +`electrum-client`, `libportal-react-native`, `rn-nodeify`, and +`satochip-react-native`. Their Git or GitHub archive resolutions use full commit +SHAs; that does not independently authenticate archive/installed bytes. No +Gradle lockfiles were found in the Android source. The fallback +`org.webkit:android-jsc:+` declaration remains (Hermes is enabled here). +Installed transitive modules require a separate audit; strict checksums do not +lock version selection. + +The new apt stage passed in Docker with the managed proxy CA mounted only for +the build step, preserving TLS and APT signature verification. It recorded +23 downloaded `.deb` hashes (manifest SHA-256 +`73b702f96a2d9659b0e26426878b7e0e538468b1b079270ae6e3bd5dc1ee49dd`) +and 169 installed package versions (manifest SHA-256 +`9956078854e22b7c1b123f9d6d30de37fc9a44c720c9da3d0a9c53d2fd96ff19`). +CI now retains these manifests. They account for observed diagnostic inputs, +not the publisher's historical environment. + +### Native downloads outside Gradle + +The locked `realm@12.15.0` npm archive passed Yarn's recorded SHA-512 SRI. +Its four Android CMake helpers download OpenSSL 3.3.1 outside both Yarn and +Gradle verification. [`realm+12.15.0.patch`](../patches/realm+12.15.0.patch) adds +`EXPECTED_HASH SHA256` before extraction and rejects unreviewed Android versions +or ABIs. Hashes were measured from two equal, TLS-verified downloads per archive: + +| Android ABI | OpenSSL archive SHA-256 | +| --- | --- | +| armeabi-v7a | `f7ca33cda546c05ad9c258add4f98b6f8f9764d0883d868d93579b1bc2a80ac4` | +| arm64-v8a | `54e4581c4b123d7f04842a6cec3f153838e8a52c9b162b2a2233efd868247610` | +| x86 | `f03642845c924a4f4c5e934494b10e3658dbaab5874339a0fe37b661e80adce8` | +| x86_64 | `ff64787be7ee2e29fef1d8341ff543f6d8aaa291a8fc7c2e3849d82a8c2ae6fa` | + +These are an observed baseline, not publisher-signed or historical provenance. +Locked `patch-package` 6.4.7 applied all four edits successfully. Real CMake +3.22.1 download/extract checks passed for every ABI; a wrong hash failed before +extraction, and unknown version/ABI checks failed. A non-Android fixture preserved +prior behavior. An already extracted `include.cmake` remains a cache bypass; +fresh CMake trees are required. Other native download paths remain to be audited. + +### Container comparison and limits of AAB evidence + +[`inspect-apk-container.py`](inspect-apk-container.py) hashes bounded ZIP32 +regions, headers/compressed entries and signing-block pairs, without printing +contents or decoding ZIP names. It supplements the payload comparator: + +```sh +python3 -B reproducibility/inspect-apk-container.py released.apk > released-container.json +python3 -B reproducibility/inspect-apk-container.py released.apk rebuilt.apk > container-comparison.json +``` + +Two-file exit 0 requires byte-identical files. Exit 1 reports any difference, +including differences confined to SDK metadata `0x504b4453`; exit 2 rejects +malformed or unsupported input. Signature pairs, padding, unknown pairs, framing, +ordering and ZIP differences remain explicit. It does not verify signatures or +claim reproducibility. + +The released APK has 1,610 ZIP entries and a 20,480-byte signing block: v2 pair +`0x7109871a` (1,537 value bytes), SDK pair `0x504b4453` (15,543), and padding +`0x42726577` (3,332). A **copied-release test fixture**, with one SDK metadata +byte flipped, retained Android v2 signature validity and all 1,610 payload entries. +The container tool correctly returned exit 1 with that pair as the only changed +region. This tests the inspection boundary, not a source rebuild or a release +comparison. The original authenticated release remained unchanged. + +[Prior final-head run 37937333390](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37937333390) +was independently rechecked as **passed**: 1,096 Gradle tasks at checkout +`94eb5a53a055e13eaff773f2b8af1551e4026a32`, associated with prior PR head +`5a6a1ead6b14a9054c34de28bd2885458d576389`. Its artifact ZIP matched GitHub's +digest; its entry manifest matched +[run 37925672723](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/37925672723) +byte for byte (`390ebdd7481de40ed7d0850a25e5de65ff69edd307507b4978b0a6416b128670`). +The whole AAB retained SHA-256 `f08727ab342ef8a1b9740cbcdbaa3fc62ae2f0fb022cb06b40e2c78f970effc0`. +These are prior placeholder/debug results, not validation of this continuation's +new build-input changes. The prior general Jest failure remains an open gate. + +No AAB is published for v2.6.3. Fresh Play split retrieval was not performed; +no Play identity is configured here. Earlier channel-parity results remain +historical evidence. Compare a complete delivered split set with corresponding +outputs from an exact rebuilt AAB, recording the device specification, bundletool +version and signing inputs. A universal APK or an AAB entry manifest cannot +substitute for that comparison. Historical release configuration, complete +resolved inputs, an exact-source independent build and fresh complete Play split +evidence remain blockers to a released-binary verdict and WalletScrutiny results. diff --git a/reproducibility/android-diagnostic-in-container.sh b/reproducibility/android-diagnostic-in-container.sh index 4661c10523..167755360f 100644 --- a/reproducibility/android-diagnostic-in-container.sh +++ b/reproducibility/android-diagnostic-in-container.sh @@ -108,9 +108,14 @@ cp "$apk" /output/Bitcoin_Keeper_DIAGNOSTIC.apk cp "$aab" /output/Bitcoin_Keeper_DIAGNOSTIC.aab python3 reproducibility/write-zip-entry-hashes.py \ --apk "$apk" --aab "$aab" --output /output/ZIP_ENTRY_SHA256.json +python3 reproducibility/inspect-apk-container.py "$apk" > /output/APK_CONTAINER.json +python3 reproducibility/audit-android-source.py > /output/SOURCE_INPUT_AUDIT.json +cp /opt/keeper-toolchain/APT_PACKAGE_SHA256SUMS /output/ +cp /opt/keeper-toolchain/DPKG_PACKAGES.tsv /output/ ( cd /output sha256sum Bitcoin_Keeper_DIAGNOSTIC.apk Bitcoin_Keeper_DIAGNOSTIC.aab \ - ZIP_ENTRY_SHA256.json > SHA256SUMS + ZIP_ENTRY_SHA256.json APK_CONTAINER.json SOURCE_INPUT_AUDIT.json \ + APT_PACKAGE_SHA256SUMS DPKG_PACKAGES.tsv > SHA256SUMS ) echo 'Diagnostic APK/AAB built with placeholder values and debug signing; no reproducibility verdict.' diff --git a/reproducibility/audit-android-source.py b/reproducibility/audit-android-source.py new file mode 100644 index 0000000000..eeb7bd1be7 --- /dev/null +++ b/reproducibility/audit-android-source.py @@ -0,0 +1,301 @@ +#!/usr/bin/env python3 +"""Report Android source/dependency input gaps without reading environment values. + +This passive, static audit is neither a build-input approval nor a reproducibility +verdict. It does not resolve Gradle dependencies or verify installed Yarn bytes. +""" + +import argparse +import base64 +from collections import Counter +import csv +import hashlib +import json +from pathlib import Path +import re +import sys +from urllib.parse import urlsplit + + +class AuditError(Exception): + pass + + +CONFIG_PATH = "src/utils/service-utilities/config.ts" +SOURCE_FILES = ( + "package.json", "yarn.lock", CONFIG_PATH, "android/build.gradle", + "android/app/build.gradle", "android/settings.gradle", "android/gradle.properties", + "android/gradle/wrapper/gradle-wrapper.properties", + "android/gradle/wrapper/gradle-wrapper.jar", +) +NAME_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*\Z") +PACKAGE_RE = re.compile(r"(?:@[A-Za-z0-9_.-]+/)?[A-Za-z0-9_.-]+") +TOKEN_RE = re.compile( + r"(?P//[^\n]*|/\*[\s\S]*?\*/)" + r"|(?P'(?:\\.|[^'\\])*'|\"(?:\\.|[^\"\\])*\"|`(?:\\.|[^`\\])*`)" + r"|(?P[A-Za-z_$][A-Za-z0-9_$]*|\S)" +) + + +def sha256(path): + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def tokens(source): + return [match.group() for match in TOKEN_RE.finditer(source) if not match.group("comment")] + + +def configuration_names(source): + """Inspect the repository's default import and static uppercase accesses only.""" + items = tokens(source) + aliases = set() + import_alias_positions = set() + for index in range(len(items) - 3): + if (items[index] == "import" and NAME_RE.fullmatch(items[index + 1]) + and items[index + 2] == "from" + and items[index + 3] in ("'react-native-config'", '"react-native-config"')): + aliases.add(items[index + 1]) + import_alias_positions.add(index + 1) + if not aliases: + raise AuditError("configuration module has no supported react-native-config default import") + names = set() + dynamic = 0 + unsupported = 0 + for index, token in enumerate(items): + if token not in aliases or index in import_alias_positions: + continue + # A property with the same spelling as an import alias is not that alias. + if (index and items[index - 1] == "." + and items[max(0, index - 3):index] != [".", ".", "."]): + continue + access = index + 1 + if items[access:access + 2] == ["?", "."]: + access += 2 + if access < len(items) and re.fullmatch(r"[A-Z][A-Z0-9_]*", items[access]): + names.add(items[access]) + continue + if (access + 1 < len(items) and items[access] == "." + and re.fullmatch(r"[A-Z][A-Z0-9_]*", items[access + 1])): + names.add(items[access + 1]) + elif access + 1 < len(items) and items[access] == "[": + key = items[access + 1] + if (access + 2 < len(items) and items[access + 2] == "]" + and re.fullmatch(r"['\"][A-Z][A-Z0-9_]*['\"]", key)): + names.add(key[1:-1]) + else: + dynamic += 1 + else: + # Destructuring, passing/spreading the config object, and shadowing + # cannot be resolved by this static scan. Keep the gap explicit. + unsupported += 1 + return sorted(names), dynamic, unsupported + + +def approved_names(inputs): + names = inputs.get("environment_names") + if (not isinstance(names, list) or not names + or any(not isinstance(name, str) or not NAME_RE.fullmatch(name) for name in names) + or len(set(names)) != len(names)): + raise AuditError("input manifest has an invalid environment name list") + return sorted(names) + + +def package_names(header): + try: + selectors = next(csv.reader([header], skipinitialspace=True, strict=True)) + except csv.Error: + raise AuditError("invalid Yarn entry header") from None + names = set() + for selector in selectors: + match = PACKAGE_RE.match(selector) + if not match or selector[match.end():match.end() + 1] != "@": + raise AuditError("unsupported Yarn package selector") + names.add(match.group()) + return sorted(names) + + +def valid_integrity(value): + """Validate SRI encoding/length; presence does not authenticate installed files.""" + algorithms = [] + lengths = {"sha1": 20, "sha256": 32, "sha384": 48, "sha512": 64} + for token in value.split(): + algorithm, separator, encoded = token.partition("-") + if not separator or algorithm not in lengths: + return None + try: + digest = base64.b64decode(encoded, validate=True) + except (ValueError, base64.binascii.Error): + return None + if len(digest) != lengths[algorithm]: + return None + algorithms.append(algorithm) + return algorithms or None + + +def yarn_report(source): + entries = [] + entry = None + for line in source.splitlines(): + if not line or line.startswith("#"): + continue + if not line[0].isspace(): + if not line.endswith(":"): + raise AuditError("unsupported Yarn lockfile format") + entry = {"packages": package_names(line[:-1])} + entries.append(entry) + elif entry is not None: + match = re.fullmatch(r' (resolved|integrity) (.+)', line) + if match: + field, value = match.groups() + if field in entry: + raise AuditError("duplicate Yarn resolution or integrity field") + entry[field] = value.strip('"') + if not entries: + raise AuditError("Yarn lockfile has no supported entries") + algorithms = Counter() + missing = [] + invalid = [] + unresolved = [] + git_entries = [] + commit_archives = [] + for entry in entries: + names = entry["packages"] + integrity = entry.get("integrity") + if not integrity: + missing.extend(names) + else: + parsed = valid_integrity(integrity) + if parsed is None: + invalid.extend(names) + else: + algorithms.update(parsed) + resolved = entry.get("resolved", "") + if not resolved: + unresolved.extend(names) + if resolved.startswith("git+") or resolved.startswith("git://"): + revision = resolved.rsplit("#", 1)[-1] + git_entries.append({"packages": names, "full_commit_pinned": bool( + re.fullmatch(r"[0-9a-f]{40}", revision))}) + elif urlsplit(resolved).hostname == "codeload.github.com": + revision = urlsplit(resolved).path.rsplit("/", 1)[-1] + commit_archives.append({"packages": names, "full_commit_pinned": bool( + re.fullmatch(r"[0-9a-f]{40}", revision))}) + return { + "entries": len(entries), "integrity_algorithms": dict(sorted(algorithms.items())), + "packages_without_integrity": sorted(set(missing)), + "packages_with_invalid_integrity": sorted(set(invalid)), + "packages_without_resolution": sorted(set(unresolved)), "git_entries": git_entries, + "github_commit_archive_entries": commit_archives, + "installed_bytes_verified": False, + } + + +def gradle_dynamic_declarations(path, display_path): + """Find literal Maven dynamic selectors; this is not dependency resolution.""" + source = path.read_text(encoding="utf-8") + result = [] + coordinate_re = re.compile(r"([A-Za-z0-9_.-]+):([A-Za-z0-9_.-]+):([^\s]+)\Z") + for match in TOKEN_RE.finditer(source): + if not match.group("string") or match.group()[0] == "`": + continue + coordinate = match.group()[1:-1] + parsed = coordinate_re.fullmatch(coordinate) + if not parsed: + continue + version = parsed.group(3) + if ("+" in version or version.startswith(("[", "(", "latest.")) + or version.endswith("-SNAPSHOT")): + result.append({"path": display_path, "line": source.count("\n", 0, match.start()) + 1, + "coordinate": coordinate}) + return result + + +def realm_report(package): + if not package.is_dir(): + return {"status": "not_inspected", "outside_gradle_downloads": []} + downloads = [] + for path in sorted((package / "prebuilds/android").glob("*/share/cmake/Realm/*.cmake")): + source = re.sub(r"#[^\n]*", "", path.read_text(encoding="utf-8")) + for match in re.finditer(r"file\s*\(\s*DOWNLOAD\b([\s\S]*?)\)", source, re.I): + body = match.group(1) + literal_expected_hash = bool(re.search(r"\bEXPECTED_(?:HASH|MD5)\b", body)) + conditional_options = False + for variable in re.findall(r"\$\{([A-Za-z_][A-Za-z0-9_]*)\}", body): + conditional_options |= bool(re.search( + r"\bset\s*\(\s*" + re.escape(variable) + r"\s+EXPECTED_(?:HASH|MD5)\b", source)) + downloads.append({ + "path": path.relative_to(package).as_posix(), + "sha256": sha256(path), + "literal_expected_hash_argument": literal_expected_hash, + "conditional_checksum_options_present": conditional_options, + }) + return {"status": "inspected_static_cmake", "outside_gradle_downloads": downloads, + "archive_bytes_verified": False, "cached_extracted_bytes_verified": False, + "runtime_checksum_verification_executed": False} + + +def audit(repo, inputs_path, realm_package=None): + inputs = json.loads(inputs_path.read_text(encoding="utf-8")) + approved = approved_names(inputs) + used, dynamic, unsupported = configuration_names((repo / CONFIG_PATH).read_text(encoding="utf-8")) + fingerprints = {name: sha256(repo / name) for name in SOURCE_FILES if (repo / name).is_file()} + fingerprints.update({path.relative_to(repo).as_posix(): sha256(path) + for path in sorted((repo / "patches").glob("*.patch"))}) + fingerprint = hashlib.sha256(json.dumps(fingerprints, sort_keys=True, separators=(",", ":")) + .encode()).hexdigest() + gradle_paths = list((repo / "android").rglob("*.gradle")) + dependencies = repo / "node_modules" + if dependencies.is_dir() and not dependencies.is_symlink(): + gradle_paths.extend(dependencies.rglob("*.gradle")) + dynamic_gradle = [] + for path in sorted(gradle_paths): + if any(part in ("build", ".gradle") for part in path.relative_to(repo).parts): + continue + dynamic_gradle.extend(gradle_dynamic_declarations(path, path.relative_to(repo).as_posix())) + lockfiles = [path.relative_to(repo).as_posix() for path in sorted((repo / "android").rglob("*.lockfile")) + if not any(part in ("build", ".gradle") for part in path.relative_to(repo).parts)] + return { + "schema_version": 1, "reproducibility_verdict": "not_established", + "source_input_fingerprint_sha256": fingerprint, "file_sha256": fingerprints, + "chosen_manifest_yarn_hash_matches": fingerprints.get("yarn.lock") == inputs.get("yarn_lock_sha256"), + "configuration": {"path": CONFIG_PATH, "static_names": used, "approved_names": approved, + "used_names_outside_allowlist": sorted(set(used) - set(approved)), + "approved_names_not_statically_used": sorted(set(approved) - set(used)), + "dynamic_key_accesses": dynamic, + "unsupported_alias_uses": unsupported, + "complete_environment_input_verified": False}, + "yarn": yarn_report((repo / "yarn.lock").read_text(encoding="utf-8")), + "gradle": {"literal_dynamic_declarations": dynamic_gradle, "lockfiles": lockfiles, + "verification_metadata_present": (repo / "android/gradle/verification-metadata.xml").is_file(), + "local_dependency_gradle_files_inspected": dependencies.is_dir() and not dependencies.is_symlink(), + "resolved_versions_verified": False}, + "realm": realm_report(realm_package or dependencies / "realm"), + "limitations": ["Only supported static accesses in the named configuration module are inspected.", + "Dynamic keys, destructuring and other unsupported alias uses leave names unresolved.", + "react-native-config can embed supplied names beyond static source references.", + "No environment files or values are read; configuration identity is unresolved.", + "No downloaded or installed dependency bytes are authenticated by this audit.", + "CMake option declarations do not verify runtime branches, selected hashes or execution.", + "Gradle declarations and metadata do not prove the historical resolved graph.", + "The file fingerprint covers listed build inputs and patches, not the entire source tree."], + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--repo", type=Path, default=Path(__file__).resolve().parent.parent) + parser.add_argument("--inputs", type=Path, default=Path(__file__).with_name("android-inputs.json")) + parser.add_argument("--realm-package", type=Path, help="optional unpacked Realm npm package to inspect") + args = parser.parse_args() + try: + report = audit(args.repo.resolve(), args.inputs, args.realm_package) + except (AuditError, OSError, ValueError, KeyError): + # Source literals, paths and parse error contents can contain private data. + print("Android source audit failed; check readable supported source inputs.", file=sys.stderr) + return 1 + print(json.dumps(report, indent=2, sort_keys=True)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/reproducibility/inspect-apk-container.py b/reproducibility/inspect-apk-container.py new file mode 100644 index 0000000000..89dd8f554c --- /dev/null +++ b/reproducibility/inspect-apk-container.py @@ -0,0 +1,364 @@ +#!/usr/bin/env python3 +"""Hash exact ZIP32 APK regions and APK signing-block pairs without extracting data. + +This read-only inspection does not verify signatures, authenticate an APK, or +establish source reproducibility. Even an SDK metadata-only difference exits 1. +No entry contents, signing-block values, or decoded ZIP names are printed. +""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path +import struct +import sys + + +CHUNK_SIZE = 1024 * 1024 +MAX_APK_BYTES = 0xFFFFFFFF +MAX_CENTRAL_DIRECTORY_BYTES = 64 * 1024 * 1024 +MAX_SIGNING_BLOCK_BYTES = 64 * 1024 * 1024 +MAX_SIGNING_PAIRS = 1024 +EOCD_MAGIC = b"PK\x05\x06" +APK_MAGIC = b"APK Sig Block 42" +SDK_METADATA_ID = "0x504b4453" +SCOPE = ( + "Exact ZIP32 APK container bytes and APK signing-block pair values; " + "no signature verification, artifact authentication, or reproducibility verdict" +) + + +def _read(stream, offset: int, size: int, limit: int) -> bytes: + if offset < 0 or size < 0 or offset + size > limit: + raise ValueError("APK region exceeds its containing boundary") + stream.seek(offset) + value = stream.read(size) + if len(value) != size: + raise ValueError("Truncated APK region") + return value + + +def _region(stream, offset: int, size: int, limit: int) -> dict: + if offset < 0 or size < 0 or offset + size > limit: + raise ValueError("APK region exceeds its containing boundary") + stream.seek(offset) + digest = hashlib.sha256() + remaining = size + while remaining: + chunk = stream.read(min(CHUNK_SIZE, remaining)) + if not chunk: + raise ValueError("Truncated APK region") + digest.update(chunk) + remaining -= len(chunk) + return {"offset": offset, "size": size, "sha256": digest.hexdigest()} + + +def _extra(data: bytes) -> None: + position = 0 + nonzero_end = len(data.rstrip(b"\0")) + while position < len(data): + # Android zipalign also uses unstructured zero padding in local extras. + if position >= nonzero_end: + return + if len(data) - position < 4: + raise ValueError("Malformed ZIP extra field") + field_id, size = struct.unpack_from(" len(data): + raise ValueError("Malformed ZIP extra field") + position += size + + +def _eocd(stream, file_size: int) -> tuple[int, int, int, int]: + tail_size = min(file_size, 22 + 0xFFFF) + tail_start = file_size - tail_size + tail = _read(stream, tail_start, tail_size, file_size) + candidates = [] + position = tail.find(EOCD_MAGIC) + while position >= 0: + if position + 22 <= len(tail): + comment_size = struct.unpack_from("= 20 and _read(stream, offset - 20, 4, file_size) == b"PK\x06\x07": + raise ValueError("ZIP64 is unsupported") + if cd_offset + cd_size != offset: + raise ValueError("Central directory does not end at the ZIP end record") + if cd_size > MAX_CENTRAL_DIRECTORY_BYTES: + raise ValueError("Central directory exceeds inspection limit") + return offset, cd_offset, cd_size, count + + +def _signing_block(stream, cd_offset: int, file_size: int) -> tuple[int, dict]: + if cd_offset < 24 or _read(stream, cd_offset - 16, 16, file_size) != APK_MAGIC: + return cd_offset, {"present": False} + footer = _read(stream, cd_offset - 24, 24, file_size) + size = struct.unpack_from(" cd_offset: + raise ValueError("Invalid APK signing-block size") + if total_size > MAX_SIGNING_BLOCK_BYTES: + raise ValueError("APK signing block exceeds inspection limit") + start = cd_offset - total_size + if struct.unpack("= MAX_SIGNING_PAIRS: + raise ValueError("Too many APK signing-block pairs") + pair_size = struct.unpack(" end: + raise ValueError("Invalid APK signing-block pair size") + pair_id = struct.unpack(" list[dict]: + position, end = offset, offset + size + entries = [] + names, offsets = set(), set() + for _ in range(count): + header = _read(stream, position, 46, end) + fields = struct.unpack("<4s6H3I5H2I", header) + if fields[0] != b"PK\x01\x02": + raise ValueError("Invalid ZIP central directory header") + _, _, _, flags, method, _, _, crc, compressed, uncompressed, name_len, extra_len, comment_len, disk, _, _, local_offset = fields + if compressed == 0xFFFFFFFF or uncompressed == 0xFFFFFFFF or local_offset == 0xFFFFFFFF: + raise ValueError("ZIP64 is unsupported") + if disk: + raise ValueError("Multi-disk ZIP is unsupported") + if flags & 0x0041: + raise ValueError("Encrypted ZIP entries are unsupported") + variable = _read(stream, position + 46, name_len + extra_len + comment_len, end) + name = variable[:name_len] + if not name or name in names: + raise ValueError("Empty or duplicate raw ZIP entry name") + if local_offset in offsets or local_offset >= local_end: + raise ValueError("Invalid or duplicate local ZIP header offset") + names.add(name) + offsets.add(local_offset) + _extra(variable[name_len:name_len + extra_len]) + header_size = 46 + len(variable) + entries.append({ + "name": name, + "name_sha256": hashlib.sha256(name).hexdigest(), + "flags": flags, + "method": method, + "crc": crc, + "compressed": compressed, + "uncompressed": uncompressed, + "local_offset": local_offset, + "central_header": _region(stream, position, header_size, end), + }) + position += header_size + if position != end: + raise ValueError("Central directory size or entry count disagrees") + return entries + + +def _local_entries(stream, entries: list[dict], local_end: int) -> dict: + result = {} + position = 0 + ordered = sorted(entries, key=lambda entry: entry["local_offset"]) + for index, entry in enumerate(ordered): + if entry["local_offset"] != position: + raise ValueError("Gaps, overlapping entries, or a ZIP prefix are unsupported") + end = ordered[index + 1]["local_offset"] if index + 1 < len(ordered) else local_end + header = _read(stream, position, 30, end) + magic, _, flags, method, _, _, crc, compressed, uncompressed, name_len, extra_len = struct.unpack("<4s5H3I2H", header) + if magic != b"PK\x03\x04": + raise ValueError("Invalid local ZIP header") + if compressed == 0xFFFFFFFF or uncompressed == 0xFFFFFFFF: + raise ValueError("ZIP64 is unsupported") + variable = _read(stream, position + 30, name_len + extra_len, end) + if variable[:name_len] != entry["name"] or flags != entry["flags"] or method != entry["method"]: + raise ValueError("Local and central ZIP headers disagree") + _extra(variable[name_len:]) + expected = (entry["crc"], entry["compressed"], entry["uncompressed"]) + observed = (crc, compressed, uncompressed) + if flags & 8: + if any(actual not in (0, wanted) for actual, wanted in zip(observed, expected)): + raise ValueError("Local ZIP data-descriptor fields disagree") + elif observed != expected: + raise ValueError("Local and central ZIP sizes or CRC disagree") + header_size = 30 + len(variable) + data_offset = position + header_size + data_end = data_offset + entry["compressed"] + descriptor_size = end - data_end + if flags & 8: + if descriptor_size not in (12, 16): + raise ValueError("Invalid or unsupported ZIP data descriptor") + descriptor = _read(stream, data_end, descriptor_size, end) + if descriptor_size == 16: + if descriptor[:4] != b"PK\x07\x08": + raise ValueError("Invalid ZIP data descriptor signature") + descriptor = descriptor[4:] + if struct.unpack("<3I", descriptor) != expected: + raise ValueError("ZIP data descriptor disagrees with central header") + elif descriptor_size: + raise ValueError("Gaps or overlapping ZIP entries are unsupported") + result[entry["name_sha256"]] = { + "local_header": _region(stream, position, header_size, end), + "compressed_data": _region(stream, data_offset, entry["compressed"], end), + "data_descriptor": _region(stream, data_end, descriptor_size, end), + "central_header": entry["central_header"], + } + position = end + if position != local_end: + raise ValueError("Unaccounted bytes before the central directory or signing block") + return dict(sorted(result.items())) + + +def inspect_apk(path: Path) -> dict: + if not path.is_file(): + raise ValueError("Input is not a regular file") + file_size = path.stat().st_size + if file_size > MAX_APK_BYTES: + raise ValueError("APK exceeds ZIP32 inspection limit") + with path.open("rb") as stream: + eocd_offset, cd_offset, cd_size, count = _eocd(stream, file_size) + local_end, signing = _signing_block(stream, cd_offset, file_size) + entries = _central_entries(stream, cd_offset, cd_size, count, local_end) + entry_hashes = _local_entries(stream, entries, local_end) + return { + "schema_version": 1, + "scope": SCOPE, + "file_size": file_size, + "file_sha256": _region(stream, 0, file_size, file_size)["sha256"], + "zip_entry_count": count, + "zip_regions": { + "local_records": _region(stream, 0, local_end, file_size), + "central_directory": _region(stream, cd_offset, cd_size, file_size), + "eocd": _region(stream, eocd_offset, file_size - eocd_offset, file_size), + }, + "signing_block": signing, + "entries_by_raw_name_sha256": entry_hashes, + } + + +def _bytes_equal(left: dict | None, right: dict | None) -> bool: + if left is None or right is None: + return left is right + return (left["size"], left["sha256"]) == (right["size"], right["sha256"]) + + +def compare(reference: dict, rebuilt: dict) -> dict: + zip_differences = [ + name for name in reference["zip_regions"] + if not _bytes_equal(reference["zip_regions"][name], rebuilt["zip_regions"][name]) + ] + before_block, after_block = reference["signing_block"], rebuilt["signing_block"] + before_pairs = {pair["id"]: pair for pair in before_block.get("pairs", [])} + after_pairs = {pair["id"]: pair for pair in after_block.get("pairs", [])} + pair_differences = [] + for pair_id in sorted(before_pairs.keys() | after_pairs.keys()): + before, after = before_pairs.get(pair_id), after_pairs.get(pair_id) + identity = lambda pair: None if pair is None else (pair["value_size"], pair["value_sha256"]) + if identity(before) != identity(after): + pair_differences.append({ + "id": pair_id, + "role": "sdk_dependency_metadata" if pair_id == SDK_METADATA_ID else "other_signing_block_data", + "reference": before, + "rebuilt": after, + }) + before_order = [pair["id"] for pair in before_block.get("pairs", [])] + after_order = [pair["id"] for pair in after_block.get("pairs", [])] + framing_equal = before_block["present"] == after_block["present"] and all( + _bytes_equal(before_block.get("framing", {}).get(name), after_block.get("framing", {}).get(name)) + for name in ("leading_size", "footer") + ) + entry_differences = [] + matching_parts = {name: 0 for name in ("local_header", "compressed_data", "data_descriptor", "central_header")} + before_entries = reference["entries_by_raw_name_sha256"] + after_entries = rebuilt["entries_by_raw_name_sha256"] + for name_hash in sorted(before_entries.keys() | after_entries.keys()): + before, after = before_entries.get(name_hash), after_entries.get(name_hash) + parts = [] + for name in matching_parts: + if before is not None and after is not None and _bytes_equal(before[name], after[name]): + matching_parts[name] += 1 + else: + parts.append(name) + if parts: + entry_differences.append({"raw_name_sha256": name_hash, "differing_parts": parts}) + identical = reference["file_size"] == rebuilt["file_size"] and reference["file_sha256"] == rebuilt["file_sha256"] + sdk_only = ( + not identical and not zip_differences and framing_equal and before_order == after_order + and len(pair_differences) == 1 and pair_differences[0]["id"] == SDK_METADATA_ID + ) + return { + "schema_version": 1, + "scope": SCOPE, + "result": "identical" if identical else "different", + "difference_scope": "none" if identical else "sdk_dependency_metadata_pair_only" if sdk_only else "other_package_data", + "reference": {key: value for key, value in reference.items() if key != "entries_by_raw_name_sha256"}, + "rebuilt": {key: value for key, value in rebuilt.items() if key != "entries_by_raw_name_sha256"}, + "zip_region_differences": zip_differences, + "signing_block_presence_equal": before_block["present"] == after_block["present"], + "signing_block_framing_equal": framing_equal, + "signing_block_pair_order_equal": before_order == after_order, + "signing_block_pair_differences": pair_differences, + "matching_entry_parts": matching_parts, + "entry_differences": entry_differences, + } + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("reference_apk", type=Path, help="APK to inspect; independently verify its signer and provenance") + parser.add_argument("rebuilt_apk", type=Path, nargs="?", help="Optional second APK for exact-byte comparison") + args = parser.parse_args() + try: + reference = inspect_apk(args.reference_apk) + if args.rebuilt_apk is None: + report, status = reference, 0 + else: + report = compare(reference, inspect_apk(args.rebuilt_apk)) + status = 0 if report["result"] == "identical" else 1 + except (OSError, ValueError, struct.error) as error: + # OSError text can contain input paths; print only the exception type. + message = str(error) if isinstance(error, ValueError) else type(error).__name__ + report, status = {"schema_version": 1, "scope": SCOPE, "result": "invalid_input", "error": message}, 2 + json.dump(report, sys.stdout, indent=2, sort_keys=True) + sys.stdout.write("\n") + return status + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/reproducibility/test_audit_android_source.py b/reproducibility/test_audit_android_source.py new file mode 100644 index 0000000000..cc7983b352 --- /dev/null +++ b/reproducibility/test_audit_android_source.py @@ -0,0 +1,169 @@ +import base64 +import contextlib +import hashlib +import importlib.util +import io +import json +from pathlib import Path +import tempfile +import unittest +from unittest.mock import patch + + +SCRIPT = Path(__file__).with_name("audit-android-source.py") +SPEC = importlib.util.spec_from_file_location("audit_android_source", SCRIPT) +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) +PRIVATE_VALUE = "private-fixture-do-not-print" +SRI = "sha512-" + base64.b64encode(hashlib.sha512(b"fixture").digest()).decode() + + +class SourceAuditTest(unittest.TestCase): + def test_configuration_reports_names_without_values_or_comment_false_positives(self): + source = f"""import config from 'react-native-config'; + const defaultConfig = {{ RELAY: '{PRIVATE_VALUE}' }}; + // config.COMMENTED + const text = 'config.STRING'; + config.RELAY; config['ENVIRONMENT']; config[computedName]; + """ + names, dynamic, unsupported = MODULE.configuration_names(source) + self.assertEqual(names, ["ENVIRONMENT", "RELAY"]) + self.assertEqual(dynamic, 1) + self.assertEqual(unsupported, 0) + + def test_optional_access_supported_and_destructuring_reported_unresolved(self): + source = """import cfg from 'react-native-config'; + cfg?.GASFREE_API_KEY; cfg?.['RELAY']; + const { GASFREE_API_SECRET } = cfg; + const copied = { ...cfg }; + other.cfg.UNRELATED; + """ + names, dynamic, unsupported = MODULE.configuration_names(source) + self.assertEqual(names, ["GASFREE_API_KEY", "RELAY"]) + self.assertEqual(dynamic, 0) + self.assertEqual(unsupported, 2) + + def test_configuration_requires_supported_import(self): + with self.assertRaises(MODULE.AuditError): + MODULE.configuration_names("const config = {}; config.RELAY;") + + def test_names_manifest_rejects_duplicates_and_invalid_names(self): + for names in (["RELAY", "RELAY"], [PRIVATE_VALUE], [], "RELAY"): + with self.subTest(names=names), self.assertRaises(MODULE.AuditError): + MODULE.approved_names({"environment_names": names}) + + def test_yarn_reports_pinned_git_and_missing_integrity_without_remote_values(self): + source = f'''# yarn lockfile v1 +"@scope/pkg@^1", "@scope/pkg@~1": + version "1.0.0" + resolved "https://registry.example/{PRIVATE_VALUE}/pkg.tgz" + integrity {SRI} +"native@git+https://{PRIVATE_VALUE}@example.invalid/native.git#{'a' * 40}": + version "1.0.0" + resolved "git+https://{PRIVATE_VALUE}@example.invalid/native.git#{'a' * 40}" +"rn-nodeify@github:tradle/rn-nodeify#{'b' * 40}": + resolved "https://codeload.github.com/tradle/rn-nodeify/tar.gz/{'b' * 40}" +''' + report = MODULE.yarn_report(source) + self.assertEqual(report["entries"], 3) + self.assertEqual(report["integrity_algorithms"], {"sha512": 1}) + self.assertEqual(report["packages_without_integrity"], ["native", "rn-nodeify"]) + self.assertEqual(report["git_entries"], [{"packages": ["native"], "full_commit_pinned": True}]) + self.assertEqual(report["github_commit_archive_entries"], [{"packages": ["rn-nodeify"], "full_commit_pinned": True}]) + self.assertNotIn(PRIVATE_VALUE, json.dumps(report)) + + def test_yarn_rejects_corrupt_integrity_and_noncommit_git_pin(self): + source = '''"native@git+https://example.invalid/native.git#main": + resolved "git+https://example.invalid/native.git#main" + integrity sha512-Zm9v +''' + report = MODULE.yarn_report(source) + self.assertEqual(report["packages_with_invalid_integrity"], ["native"]) + self.assertFalse(report["git_entries"][0]["full_commit_pinned"]) + + def test_gradle_dynamic_selectors_exclude_comments_and_fixed_versions(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "build.gradle" + path.write_text('''// implementation 'org.example:comment:+' +implementation 'org.example:fixed:1.0' +implementation 'org.example:dynamic:+' +implementation "org.example:range:[1,2)" +implementation 'org.example:nightly:1.0-SNAPSHOT' +''') + report = MODULE.gradle_dynamic_declarations(path, "android/build.gradle") + self.assertEqual([item["line"] for item in report], [3, 4, 5]) + self.assertEqual([item["coordinate"] for item in report], + ["org.example:dynamic:+", "org.example:range:[1,2)", "org.example:nightly:1.0-SNAPSHOT"]) + + def test_realm_detects_checksum_omission_without_exporting_url(self): + with tempfile.TemporaryDirectory() as directory: + package = Path(directory) + path = package / "prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake" + path.parent.mkdir(parents=True) + path.write_text(f'file(DOWNLOAD "https://example.invalid/{PRIVATE_VALUE}" "archive" STATUS result)') + report = MODULE.realm_report(package) + self.assertFalse(report["outside_gradle_downloads"][0]["literal_expected_hash_argument"]) + self.assertFalse(report["outside_gradle_downloads"][0]["conditional_checksum_options_present"]) + self.assertNotIn(PRIVATE_VALUE, json.dumps(report)) + path.write_text('file(DOWNLOAD "url" "archive" EXPECTED_HASH "SHA256=pin" STATUS result)') + inline = MODULE.realm_report(package)["outside_gradle_downloads"][0] + self.assertTrue(inline["literal_expected_hash_argument"]) + self.assertFalse(inline["conditional_checksum_options_present"]) + + def test_original_and_patched_realm_helper_distinguish_conditional_checksum_options(self): + original = '''function(realm_acquire_dependency dep_name dep_version out_dep_cmake) + if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${dep_name}/include.cmake) + file(DOWNLOAD "${DEP_URL}" "archive" STATUS download_status) + endif() + endfunction() + ''' + patched = original.replace(' if(NOT EXISTS', ''' set(_realm_download_verification_args) + if(ANDROID AND dep_name STREQUAL "openssl") + set(_realm_download_verification_args EXPECTED_HASH "SHA256=${_realm_expected_sha256}") + endif() + if(NOT EXISTS''').replace('STATUS download_status)', '${_realm_download_verification_args} STATUS download_status)') + with tempfile.TemporaryDirectory() as directory: + package = Path(directory) + path = package / "prebuilds/android/arm64-v8a/share/cmake/Realm/AcquireRealmDependency.cmake" + path.parent.mkdir(parents=True) + path.write_text(original) + upstream = MODULE.realm_report(package)["outside_gradle_downloads"][0] + self.assertFalse(upstream["literal_expected_hash_argument"]) + self.assertFalse(upstream["conditional_checksum_options_present"]) + path.write_text(patched) + report = MODULE.realm_report(package) + declarations = report["outside_gradle_downloads"][0] + self.assertFalse(declarations["literal_expected_hash_argument"]) + self.assertTrue(declarations["conditional_checksum_options_present"]) + self.assertFalse(report["runtime_checksum_verification_executed"]) + self.assertFalse(report["archive_bytes_verified"]) + + def test_report_names_allowlist_gap_passively_and_has_stable_input_fingerprint(self): + with tempfile.TemporaryDirectory() as directory: + repo = Path(directory) + config = repo / MODULE.CONFIG_PATH + config.parent.mkdir(parents=True) + config.write_text(f"import cfg from 'react-native-config'; cfg.RELAY; cfg.GASFREE_API_KEY; const value='{PRIVATE_VALUE}';") + (repo / "android").mkdir() + (repo / "package.json").write_text("{}") + (repo / "yarn.lock").write_text(f'realm@12.15.0:\n resolved "https://example.invalid/realm.tgz"\n integrity {SRI}\n') + inputs = repo / "inputs.json" + inputs.write_text(json.dumps({"environment_names": ["RELAY"], "yarn_lock_sha256": MODULE.sha256(repo / "yarn.lock")})) + first = MODULE.audit(repo, inputs) + second = MODULE.audit(repo, inputs) + self.assertEqual(first["configuration"]["used_names_outside_allowlist"], ["GASFREE_API_KEY"]) + self.assertTrue(first["chosen_manifest_yarn_hash_matches"]) + self.assertEqual(first["source_input_fingerprint_sha256"], second["source_input_fingerprint_sha256"]) + self.assertNotIn(PRIVATE_VALUE, json.dumps(first)) + config.write_text(config.read_text() + "\n// change\n") + self.assertNotEqual(first["source_input_fingerprint_sha256"], MODULE.audit(repo, inputs)["source_input_fingerprint_sha256"]) + + def test_cli_read_failure_does_not_export_private_path(self): + stderr = io.StringIO() + with patch("sys.argv", [str(SCRIPT), "--repo", f"/missing/{PRIVATE_VALUE}"]), contextlib.redirect_stderr(stderr): + self.assertEqual(MODULE.main(), 1) + self.assertNotIn(PRIVATE_VALUE, stderr.getvalue()) + + +if __name__ == "__main__": + unittest.main() diff --git a/reproducibility/test_inspect_apk_container.py b/reproducibility/test_inspect_apk_container.py new file mode 100644 index 0000000000..fccdf4b07e --- /dev/null +++ b/reproducibility/test_inspect_apk_container.py @@ -0,0 +1,285 @@ +import hashlib +import io +import json +from importlib.util import module_from_spec, spec_from_file_location +from pathlib import Path +import struct +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch +import warnings +from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile, ZipInfo + + +SCRIPT = Path(__file__).with_name("inspect-apk-container.py") +SPEC = spec_from_file_location("inspect_apk_container", SCRIPT) +MODULE = module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) +V2 = 0x7109871A +SDK = 0x504B4453 +PADDING = 0x42726577 +DEFAULT_PAIRS = [(V2, b"synthetic-signature"), (SDK, b"encrypted-sdk-data")] + + +class NonSeekable(io.BytesIO): + def seek(self, *args): + raise io.UnsupportedOperation("seek") + + +def zip_bytes(entries=None, compression=ZIP_STORED, date=(2026, 10, 12, 0, 0, 0), + comment=b"", extra=b"", descriptor=False): + buffer = NonSeekable() if descriptor else io.BytesIO() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + with ZipFile(buffer, "w") as archive: + archive.comment = comment + for name, value in entries or [("classes.dex", b"synthetic-dex")]: + info = ZipInfo(name, date) + info.compress_type = compression + info.extra = extra + archive.writestr(info, value) + return buffer.getvalue() + + +def apk_bytes(pairs=DEFAULT_PAIRS, **kwargs): + data = zip_bytes(**kwargs) + if pairs is None: + return data + eocd = data.rfind(MODULE.EOCD_MAGIC) + cd_offset = struct.unpack_from("