diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..10dac30f4 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +scripts/check-secrets.py --staged diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 000000000..4303630e3 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,17 @@ +#!/bin/sh +set -eu + +tmp=$(mktemp "${TMPDIR:-/tmp}/inbe-pre-push.XXXXXX") +trap 'rm -f "$tmp"' EXIT +cat > "$tmp" + +if command -v git-lfs >/dev/null 2>&1; then + git lfs pre-push "$@" < "$tmp" +elif git lfs version >/dev/null 2>&1; then + git lfs pre-push "$@" < "$tmp" +else + printf '%s\n' "This repository uses Git LFS, but git-lfs is not available." >&2 + exit 2 +fi + +scripts/check-secrets.py --pre-push "$@" < "$tmp" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4be5d34bf..a9246a26a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,21 @@ concurrency: cancel-in-progress: true jobs: + secret-scan: + name: Secret Scan + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Scan Tracked Files and History + run: | + set -euo pipefail + python3 scripts/check-secrets.py --working-tree + python3 scripts/check-secrets.py --history + guard-submodule-urls: name: Submodule URLs are public HTTPS runs-on: ubuntu-latest @@ -41,7 +56,9 @@ jobs: test: name: Test runs-on: ubuntu-latest - needs: guard-submodule-urls + needs: + - guard-submodule-urls + - secret-scan timeout-minutes: 60 env: APT_CACHE_DIR: /tmp/apt-cache diff --git a/.github/workflows/publish-openstore.yml b/.github/workflows/publish-openstore.yml index 35a862b7a..edec163c9 100644 --- a/.github/workflows/publish-openstore.yml +++ b/.github/workflows/publish-openstore.yml @@ -39,6 +39,12 @@ jobs: fetch-depth: 0 lfs: true + - name: Scan Tracked Files and History + run: | + set -euo pipefail + python3 scripts/check-secrets.py --working-tree + python3 scripts/check-secrets.py --history + - name: Install build dependencies run: | sudo dpkg --add-architecture arm64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af85b8b5c..b59210362 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,9 +14,25 @@ concurrency: cancel-in-progress: true jobs: + secret-scan: + name: Secret Scan + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Scan Tracked Files and History + run: | + set -euo pipefail + python3 scripts/check-secrets.py --working-tree + python3 scripts/check-secrets.py --history + test: name: Test runs-on: ubuntu-latest + needs: secret-scan timeout-minutes: 60 env: APT_CACHE_DIR: /tmp/apt-cache @@ -687,6 +703,11 @@ jobs: mkdir -p ~/.android echo "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore + - name: Prepare Firebase config + env: + GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} + run: ./scripts/write-google-services-json.sh + - name: Copy Android Assets run: ./scripts/copy-android-assets.sh @@ -719,21 +740,24 @@ jobs: echo "Could not read INBE_VERSION_STRING" exit 1 fi - cp "build/android/inbe-$VERSION.apk" build/release/android/ - for abi in arm64-v8a armeabi-v7a x86 x86_64; do - split="build/android/inbe-$VERSION-$abi.apk" - if [ ! -f "$split" ]; then - echo "Missing split APK: $split" + for flavor in fdroid gplay; do + apk="build/android/inbe-$VERSION-$flavor.apk" + if [ ! -f "$apk" ]; then + echo "Missing universal APK: $apk" exit 1 fi - cp "$split" build/release/android/ + cp "$apk" build/release/android/ + for abi in arm64-v8a armeabi-v7a x86 x86_64; do + split="build/android/inbe-$VERSION-$flavor-$abi.apk" + if [ ! -f "$split" ]; then + echo "Missing split APK: $split" + exit 1 + fi + cp "$split" build/release/android/ + done done - aab="$(find droid/app/build/outputs/bundle/release build/android -type f -name '*.aab' | head -n 1)" - if [ -z "$aab" ]; then - echo "No release AAB was produced" - exit 1 - fi - cp "$aab" "build/release/android/inbe-$VERSION.aab" + cp "build/android/inbe-$VERSION-fdroid.aab" build/release/android/ + cp "build/android/inbe-$VERSION-gplay.aab" build/release/android/ - name: Upload Android Artifacts uses: actions/upload-artifact@v4 @@ -952,7 +976,7 @@ jobs: VERSION="${{ needs.release.outputs.version }}" web_zip="build/release/inbe-web.zip" - android_apk="build/release/inbe-$VERSION.apk" + android_apk="build/release/inbe-$VERSION-fdroid.apk" windows_zip="build/release/inbe-windows.zip" linux_appimage="build/release/inbe-linux-x86_64.AppImage" @@ -1025,7 +1049,7 @@ jobs: with: serviceAccountJsonPlainText: ${{ secrets.PLAY_STORE_JSON_KEY }} packageName: xyz.waozi.inbe - releaseFiles: build/release/android/*.aab + releaseFiles: build/release/android/inbe-${{ needs.release.outputs.version }}-gplay.aab track: production status: completed @@ -1075,7 +1099,7 @@ jobs: - name: Upload APK to Amazon Appstore if: steps.amazon_secrets.outputs.configured == 'true' env: - AMAZON_RELEASE_FILE: build/release/android/inbe-${{ needs.release.outputs.version }}.apk + AMAZON_RELEASE_FILE: build/release/android/inbe-${{ needs.release.outputs.version }}-fdroid.apk run: | set -euo pipefail if ! node scripts/upload-amazon-appstore.mjs; then diff --git a/.gitignore b/.gitignore index 2afb5503c..09a03eb25 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ social-posts.local.json /main !droid/app/src/main droid/app/src/main/assets +droid/app/src/gplay/google-services.json droid/*.apk droid/*.aab diff --git a/Makefile b/Makefile index 272679333..05f5b722b 100644 --- a/Makefile +++ b/Makefile @@ -548,7 +548,7 @@ MEDITATION_AUDIO_TRACKS := \ include $(KRYON_DIR)/mk/package-freebsd.mk .PHONY: web-canvas web-canvas-smoke-test web-compare-test web-side-by-side-test all native kryon-host install install-user uninstall stage package-freebsd deb package-deb deb-check rpm package-rpm rpm-check snap package-snap snap-cache-clean flatpak package-flatpak podman-check validate-desktop run tui run-tui run-termi run-termi-direct run-fresh screenshot test ci dist appimage click click-verify vendor-prebuilds vendor-prebuilds-native vendor-prebuilds-web vendor-prebuilds-windows font-subsets font-bundle-check clean clean-linux clean-native clean-vendor-builds windows-setup windows-setup-check android-avd android-audio-e2e android-check-keystore android-copy-assets android-copy-debug-apks android-copy-release-apks android-copy-bundle android-smoke android-local-properties android-debug android-release android-bundle android-install android-install-release android-clean android-rebuild validate-meditation-audio package-unpackaged-assets windows-runtime-assets-check windows windows64 windows32 web web-tools-check web-smoke-test web-smoke-test-firefox web-smoke-test-librewolf site site-release-assets-check chrome-web-store chrome-web-store-test firefox-addons firefox-addons-lint firefox-addons-source-zip verify-firefox-addons sync-web-icons social-install social-login social-draft social-x-draft social-post social-x-post social-x-post-dry-run social-post-dry-run -.PHONY: no-vendor-edits test-tui-screenshot test-termi-screenshot test-termi-screenshot-direct +.PHONY: no-vendor-edits secret-check secret-check-history hooks-install test-tui-screenshot test-termi-screenshot test-termi-screenshot-direct .NOTPARALLEL: dist windows windows64 windows32 android-release android-bundle click deb package-deb rpm package-rpm snap package-snap flatpak package-flatpak all: native @@ -709,10 +709,19 @@ test-desktop-windows: no-vendor-edits: bash ./scripts/check-no-vendor-edits.sh +secret-check: + python3 ./scripts/check-secrets.py --working-tree + +secret-check-history: + python3 ./scripts/check-secrets.py --history + +hooks-install: + sh ./scripts/install-git-hooks.sh + embedded-image-assets-check: $(EMBEDDED_ASSETS_C) bash ./tests/embedded_image_assets_test.sh -test: no-vendor-edits $(TESTS) font-bundle-check audio-test-fixture-check embedded-image-assets-check +test: no-vendor-edits secret-check $(TESTS) font-bundle-check audio-test-fixture-check embedded-image-assets-check bash ./tests/screenshot_scene_test.sh echo "== Inbe tests =="; \ status=0; \ @@ -1548,21 +1557,21 @@ android-copy-release-apks: | $(ANDROID_BUILD_DIR) echo "Could not read INBE_VERSION_STRING from $(VERSION_FILE)"; \ exit 1; \ fi; \ - universal="$$(find droid/app/build/outputs/apk -path '*/release/*' -name '*universal*release*.apk' | head -n 1)"; \ - if [ -z "$$universal" ]; then universal="$$(find droid/app/build/outputs/apk -path '*/release/*' -name '*release*.apk' | head -n 1)"; fi; \ - if [ -z "$$universal" ]; then \ - echo "No release APK was available for versioned copy"; \ - exit 1; \ - fi; \ - cp "$$universal" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION).apk"; \ - cp "$$universal" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-latest.apk"; \ - for abi in arm64-v8a armeabi-v7a x86 x86_64; do \ - split="$$(find droid/app/build/outputs/apk -path '*/release/*' -name "app-*$$abi-release*.apk" | head -n 1)"; \ - if [ -z "$$split" ] || [ ! -f "$$split" ]; then \ - echo "No release APK was produced for ABI $$abi"; \ + for flavor in fdroid gplay; do \ + universal="$$(find droid/app/build/outputs/apk -path '*/release/*' -name "app-$$flavor-universal-release*.apk" | head -n 1)"; \ + if [ -z "$$universal" ] || [ ! -f "$$universal" ]; then \ + echo "No $$flavor universal release APK was produced"; \ exit 1; \ fi; \ - cp "$$split" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-$$abi.apk"; \ + cp "$$universal" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-$$flavor.apk"; \ + for abi in arm64-v8a armeabi-v7a x86 x86_64; do \ + split="$$(find droid/app/build/outputs/apk -path '*/release/*' -name "app-$$flavor-$$abi-release*.apk" | head -n 1)"; \ + if [ -z "$$split" ] || [ ! -f "$$split" ]; then \ + echo "No $$flavor release APK was produced for ABI $$abi"; \ + exit 1; \ + fi; \ + cp "$$split" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-$$flavor-$$abi.apk"; \ + done; \ done android-copy-bundle: | $(ANDROID_BUILD_DIR) @@ -1576,6 +1585,21 @@ android-copy-bundle: | $(ANDROID_BUILD_DIR) if [ "$$found" -eq 0 ]; then \ echo "No release AAB was produced"; \ exit 1; \ + fi; \ + if [ -z "$(APP_VERSION)" ]; then \ + echo "Could not read INBE_VERSION_STRING from $(VERSION_FILE)"; \ + exit 1; \ + fi; \ + for flavor in fdroid gplay; do \ + bundle="$$(find droid/app/build/outputs/bundle -path "*$${flavor}Release*" -name "app-$$flavor-release.aab" | head -n 1)"; \ + if [ -z "$$bundle" ] || [ ! -f "$$bundle" ]; then \ + echo "No $$flavor release AAB was produced"; \ + exit 1; \ + fi; \ + cp "$$bundle" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-$$flavor.aab"; \ + done; \ + if [ -f "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-gplay.apk" ]; then \ + cp "$(ANDROID_BUILD_DIR)/$(APP_NAME)-$(APP_VERSION)-gplay.apk" "$(ANDROID_BUILD_DIR)/$(APP_NAME)-latest.apk"; \ fi android-install: android-debug diff --git a/README.md b/README.md index 5c9241e42..3cabdd694 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@

