diff --git a/.github/release-signing-sha256.txt b/.github/release-signing-sha256.txt new file mode 100644 index 0000000..05cee3a --- /dev/null +++ b/.github/release-signing-sha256.txt @@ -0,0 +1 @@ +73ab85c428aae3e50152ed2837d6f090a3f1ed97a227e257b73b720e16693ae1 diff --git a/.github/scripts/check-release-apk.sh b/.github/scripts/check-release-apk.sh index 22e9d4f..a9ceecd 100644 --- a/.github/scripts/check-release-apk.sh +++ b/.github/scripts/check-release-apk.sh @@ -1,44 +1,28 @@ #!/usr/bin/env bash -# Verify the published baseline, and optionally compare a new signed APK to it. +# Check package, version and the owner-selected public signing certificate. set -euo pipefail -baseline=$1 -candidate=${2:-} -expected_code=${3:-} +candidate=$1 +expected_code=$2 +certificate_file=$3 +[[ "$expected_code" =~ ^[1-9][0-9]*$ ]] || { echo "Invalid expected version code" >&2; exit 1; } +test -s "$candidate" && test -s "$certificate_file" || { echo "Missing APK or certificate pin" >&2; exit 1; } +expected=$(tr -d '\r\n' < "$certificate_file") +[[ "$expected" =~ ^[0-9a-f]{64}$ ]] || { echo "Invalid signing certificate pin" >&2; exit 1; } aapt=$(find "$ANDROID_HOME/build-tools" -name aapt -type f | sort -V | tail -n 1) apksigner=$(find "$ANDROID_HOME/build-tools" -name apksigner -type f | sort -V | tail -n 1) test -n "$aapt" && test -n "$apksigner" || { echo "Android build tools missing" >&2; exit 1; } -test -s "$baseline" || { echo "Baseline APK is missing" >&2; exit 1; } -metadata=$("$aapt" dump badging "$baseline" | sed -n '1p') -if [[ "$metadata" != *"name='com.gothwad.computer'"* || "$metadata" != *"versionCode='20'"* ]]; then - echo "Unexpected package or version code in v1.0.20; investigate upgrade history." >&2 +metadata=$("$aapt" dump badging "$candidate" | sed -n '1p') +if [[ "$metadata" != *"name='com.gothwad.computer'"* || "$metadata" != *"versionCode='$expected_code'"* ]]; then + echo "Candidate package or version code is incorrect" >&2 exit 1 fi -certificates() { - local output certs - if ! output=$("$apksigner" verify --print-certs "$1" 2>&1); then - echo "APK signature verification failed: $output" >&2 - return 1 - fi - certs=$(printf '%s\n' "$output" | sed -nE 's/^(Signer #[0-9]+|V[0-9.]+ Signer): certificate SHA-256 digest: ([0-9a-fA-F]+)$/\2/p' | sort -u) - if [[ -z "$certs" ]]; then - echo "No signing certificate found; verifier output: $output" >&2 - return 1 - fi - printf '%s\n' "$certs" -} -baseline_certs=$(certificates "$baseline") -if [[ -n "$candidate" ]]; then - test -s "$candidate" - metadata=$("$aapt" dump badging "$candidate" | sed -n '1p') - [[ "$expected_code" =~ ^[1-9][0-9]*$ ]] || { echo "Missing expected version code" >&2; exit 1; } - if [[ "$metadata" != *"name='com.gothwad.computer'"* || "$metadata" != *"versionCode='$expected_code'"* ]]; then - echo "Candidate package or version code is incorrect" >&2 - exit 1 - fi - candidate_certs=$(certificates "$candidate") - if [[ -z "$candidate_certs" || "$candidate_certs" != "$baseline_certs" ]]; then - echo "Release APK signing certificate differs from v1.0.20; refusing to publish." >&2 - exit 1 - fi +if ! output=$("$apksigner" verify --print-certs "$candidate" 2>&1); then + echo "APK signature verification failed: $output" >&2 + exit 1 +fi +certs=$(printf '%s\n' "$output" | sed -nE 's/^(Signer #[0-9]+|V[0-9.]+ Signer:?) certificate SHA-256 digest: ([0-9a-fA-F]+)$/\2/p' | tr '[:upper:]' '[:lower:]' | sort -u) +if [[ -z "$certs" || "$certs" != "$expected" ]]; then + echo "Signed APK does not match the owner-selected release certificate; refusing to publish." >&2 + exit 1 fi -echo "Release APK baseline verification passed." +echo "APK package, version and release signing certificate verified." diff --git a/.github/scripts/tests/test_release_apk.py b/.github/scripts/tests/test_release_apk.py new file mode 100644 index 0000000..7ab8d8d --- /dev/null +++ b/.github/scripts/tests/test_release_apk.py @@ -0,0 +1,56 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().parents[1] / 'check-release-apk.sh' +PIN = '73ab85c428aae3e50152ed2837d6f090a3f1ed97a227e257b73b720e16693ae1' + + +class ReleaseApkTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + root = Path(self.tmp.name) + tools = root / 'sdk' / 'build-tools' / '35.0.0' + tools.mkdir(parents=True) + for name, body in { + 'aapt': 'printf "%s\\n" "$FAKE_BADGING"', + 'apksigner': 'printf "%s\\n" "$FAKE_CERT"; exit "${FAKE_VERIFY_EXIT:-0}"', + }.items(): + tool = tools / name + tool.write_text('#!/usr/bin/env bash\n' + body + '\n') + tool.chmod(0o755) + self.apk = root / 'release.apk' + self.apk.write_text('fake') + self.pin = root / 'pin.txt' + self.pin.write_text(PIN + '\n') + self.env = dict(os.environ, ANDROID_HOME=str(root / 'sdk'), + FAKE_BADGING="package: name='com.gothwad.computer' versionCode='21' versionName='1.0.21'", + FAKE_CERT=f'V3.0 Signer: certificate SHA-256 digest: {PIN}') + + def run_check(self, **updates): + return subprocess.run(['bash', str(SCRIPT), str(self.apk), '21', str(self.pin)], + env={**self.env, **updates}, capture_output=True, text=True) + + def test_selected_certificate_and_package(self): + self.assertEqual(self.run_check().returncode, 0) + self.assertEqual(self.run_check(FAKE_CERT=f'Signer #1 certificate SHA-256 digest: {PIN.upper()}').returncode, 0) + + def test_rejects_other_or_missing_certificates(self): + for output in ['V3.0 Signer: certificate SHA-256 digest: ' + 'a' * 64, '', + f'V3.0 Signer: certificate SHA-256 digest: {PIN}\nV2.0 Signer: certificate SHA-256 digest: ' + 'b' * 64]: + with self.subTest(output=output): + self.assertNotEqual(self.run_check(FAKE_CERT=output).returncode, 0) + self.assertNotEqual(self.run_check(FAKE_VERIFY_EXIT='1').returncode, 0) + + def test_rejects_wrong_package_version_and_pin(self): + self.assertNotEqual(self.run_check(FAKE_BADGING="package: name='other' versionCode='21'").returncode, 0) + self.assertNotEqual(self.run_check(FAKE_BADGING="package: name='com.gothwad.computer' versionCode='20'").returncode, 0) + self.pin.write_text('invalid\n') + self.assertNotEqual(self.run_check().returncode, 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/workflows/build_apk.yml b/.github/workflows/build_apk.yml index 5c9aa07..8f1f9a9 100644 --- a/.github/workflows/build_apk.yml +++ b/.github/workflows/build_apk.yml @@ -5,6 +5,10 @@ on: branches: [main] workflow_dispatch: inputs: + dry_run: + description: 'Build and sign without publishing (required outside main)' + type: boolean + default: false version_name: description: 'Version Name (e.g. 1.0.6 - leave empty for auto 1.0.X)' required: false @@ -19,7 +23,7 @@ permissions: jobs: validate: - if: github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main' + if: github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main' || inputs.dry_run uses: ./.github/workflows/ci.yml permissions: contents: read @@ -178,15 +182,12 @@ jobs: rm -f "$KS_PATH" echo "Keystore securely cleaned up." - - name: Verify upgrade signing against v1.0.20 + - name: Verify package, version and release signing certificate env: - GH_TOKEN: ${{ github.token }} V_NAME: ${{ steps.versioning.outputs.v_name }} V_CODE: ${{ steps.versioning.outputs.v_code }} run: | - mkdir -p release-baseline - gh release download v1.0.20 --pattern 'GothwadComputer-v1.0.20-Release.apk' --dir release-baseline - bash .github/scripts/check-release-apk.sh release-baseline/GothwadComputer-v1.0.20-Release.apk "output_release/GothwadComputer-v${V_NAME}-Release.apk" "$V_CODE" + bash .github/scripts/check-release-apk.sh "output_release/GothwadComputer-v${V_NAME}-Release.apk" "$V_CODE" .github/release-signing-sha256.txt - name: Upload Signed Release APK, Debug APK & AAB Artifacts uses: actions/upload-artifact@v7 @@ -195,6 +196,7 @@ jobs: path: output_release/ - name: Create Automatic GitHub Release + if: github.event_name != 'workflow_dispatch' || !inputs.dry_run uses: softprops/action-gh-release@v3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -206,6 +208,8 @@ jobs: draft: false prerelease: false generate_release_notes: true + body: | + **Signing key change:** This release uses a different signing key from v1.0.20. Android may reject an in-place update from v1.0.20; uninstalling the old app can delete its local data. Back up data first and verify recovery on a test device. Keep an alternate launcher installed. files: | output_release/GothwadComputer-v${{ steps.versioning.outputs.v_name }}-Release.apk output_release/GothwadComputer-v${{ steps.versioning.outputs.v_name }}-Debug.apk diff --git a/.github/workflows/release-validation.yml b/.github/workflows/release-validation.yml index af19770..4355639 100644 --- a/.github/workflows/release-validation.yml +++ b/.github/workflows/release-validation.yml @@ -9,6 +9,7 @@ on: - '.github/workflows/release-validation.yml' - '.github/scripts/release_version.py' - '.github/scripts/check-release-apk.sh' + - '.github/release-signing-sha256.txt' - '.github/scripts/tests/**' push: branches: ['arena/**'] @@ -19,6 +20,7 @@ on: - '.github/workflows/release-validation.yml' - '.github/scripts/release_version.py' - '.github/scripts/check-release-apk.sh' + - '.github/release-signing-sha256.txt' - '.github/scripts/tests/**' permissions: @@ -44,30 +46,12 @@ jobs: GH_TOKEN: ${{ github.token }} run: python3 .github/scripts/release_version.py - baseline: - name: Inspect existing v1.0.20 APK + signature_tests: + name: Test release signing checks runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - - name: Download and inspect existing release (read only) - env: - GH_TOKEN: ${{ github.token }} - run: | - mkdir -p release-baseline - set +e - { - gh release download v1.0.20 --pattern 'GothwadComputer-v1.0.20-Release.apk' --dir release-baseline && - bash .github/scripts/check-release-apk.sh release-baseline/GothwadComputer-v1.0.20-Release.apk - } > baseline.log 2>&1 - result=$? - cat baseline.log - if [ "$result" -ne 0 ]; then - python3 - <<'PYCODE' - from pathlib import Path - text = Path('baseline.log').read_text(errors='replace')[:4000] - print('::error::' + text.replace('%', '%25').replace('\r', '%0D').replace('\n', '%0A')) - PYCODE - fi - exit "$result" + - name: Test certificate, package and version guards + run: python3 -m unittest discover -s .github/scripts/tests -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08c2da7..4cbd915 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -163,15 +163,12 @@ jobs: rm -f "$KS_PATH" echo "Keystore securely cleaned up." - - name: Verify upgrade signing against v1.0.20 + - name: Verify package, version and release signing certificate env: - GH_TOKEN: ${{ github.token }} V_NAME: ${{ steps.versioning.outputs.v_name }} V_CODE: ${{ steps.versioning.outputs.v_code }} run: | - mkdir -p release-baseline - gh release download v1.0.20 --pattern 'GothwadComputer-v1.0.20-Release.apk' --dir release-baseline - bash .github/scripts/check-release-apk.sh release-baseline/GothwadComputer-v1.0.20-Release.apk "release_out/GothwadComputer-v${V_NAME}-Release.apk" "$V_CODE" + bash .github/scripts/check-release-apk.sh "release_out/GothwadComputer-v${V_NAME}-Release.apk" "$V_CODE" .github/release-signing-sha256.txt - name: Upload Release Artifacts uses: actions/upload-artifact@v7 @@ -191,6 +188,8 @@ jobs: draft: false prerelease: false generate_release_notes: true + body: | + **Signing key change:** This release uses a different signing key from v1.0.20. Android may reject an in-place update from v1.0.20; uninstalling the old app can delete its local data. Back up data first and verify recovery on a test device. Keep an alternate launcher installed. files: | release_out/GothwadComputer-v${{ steps.versioning.outputs.v_name }}-Release.apk release_out/GothwadComputer-v${{ steps.versioning.outputs.v_name }}-Debug.apk diff --git a/README.md b/README.md index f7929ac..7bc80e3 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ Debug output: `app/build/outputs/apk/debug/`. Build release artifacts with: sh ./gradlew assembleRelease bundleRelease ``` +**Signing-key change:** the owner reports that v1.0.20 used an incorrect signing key. New releases use the corrected key and may not upgrade over v1.0.20 in place. Uninstalling can erase local app data: back up first, test migration, and keep an alternate Home installed. + Release builds are unsigned by default. For local testing only, `-PlocalSign` uses a debug signing key; do **not** distribute that as a production release. `app/build.gradle.kts` also supports CI signing with `KEYSTORE_FILE`, `KEYSTORE_PASSWORD`, `KEY_ALIAS` and `KEY_PASSWORD`. The GitHub workflows instead build and sign in a separate step using repository secrets; see the [CI section](docs/PROJECT_ANALYSIS.md#build-test-aur-ci). ## Documentation diff --git a/docs/GITHUB_AUTOMATION.md b/docs/GITHUB_AUTOMATION.md index ec13783..92d8d6a 100644 --- a/docs/GITHUB_AUTOMATION.md +++ b/docs/GITHUB_AUTOMATION.md @@ -28,5 +28,5 @@ PR jobs use `pull_request` rather than `pull_request_target`, do not use release - On every push to `main`, the release workflow calls Android CI (build, unit tests, lint and API 21/29/34 emulator smoke tests). If validation or signing fails, no release should be published. The publication job refuses an outdated `main` commit if the branch has already moved on when it starts; inspect failures and rerun the latest commit as needed. - Version selection inspects existing tags and GitHub Releases and chooses the next `v1.0.N`, using `N` as Android `versionCode`. The latest observed release was `v1.0.20`/code 20; with no intervening tags/releases the next would be `v1.0.21`/code 21. Explicit manual versions must use `1.0.N` with matching code and exceed existing version tags. An existing release is never deliberately reused. Non-`v1.0.N` version tags make allocation fail closed until version history is reviewed. This convention assumes earlier release codes match their tag suffixes; independently verify any release created outside these workflows. - Both release jobs use the same GitHub concurrency group and a bounded queue (up to 100 waiting jobs). Queue overflow, CI errors, tags created outside these workflows and platform outages can prevent a release; inspect the Actions tab rather than assuming publication succeeded. Tag-triggered releases must use a new `v1.0.N` tag newer than all other version tags. Manual runs are restricted to `main`. -- Android release signing requires existing repository signing secrets. Before publishing, the workflows compare the signed APK certificate and package to the v1.0.20 APK and check version codes; inspect the APK/AAB, test actual upgrade and real devices, and keep an alternate Home. The CI debug APK uses a debug key and may not install as an update to the release app. This compares with v1.0.20 only; it does not prove upgrade compatibility from other sources, validate OEM behavior or guarantee safety. -- The PR dry-run exercises the reusable CI gate and version allocator with read-only access, and never publishes or signs. An actual end-to-end signing/publication test only occurs when a release workflow runs with secrets. +- Android release signing uses repository signing secrets. Per the owner’s correction, v1.0.20 used an incorrect signing key. The owner-approved current public signing certificate SHA-256 is pinned in `.github/release-signing-sha256.txt`; releases fail if the APK signature, application ID or version code does not match. This public fingerprint is not the private key. Treat changes to the pin as security-sensitive and verify with the owner. The current key differs from v1.0.20: an in-place update from it will be rejected unless Android has a compatible signing lineage. Uninstalling can delete local app data; back up first and test migration. Keep an alternate Home and test on real devices. +- The PR dry-run exercises the reusable CI gate, version allocator and signing-guard tests with read-only access. The build workflow also supports a manually dispatched `dry_run` on a branch: it signs and verifies using repository secrets, uploads build artifacts, and does not publish. Actual release publication occurs on `main` after successful validation/signing; verify the first run and assets. diff --git a/docs/REMAINING_RELEASE_WORK.md b/docs/REMAINING_RELEASE_WORK.md index 0826b8f..2f12479 100644 --- a/docs/REMAINING_RELEASE_WORK.md +++ b/docs/REMAINING_RELEASE_WORK.md @@ -16,5 +16,5 @@ This branch is not yet release-ready. The phase gates in `task.md` are authorita - A limited per-device foreground shortcut editor is available under System > Keyboard & remote shortcuts: assign Start, Search or Quick settings using Ctrl + letter/digit, F1–F12 or remote colour keys. No bindings are set by default; conflicts are rejected and the editor can view or clear all mappings. Shortcuts are ignored in text/web input, recovery, lock, popups and floating windows. Android/OEM may not deliver some keys. Individual edit/removal, wider action coverage, real-device tests and optional global shortcuts remain incomplete. Legacy `buttonMap` is preserved, not migrated. No accessibility service is installed; any future service must be explicitly enabled, optional and policy-reviewed. - Complete the Phase 4 audit: launcher app-lock coverage, plaintext credential migration, notification/overlay paths, backups, WebView/store bridge security, storage access, privacy and upgrade/rollback testing. Launcher locks are not Android system security. - Validate Phase 1–5 acceptance gates on representative real Android TV and tablet devices with remote, touch, keyboard and mouse; test Home selection/rollback, reboot, recovery, permissions, loss-of-focus, low memory and OEM variations. Record named devices, software versions and results. -- A `main` push automatically publishes after CI and signing succeed; a `v*` tag or manual dispatch can also publish. The release workflows share version selection and a queue but signing, historical version codes and upgrade compatibility have not been verified end to end. See `GITHUB_AUTOMATION.md` before merging or releasing; the merge itself will trigger a release. +- A `main` push automatically publishes after CI and signing succeed; a `v*` tag or manual dispatch can also publish. The release workflows share version selection, a signing-certificate pin and a queue. The owner-selected key differs from v1.0.20, so ordinary in-place upgrade from that release will not work without a compatible signing lineage; uninstalling may delete local data. Migration and device testing remain open. See `GITHUB_AUTOMATION.md` before merging or releasing; the merge itself will trigger a release. - Agree and measure startup, input, frame and memory budgets; run sustained stress/soak tests. Review the outstanding lint warnings and release lint; confirm dependencies, release workflows, signing and upgrade from the previous signed version. The debug APK is not a signed release candidate.