- Get it on Google Play + Get it on Google Play - Get it on F-Droid + Get it on F-Droid

diff --git a/assets/app/badge-f-droid.png b/assets/app/badge-f-droid.png new file mode 100644 index 000000000..9500c4ac0 Binary files /dev/null and b/assets/app/badge-f-droid.png differ diff --git a/assets/app/badge-f-droid.svg b/assets/app/badge-f-droid.svg deleted file mode 100644 index f58f88ed1..000000000 --- a/assets/app/badge-f-droid.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - GET IT ON - F-Droid - diff --git a/assets/app/badge-google-play.png b/assets/app/badge-google-play.png new file mode 100644 index 000000000..131f3acaa Binary files /dev/null and b/assets/app/badge-google-play.png differ diff --git a/assets/app/badge-google-play.svg b/assets/app/badge-google-play.svg deleted file mode 100644 index a33050cad..000000000 --- a/assets/app/badge-google-play.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - GET IT ON - Google Play - diff --git a/assets/app/readme-banner.png b/assets/app/readme-banner.png index 3605a4a24..d3a519faf 100644 Binary files a/assets/app/readme-banner.png and b/assets/app/readme-banner.png differ diff --git a/droid/app/src/gplay/google-services.example.json b/droid/app/src/gplay/google-services.example.json new file mode 100644 index 000000000..f19b3e760 --- /dev/null +++ b/droid/app/src/gplay/google-services.example.json @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "YOUR_FIREBASE_PROJECT_NUMBER", + "project_id": "inner-breeze", + "storage_bucket": "inner-breeze.firebasestorage.app" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "YOUR_FIREBASE_ANDROID_APP_ID", + "android_client_info": { + "package_name": "xyz.waozi.inbe" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "YOUR_FIREBASE_ANDROID_API_KEY" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} diff --git a/scripts/check-secrets.py b/scripts/check-secrets.py new file mode 100755 index 000000000..729a00fdc --- /dev/null +++ b/scripts/check-secrets.py @@ -0,0 +1,379 @@ +#!/usr/bin/env python3 +"""Scan tracked content for secrets without echoing secret values.""" + +from __future__ import annotations + +import argparse +import dataclasses +import hashlib +import math +import os +import re +import subprocess +import sys +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] +ZERO_SHA = "0" * 40 + +SKIP_PREFIXES = ( + ".git/", + ".gradle/", + ".local/", + ".secrets/", + "build/", + "node_modules/", + "tmp/", + "vendor/", + "vendor-builds/", +) + +SKIP_SUFFIXES = ( + ".a", + ".aab", + ".apk", + ".AppImage", + ".class", + ".dll", + ".dylib", + ".exe", + ".ico", + ".jar", + ".jpg", + ".jpeg", + ".keystore", + ".mp3", + ".ogg", + ".otf", + ".png", + ".so", + ".snap", + ".svgz", + ".ttf", + ".wasm", + ".wav", + ".webp", + ".zip", +) + +PLACEHOLDER_WORDS = ( + "changeme", + "dummy", + "example", + "fake", + "placeholder", + "redacted", + "replace", + "sample", + "test", + "your", +) + + +@dataclasses.dataclass(frozen=True) +class Rule: + name: str + pattern: re.Pattern[str] + min_entropy: float = 0.0 + + +@dataclasses.dataclass(frozen=True) +class Finding: + rule: str + source: str + path: str + line: int + fingerprint: str + commit: str = "" + blob: str = "" + + +RULES = ( + Rule("private-key-block", re.compile(r"-----BEGIN (?:[A-Z0-9]+ )?PRIVATE KEY-----")), + Rule("aws-access-key", re.compile(r"(?P(?:A3T[A-Z0-9]|AKIA|ASIA)[A-Z0-9]{16})")), + Rule("github-token", re.compile(r"(?Pgh[pousr]_[A-Za-z0-9_]{36,255}|github_pat_[A-Za-z0-9_]{22}_[A-Za-z0-9_]{59})")), + Rule("google-api-key", re.compile(r"(?PAIza[0-9A-Za-z_-]{35})")), + Rule("openai-api-key", re.compile(r"(?Psk-(?:proj-)?[A-Za-z0-9_-]{32,})")), + Rule("slack-token", re.compile(r"(?Pxox[baprs]-[A-Za-z0-9-]{20,})")), + Rule("stripe-secret-key", re.compile(r"(?Psk_(?:live|test)_[A-Za-z0-9]{16,})")), + Rule( + "credential-assignment", + re.compile( + r"(?i)\b(?:api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|" + r"password|passwd|private[_-]?key|secret)\b\s*[:=]\s*[\"']?" + r"(?P[A-Za-z0-9+/_=.\-]{16,})" + ), + min_entropy=3.2, + ), +) + +ALLOWED_FINDINGS = { + # Historical code/build strings that match the generic credential-assignment + # heuristic but are not committed credentials. + ("droid/app/build.gradle", "credential-assignment", "dd9958e19a3251bf"), + ("src/storage/sync_account.c", "credential-assignment", "cb92a7d64e014e24"), +} + + +def git(*args: str, input_bytes: bytes | None = None) -> bytes: + try: + return subprocess.check_output( + ["git", *args], + cwd=ROOT, + input=input_bytes, + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as exc: + raise SystemExit(f"check-secrets: git {' '.join(args)} failed") from exc + + +def is_skipped_path(path: str) -> bool: + normalized = path.replace("\\", "/").lstrip("./") + return normalized.startswith(SKIP_PREFIXES) or normalized.endswith(SKIP_SUFFIXES) + + +def is_binary(data: bytes) -> bool: + if b"\0" in data: + return True + sample = data[:4096] + if not sample: + return False + control = sum(1 for byte in sample if byte < 9 or (13 < byte < 32)) + return control / len(sample) > 0.08 + + +def entropy(value: str) -> float: + if not value: + return 0.0 + counts = {char: value.count(char) for char in set(value)} + length = len(value) + return -sum((count / length) * math.log2(count / length) for count in counts.values()) + + +def looks_like_placeholder(value: str) -> bool: + lowered = value.lower() + if value.startswith("$") or "${{" in value: + return True + if any(word in lowered for word in PLACEHOLDER_WORDS): + return True + if re.fullmatch(r"[A-Z0-9_]+", value) and "_" in value: + return True + if len(set(value)) <= 3: + return True + return False + + +def fingerprint(value: str) -> str: + return hashlib.sha256(value.encode("utf-8", "replace")).hexdigest()[:16] + + +def scan_text(data: bytes, *, source: str, path: str, commit: str = "", blob: str = "") -> list[Finding]: + if is_skipped_path(path) or is_binary(data): + return [] + text = data.decode("utf-8", "replace") + findings: list[Finding] = [] + seen: set[tuple[str, int, str]] = set() + + for line_number, line in enumerate(text.splitlines(), 1): + if len(line) > 20000: + continue + for rule in RULES: + for match in rule.pattern.finditer(line): + value = match.groupdict().get("secret") or match.group(0) + value = value.strip("\"'") + if looks_like_placeholder(value): + continue + if rule.min_entropy and entropy(value) < rule.min_entropy: + continue + key = (rule.name, line_number, fingerprint(value)) + if (path, rule.name, key[2]) in ALLOWED_FINDINGS: + continue + if key in seen: + continue + seen.add(key) + findings.append( + Finding( + rule=rule.name, + source=source, + path=path, + line=line_number, + fingerprint=key[2], + commit=commit, + blob=blob, + ) + ) + return findings + + +def staged_files() -> list[str]: + data = git("diff", "--cached", "--name-only", "--diff-filter=ACMRT", "-z") + return [path.decode("utf-8", "replace") for path in data.split(b"\0") if path] + + +def tracked_files() -> list[str]: + data = git("ls-files", "-z") + return [path.decode("utf-8", "replace") for path in data.split(b"\0") if path] + + +def scan_staged() -> list[Finding]: + findings: list[Finding] = [] + for path in staged_files(): + if is_skipped_path(path): + continue + try: + data = git("show", f":{path}") + except SystemExit: + continue + findings.extend(scan_text(data, source="staged", path=path)) + return findings + + +def scan_working_tree() -> list[Finding]: + findings: list[Finding] = [] + for path in tracked_files(): + if is_skipped_path(path): + continue + full_path = ROOT / path + if not full_path.is_file(): + continue + findings.extend(scan_text(full_path.read_bytes(), source="working-tree", path=path)) + return findings + + +def scan_git_objects(rev_args: list[str], *, source: str) -> list[Finding]: + data = git("rev-list", "--objects", *rev_args) + findings: list[Finding] = [] + seen_objects: set[tuple[str, str]] = set() + for raw_line in data.splitlines(): + parts = raw_line.split(maxsplit=1) + if len(parts) != 2: + continue + oid = parts[0].decode("ascii", "replace") + path = parts[1].decode("utf-8", "replace") + if (oid, path) in seen_objects or is_skipped_path(path): + continue + seen_objects.add((oid, path)) + if git("cat-file", "-t", oid).strip() != b"blob": + continue + blob = git("cat-file", "blob", oid) + findings.extend(scan_text(blob, source=source, path=path, blob=oid)) + return findings + + +def commits_for_args(rev_args: list[str]) -> list[str]: + if not rev_args: + return [] + data = git("rev-list", *rev_args) + return [line.decode("ascii", "replace") for line in data.splitlines() if line] + + +def commits_for_blob(blob: str) -> list[str]: + if not blob: + return [] + try: + data = git("log", "--all", f"--find-object={blob}", "--format=%H") + except SystemExit: + return [] + commits: list[str] = [] + for line in data.splitlines(): + commit = line.decode("ascii", "replace") + if commit and commit not in commits: + commits.append(commit) + return commits + + +def scan_commit(commit: str) -> list[Finding]: + findings = scan_text(git("log", "-1", "--format=%B", commit), source="commit-message", path="", commit=commit) + tree = git("ls-tree", "-r", "-z", "--full-tree", commit) + for entry in tree.split(b"\0"): + if not entry: + continue + meta, raw_path = entry.split(b"\t", 1) + mode, kind, oid = meta.decode("ascii", "replace").split() + if kind != "blob": + continue + path = raw_path.decode("utf-8", "replace") + if is_skipped_path(path): + continue + findings.extend(scan_text(git("cat-file", "blob", oid), source="commit", path=path, commit=commit, blob=oid)) + return findings + + +def scan_commits(rev_args: list[str]) -> list[Finding]: + findings: list[Finding] = [] + for commit in commits_for_args(rev_args): + findings.extend(scan_commit(commit)) + return findings + + +def pre_push_rev_args(remote: str, stdin: bytes) -> list[list[str]]: + ranges: list[list[str]] = [] + for raw_line in stdin.splitlines(): + parts = raw_line.decode("utf-8", "replace").split() + if len(parts) != 4: + continue + _local_ref, local_sha, _remote_ref, remote_sha = parts + if local_sha == ZERO_SHA: + continue + if remote_sha == ZERO_SHA: + ranges.append([local_sha, "--not", f"--remotes={remote}"]) + else: + ranges.append([f"{remote_sha}..{local_sha}"]) + return ranges + + +def report(findings: list[Finding]) -> int: + if not findings: + print("check-secrets: no candidate secrets found") + return 0 + + print(f"check-secrets: found {len(findings)} candidate secret(s); values are redacted", file=sys.stderr) + for finding in findings: + location = f"{finding.path}:{finding.line}" + details = [f"rule={finding.rule}", f"fingerprint={finding.fingerprint}"] + if finding.commit: + details.append(f"commit={finding.commit[:12]}") + if finding.blob: + details.append(f"blob={finding.blob[:12]}") + if finding.blob and not finding.commit and finding.source == "history": + commits = commits_for_blob(finding.blob) + if commits: + details.append("commits=" + ",".join(commit[:12] for commit in commits[:5])) + if len(commits) > 5: + details.append(f"commit_count={len(commits)}") + print(f" {location} ({', '.join(details)})", file=sys.stderr) + return 1 + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + mode = parser.add_mutually_exclusive_group(required=True) + mode.add_argument("--staged", action="store_true", help="scan files staged for commit") + mode.add_argument("--working-tree", action="store_true", help="scan tracked files in the working tree") + mode.add_argument("--history", action="store_true", help="scan every reachable historical blob") + mode.add_argument("--commits", nargs="+", metavar="REV", help="scan every commit in the given rev-list arguments") + mode.add_argument("--pre-push", action="store_true", help="scan commits read from git pre-push stdin") + parser.add_argument("hook_args", nargs="*", help=argparse.SUPPRESS) + args = parser.parse_args() + + os.chdir(ROOT) + if args.staged: + findings = scan_staged() + elif args.working_tree: + findings = scan_working_tree() + elif args.history: + findings = scan_git_objects(["--all"], source="history") + elif args.commits: + findings = scan_commits(args.commits) + else: + remote = args.hook_args[0] if args.hook_args else "origin" + ranges = pre_push_rev_args(remote, sys.stdin.buffer.read()) + findings = [] + for rev_args in ranges: + findings.extend(scan_commits(rev_args)) + return report(findings) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/install-git-hooks.sh b/scripts/install-git-hooks.sh new file mode 100755 index 000000000..dfd8dbd43 --- /dev/null +++ b/scripts/install-git-hooks.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +repo_root=$(git rev-parse --show-toplevel) +cd "$repo_root" + +git config core.hooksPath .githooks +printf '%s\n' "Installed versioned git hooks from .githooks" diff --git a/scripts/list-expected-release-assets.sh b/scripts/list-expected-release-assets.sh index 4aaf911fc..6d3eb76af 100755 --- a/scripts/list-expected-release-assets.sh +++ b/scripts/list-expected-release-assets.sh @@ -16,12 +16,18 @@ if [ -z "$version" ]; then fi cat < "$out" +elif [ -n "${GOOGLE_SERVICES_JSON:-}" ]; then + printf '%s\n' "$GOOGLE_SERVICES_JSON" > "$out" +elif [ -f "$out" ]; then + exit 0 +else + printf '%s\n' "Missing GOOGLE_SERVICES_JSON or GOOGLE_SERVICES_JSON_BASE64 for $out" >&2 + exit 1 +fi + +python3 -m json.tool "$out" >/dev/null diff --git a/site/index.html b/site/index.html index c58bc637a..6f5f4e066 100644 --- a/site/index.html +++ b/site/index.html @@ -127,8 +127,9 @@ diff --git a/src/app/app.c b/src/app/app.c index 1cb68f652..e18657ae3 100644 --- a/src/app/app.c +++ b/src/app/app.c @@ -172,7 +172,7 @@ app_bitcoin_trocador_url(void) "&address=bc1qxzcetg50f6epgddc09n82xqn3zswlmk44235y5" "&donation=True&simple_mode=True&amount=0.001&name=Inner+Breeze" "&email=waotzi@proton.me&ticker_from=btc&network_from=Mainnet" - "&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff"; + "&buttonbgcolor=23657d&textcolor=fffdf8&bgcolor=f3f1eaff"; } const char * @@ -182,7 +182,7 @@ app_monero_trocador_url(void) "&address=86CbC3d4a2GhT9auh6X99JhmhTMFKVVk8Q9cLrKTHkBu8LLkoNWgkBeAT3YZrvDM6NczYe8brUJNsTiFmwpWDZYnFG5kzSH" "&donation=True&simple_mode=True&amount=0.1&name=Inner+Breeze" "&email=waotzi@proton.me&ticker_from=xmr&network_from=Mainnet" - "&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff"; + "&buttonbgcolor=23657d&textcolor=fffdf8&bgcolor=f3f1eaff"; } const char * @@ -1694,18 +1694,30 @@ app_donation_address_box_height(const char *address, int w, int font, return UIGetNodeHeight(UINodeReadonlyTextBox(props)); } +static int app_donation_button_stack(int w); + static int app_donation_coin_section_height(const char *address, int w) { int label_font = GetUIFontSize(); int address_font = GetUISmallFontSize(); + int pad = ScaleUIPx(12); int button_h = ScaleUIPx(36); + int gap = ScaleUIPx(8); + int content_w = w - pad * 2; + int action_h = button_h; - return TextLineHeight(label_font) + + if(content_w < ScaleUIPx(120)) + content_w = ScaleUIPx(120); + if(app_donation_button_stack(content_w)) + action_h = button_h * 3 + gap * 2; + + return pad + + TextLineHeight(label_font) + ScaleUIPx(6) + - app_donation_address_box_height(address, w, address_font, + app_donation_address_box_height(address, content_w, address_font, app_donation_address_style()) + - ScaleUIPx(8) + button_h + ScaleUIPx(18); + ScaleUIPx(10) + action_h + pad; } static char app_donation_bitcoin_text[96]; @@ -1716,6 +1728,13 @@ static int app_donation_bitcoin_focused; static int app_donation_monero_focused; static int app_donation_bitcoin_scroll; static int app_donation_monero_scroll; +static int app_donation_modal_scroll; + +static int +app_donation_button_stack(int w) +{ + return w < ScaleUIPx(330); +} static void app_draw_donation_coin_section(const char *label, const char *address, @@ -1731,9 +1750,15 @@ app_draw_donation_coin_section(const char *label, const char *address, { int label_font = GetUIFontSize(); int address_font = GetUISmallFontSize(); + int pad = ScaleUIPx(12); int button_h = ScaleUIPx(36); int gap = ScaleUIPx(8); - int button_w = (w - gap * 2) / 3; + int content_x = x + pad; + int content_w = w - pad * 2; + int button_w = (content_w - gap * 2) / 3; + int stack_buttons = app_donation_button_stack(content_w); + int card_y = y != NULL ? *y : 0; + int card_h; int box_h; int hover = 0; TextInputStyle style = app_donation_address_style(); @@ -1748,14 +1773,25 @@ app_draw_donation_coin_section(const char *label, const char *address, snprintf(address_text, address_text_size, "%s", address); - Text(label, x, *y, label_font, GetThemeText()); + card_h = app_donation_coin_section_height(address, w); + DrawRectangleRounded((Rectangle){(float)x, (float)card_y, (float)w, + (float)card_h}, 0.08f, 8, + DarkenUIColor(GetThemeBackground(), 5)); + DrawRectangleRoundedLinesEx((Rectangle){(float)x, (float)card_y, + (float)w, (float)card_h}, 0.08f, 8, + (float)ScaleUIPx(1), + DarkenUIColor(GetThemeBackground(), 26)); + + *y = card_y + pad; + Text(label, content_x, *y, label_font, GetThemeText()); *y += TextLineHeight(label_font) + ScaleUIPx(6); - box_h = app_donation_address_box_height(address, w, address_font, style); + box_h = app_donation_address_box_height(address, content_w, address_font, + style); memset(&text_area, 0, sizeof(text_area)); - text_area.bounds.x = (float)x; + text_area.bounds.x = (float)content_x; text_area.bounds.y = (float)*y; - text_area.bounds.width = (float)w; + text_area.bounds.width = (float)content_w; text_area.bounds.height = (float)box_h; text_area.text = address_text; text_area.text_size = address_text_size; @@ -1769,9 +1805,12 @@ app_draw_donation_coin_section(const char *label, const char *address, text_area.read_only = 1; text_area.wrap = 1; TextArea(text_area); - *y += box_h + ScaleUIPx(8); + *y += box_h + ScaleUIPx(10); - if(StyledButton(x, *y, button_w, button_h, + if(stack_buttons) + button_w = content_w; + + if(StyledButton(content_x, *y, button_w, button_h, GetLocaleText("copy_address_button"), ButtonStyleSecondary, 0, &hover)) { #if ANDROID_BUILD @@ -1787,19 +1826,27 @@ app_draw_donation_coin_section(const char *label, const char *address, ShowToast(GetLocaleText("address_copied")); #endif } - if(StyledButton(x + button_w + gap, *y, button_w, button_h, + + if(stack_buttons) + *y += button_h + gap; + if(StyledButton(stack_buttons ? content_x : content_x + button_w + gap, + *y, button_w, button_h, GetLocaleText("open_wallet_button"), ButtonStyleSecondary, 0, &hover)) { if(!OpenURI(wallet_url)) ShowToast(GetLocaleText("wallet_not_installed_toast")); } - if(StyledButton(x + (button_w + gap) * 2, *y, button_w, button_h, + + if(stack_buttons) + *y += button_h + gap; + if(StyledButton(stack_buttons ? content_x : + content_x + (button_w + gap) * 2, *y, button_w, button_h, GetLocaleText("trocador_button"), ButtonStylePrimary, 0, &hover)) { (void)OpenURI(trocador_url); } - *y += button_h + ScaleUIPx(18); + *y = card_y + card_h; } static void @@ -1807,10 +1854,24 @@ draw_about_donation_modal(InbeApp *app) { UIPanelFrame frame; ParagraphSpec message; + UIScrollArea scroll_area; + UIScrollView scroll_view; int modal_w; int modal_h; int content_w; + int max_modal_h; + int message_h; + int content_h; + int coin_w; + int coin_gap; + int bitcoin_h; + int monero_h; + int coins_h; + int columns; + int scroll_h; + int scroll_content_w; int y; + int coin_y; int button_w; int button_h = ScaleUIPx(36); int hover = 0; @@ -1819,12 +1880,17 @@ draw_about_donation_modal(InbeApp *app) if(app == NULL) return; - modal_w = ScaleUIPx(460); + modal_w = ScaleUIPx(760); + if(view_width < ScaleUIPx(820)) + modal_w = ScaleUIPx(460); if(modal_w > view_width - ScaleUIPx(24)) modal_w = view_width - ScaleUIPx(24); if(modal_w < ScaleUIPx(240)) modal_w = ScaleUIPx(240); content_w = modal_w - ScaleUIPx(36); + coin_gap = ScaleUIPx(12); + columns = content_w >= ScaleUIPx(640); + coin_w = columns ? (content_w - coin_gap) / 2 : content_w; memset(&message, 0, sizeof(message)); message.text = GetLocaleText("about_donation_message"); @@ -1832,14 +1898,21 @@ draw_about_donation_modal(InbeApp *app) message.font = GetUISmallFontSize(); message.line_gap = ScaleUIPx(4); message.color = DarkenUIColor(GetThemeText(), 28); - modal_h = ScaleUIPx(58) + - UIGetNodeHeight(UINodeParagraph(message, 0, 0)) + - ScaleUIPx(14) + - app_donation_coin_section_height(app_bitcoin_donation_address(), - content_w) + - app_donation_coin_section_height(app_monero_donation_address(), - content_w) + - button_h + ScaleUIPx(16); + message_h = UIGetNodeHeight(UINodeParagraph(message, 0, 0)); + bitcoin_h = app_donation_coin_section_height(app_bitcoin_donation_address(), + coin_w); + monero_h = app_donation_coin_section_height(app_monero_donation_address(), + coin_w); + coins_h = columns ? (bitcoin_h > monero_h ? bitcoin_h : monero_h) + : bitcoin_h + coin_gap + monero_h; + content_h = message_h + ScaleUIPx(16) + coins_h; + modal_h = ScaleUIPx(58) + content_h + ScaleUIPx(14) + button_h + + ScaleUIPx(16); + max_modal_h = view_height - ScaleUIPx(24); + if(modal_h > max_modal_h) + modal_h = max_modal_h; + if(modal_h < ScaleUIPx(260)) + modal_h = ScaleUIPx(260); memset(&empty_icon, 0, sizeof(empty_icon)); frame = ModalFrame(modal_w, modal_h, @@ -1850,10 +1923,37 @@ draw_about_donation_modal(InbeApp *app) return; } - y = frame.content_y; - message.width = frame.content_w; - Paragraph(message, frame.content_x, &y); - y += ScaleUIPx(14); + button_w = ScaleUIPx(120); + if(button_w > frame.content_w) + button_w = frame.content_w; + + scroll_h = frame.content_h - button_h - ScaleUIPx(14); + if(scroll_h < ScaleUIPx(120)) + scroll_h = ScaleUIPx(120); + scroll_area = (UIScrollArea){ + .bounds = { + (float)frame.content_x, + (float)frame.content_y, + (float)frame.content_w, + (float)scroll_h + }, + .content_height = content_h, + .content_x = frame.content_x, + .content_width = frame.content_w, + .scroll_offset = &app_donation_modal_scroll, + .wheel_step = ScaleUIPx(34), + .scrollbar_x = frame.content_x + frame.content_w - ScaleUIPx(8) + }; + + scroll_view = BeginUIScrollContainer(scroll_area); + scroll_content_w = scroll_view.content_w; + columns = scroll_content_w >= ScaleUIPx(640); + coin_w = columns ? (scroll_content_w - coin_gap) / 2 : scroll_content_w; + message.width = scroll_content_w; + y = scroll_view.content_y; + Paragraph(message, scroll_view.content_x, &y); + y += ScaleUIPx(16); + coin_y = y; app_draw_donation_coin_section("Bitcoin", app_bitcoin_donation_address(), @@ -1865,22 +1965,38 @@ draw_about_donation_modal(InbeApp *app) &app_donation_bitcoin_focused, &app_donation_bitcoin_scroll, 6101, - frame.content_x, frame.content_w, &y); - app_draw_donation_coin_section("Monero", - app_monero_donation_address(), - app_monero_wallet_url(), - app_monero_trocador_url(), - app_donation_monero_text, - sizeof(app_donation_monero_text), - &app_donation_monero_cursor, - &app_donation_monero_focused, - &app_donation_monero_scroll, - 6102, - frame.content_x, frame.content_w, &y); + scroll_view.content_x, coin_w, &coin_y); + if(columns) { + coin_y = y; + app_draw_donation_coin_section("Monero", + app_monero_donation_address(), + app_monero_wallet_url(), + app_monero_trocador_url(), + app_donation_monero_text, + sizeof(app_donation_monero_text), + &app_donation_monero_cursor, + &app_donation_monero_focused, + &app_donation_monero_scroll, + 6102, + scroll_view.content_x + coin_w + + coin_gap, + coin_w, &coin_y); + } else { + coin_y += coin_gap; + app_draw_donation_coin_section("Monero", + app_monero_donation_address(), + app_monero_wallet_url(), + app_monero_trocador_url(), + app_donation_monero_text, + sizeof(app_donation_monero_text), + &app_donation_monero_cursor, + &app_donation_monero_focused, + &app_donation_monero_scroll, + 6102, + scroll_view.content_x, coin_w, &coin_y); + } + EndUIScrollContainer(scroll_area, scroll_view); - button_w = ScaleUIPx(120); - if(button_w > frame.content_w) - button_w = frame.content_w; if(StyledButton(frame.x + (frame.w - button_w) / 2, frame.y + frame.h - button_h - ScaleUIPx(16), button_w, button_h,