diff --git a/.github/workflows/native-links.yml b/.github/workflows/native-links.yml new file mode 100644 index 0000000..3e47d0e --- /dev/null +++ b/.github/workflows/native-links.yml @@ -0,0 +1,58 @@ +name: Native link associations + +on: + pull_request: + paths: + - client/public/.well-known/** + - client/public/remote-link.html + - client/public/remote-link-dev.html + - vercel.json + - scripts/native-links.test.mjs + - scripts/android-development-association.test.mjs + - .github/workflows/native-links.yml + push: + branches: [main] + paths: + - client/public/.well-known/** + - client/public/remote-link.html + - client/public/remote-link-dev.html + - vercel.json + - scripts/native-links.test.mjs + - scripts/android-development-association.test.mjs + - .github/workflows/native-links.yml + +permissions: + contents: read + +jobs: + native-links: + name: Native link source and certificate checks + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + path: website + persist-credentials: false + - uses: actions/checkout@v4 + with: + repository: KeeperCommunity/bitcoin-keeper + ref: 1d8a86a7462d935cbd0e28b857934b5718c152fc + path: keeper-android-source + sparse-checkout: | + android/app/build.gradle + android/app/debug.keystore + sparse-checkout-cone-mode: false + persist-credentials: false + - uses: actions/setup-node@v4 + with: + node-version: 22 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + - name: Verify native associations against the pinned mobile inputs + working-directory: website + env: + KEEPER_ANDROID_SOURCE: ${{ github.workspace }}/keeper-android-source + run: node --test scripts/native-links.test.mjs scripts/android-development-association.test.mjs diff --git a/client/public/.well-known/apple-app-site-association b/client/public/.well-known/apple-app-site-association new file mode 100644 index 0000000..505adec --- /dev/null +++ b/client/public/.well-known/apple-app-site-association @@ -0,0 +1,15 @@ +{ + "applinks": { + "apps": [], + "details": [ + { + "appID": "Y5TCB759QL.io.hexawallet.keeper", + "paths": ["/app/prod/remote/*"] + }, + { + "appID": "Y5TCB759QL.io.hexawallet.hexakeeper.dev", + "paths": ["/app/dev/remote/*"] + } + ] + } +} diff --git a/client/public/.well-known/assetlinks.json b/client/public/.well-known/assetlinks.json new file mode 100644 index 0000000..0a83700 --- /dev/null +++ b/client/public/.well-known/assetlinks.json @@ -0,0 +1,13 @@ +[ + { + "relation": ["delegate_permission/common.handle_all_urls"], + "target": { + "namespace": "android_app", + "package_name": "io.hexawallet.bitcoinkeeper", + "sha256_cert_fingerprints": [ + "BF:A0:23:D9:9F:AC:EB:AF:A4:A9:AF:22:B9:E4:9A:13:DB:BF:A3:EE:82:5B:E3:DA:16:CC:A9:E3:EA:1B:24:3A", + "66:56:8F:D4:FB:14:C0:13:4F:F4:05:57:62:60:70:38:AD:40:0B:A5:CB:C8:E2:3E:5E:25:26:5A:02:34:46:5C" + ] + } + } +] diff --git a/client/public/remote-link-dev.html b/client/public/remote-link-dev.html new file mode 100644 index 0000000..bdd13d8 --- /dev/null +++ b/client/public/remote-link-dev.html @@ -0,0 +1,27 @@ + + + + + + + + Development remote key link + + + + + + + + + +
+

This link is for a development build

+

Ask the person coordinating this test for the matching Bitcoin Keeper development build and instructions for opening the original link.

+

Android development links do not open the app automatically from this website. The public store app cannot open this development link.

+
+ + diff --git a/client/public/remote-link.html b/client/public/remote-link.html new file mode 100644 index 0000000..7bfdb81 --- /dev/null +++ b/client/public/remote-link.html @@ -0,0 +1,29 @@ + + + + + + + + Open a remote key link in Bitcoin Keeper + + + + + + + + + +
+

Open this link in Bitcoin Keeper

+

Install Bitcoin Keeper on this device, then open the original link again to continue the remote key exchange.

+

Get Bitcoin Keeper for iPhone

+

Get Bitcoin Keeper for Android

+
+ + diff --git a/scripts/android-development-association.test.mjs b/scripts/android-development-association.test.mjs new file mode 100644 index 0000000..4929b2e --- /dev/null +++ b/scripts/android-development-association.test.mjs @@ -0,0 +1,129 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { createHash, X509Certificate } from "node:crypto"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import test from "node:test"; + +// Public R4 source already integrated in mobile PR #7045. No native build or +// production-signing credentials are needed to check these tracked inputs. +const keeperSourceSha = "1d8a86a7462d935cbd0e28b857934b5718c152fc"; +const source = process.env.KEEPER_ANDROID_SOURCE; +assert.ok( + source, + "Set KEEPER_ANDROID_SOURCE to an isolated Keeper checkout at the pinned SHA" +); +assert.equal( + execFileSync("git", ["-C", source, "rev-parse", "HEAD"], { + encoding: "utf8", + }).trim(), + keeperSourceSha, + "Use the pinned public mobile source, without changing an existing checkout" +); +assert.equal( + execFileSync( + "git", + [ + "-C", + source, + "status", + "--porcelain", + "--", + "android/app/build.gradle", + "android/app/debug.keystore", + ], + { encoding: "utf8" } + ).trim(), + "", + "The association source inputs must have no local changes" +); + +const gradleBytes = readFileSync(resolve(source, "android/app/build.gradle")); +const keystore = resolve(source, "android/app/debug.keystore"); +assert.equal( + createHash("sha256").update(gradleBytes).digest("hex"), + "5935b7aa340c5640f52a84b700d72aab5fb2c454b2431ba50f1d9bae158aa7dc" +); +assert.equal( + createHash("sha256").update(readFileSync(keystore)).digest("hex"), + "221e0a3106aa4c3ccc154e0a418b55020b3f9ea6e84f92e8749cd9e2f39f5e58" +); +const gradle = gradleBytes.toString("utf8"); +const assetLinks = JSON.parse( + readFileSync( + new URL("../client/public/.well-known/assetlinks.json", import.meta.url), + "utf8" + ) +); + +// Read the pinned file's literal sections. This deliberately fails if its +// structure or inputs change; it does not try to evaluate arbitrary Gradle. +function section(text, name) { + const match = new RegExp(`\\b${name}\\s*\\{`).exec(text); + assert.ok(match, `Missing Gradle section ${name}`); + let depth = 1; + const start = match.index + match[0].length; + for (let end = start; end < text.length; end += 1) { + if (text[end] === "{") depth += 1; + if (text[end] === "}" && --depth === 0) return text.slice(start, end); + } + assert.fail(`Unclosed Gradle section ${name}`); +} + +function literal(text, name) { + const match = new RegExp(`^\\s*${name}\\s+["']([^"']+)["']\\s*$`, "m").exec( + text + ); + assert.ok(match, `Missing literal Gradle ${name}`); + return match[1]; +} + +test("production host excludes the actual mobile development package and public debug certificate", () => { + const defaults = section(gradle, "defaultConfig"); + const development = section(section(gradle, "productFlavors"), "development"); + assert.doesNotMatch(development, /^\s*applicationId\s/m); + assert.doesNotMatch(defaults, /^\s*applicationIdSuffix\s/m); + const packageName = + literal(defaults, "applicationId") + + literal(development, "applicationIdSuffix"); + const debugSigning = section(section(gradle, "signingConfigs"), "debug"); + assert.match(debugSigning, /storeFile\s+file\('debug\.keystore'\)/); + assert.equal(literal(debugSigning, "keyAlias"), "androiddebugkey"); + assert.match( + section(section(gradle, "buildTypes"), "debug"), + /signingConfig\s+signingConfigs\.debug/ + ); + + // Export only the public certificate from the tracked, publicly known debug + // keystore. Neither a private key nor a release signing identity is loaded. + const certificate = new X509Certificate( + execFileSync( + "keytool", + [ + "-exportcert", + "-keystore", + keystore, + "-alias", + "androiddebugkey", + "-storepass", + "android", + ], + { stdio: ["ignore", "pipe", "pipe"] } + ) + ); + const developmentLinks = assetLinks.filter(entry => + entry.target.package_name.endsWith(".development") + ); + assert.deepEqual(developmentLinks, []); + for (const entry of assetLinks) { + assert.notEqual(entry.target.package_name, packageName); + assert.ok(!entry.target.sha256_cert_fingerprints.includes(certificate.fingerprint256)); + } + + const productionPackage = literal( + section(section(gradle, "productFlavors"), "production"), + "applicationId" + ); + assert.equal(assetLinks[0].target.package_name, productionPackage); + assert.notEqual(packageName, `${productionPackage}.development`); +}); diff --git a/scripts/native-links.test.mjs b/scripts/native-links.test.mjs new file mode 100644 index 0000000..2a27983 --- /dev/null +++ b/scripts/native-links.test.mjs @@ -0,0 +1,98 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; + +const config = JSON.parse(readFileSync(new URL("../vercel.json", import.meta.url), "utf8")); +const association = JSON.parse( + readFileSync(new URL("../client/public/.well-known/apple-app-site-association", import.meta.url), "utf8"), +); +const assetLinks = JSON.parse( + readFileSync(new URL("../client/public/.well-known/assetlinks.json", import.meta.url), "utf8"), +); +const fallback = readFileSync(new URL("../client/public/remote-link.html", import.meta.url), "utf8"); +const developmentFallback = readFileSync(new URL("../client/public/remote-link-dev.html", import.meta.url), "utf8"); + +function associationRoute(path) { + const index = config.routes.findIndex(entry => entry.src && new RegExp(entry.src).test(path)); + assert.ok(index >= 0 && index < config.routes.findIndex(entry => entry.handle === "filesystem")); + const route = config.routes[index]; + assert.equal(route.dest, path); + assert.equal(route.headers.Location, undefined); + assert.ok(route.status === undefined || route.status === 200); + assert.equal(new RegExp(route.src).test(`${path}/unexpected`), false); + return route; +} + +test("iOS association maps production and development links to their apps", () => { + assert.deepEqual(association.applinks.details, [ + { appID: "Y5TCB759QL.io.hexawallet.keeper", paths: ["/app/prod/remote/*"] }, + { appID: "Y5TCB759QL.io.hexawallet.hexakeeper.dev", paths: ["/app/dev/remote/*"] }, + ]); + assert.equal( + associationRoute("/.well-known/apple-app-site-association").headers["Content-Type"], + "application/json", + ); +}); + +test("Android association trusts only verified standalone and Play production certificates", () => { + // Source: https://github.com/KeeperCommunity/bitcoin-keeper/releases/tag/v2.6.3 + // The release APK SHA-256 is a20d934ebd80ece779d3c171c7906bb4aff010337989ec1b826cab55c50eba46. + // This standalone identity was also verified against 2.6.4 in Backlog232. + // Play App Signing identity: authenticated Console receipt, 21 Oct 2026 11:38 UTC, Backlog232. + assert.deepEqual(assetLinks, [ + { + relation: ["delegate_permission/common.handle_all_urls"], + target: { + namespace: "android_app", + package_name: "io.hexawallet.bitcoinkeeper", + sha256_cert_fingerprints: [ + "BF:A0:23:D9:9F:AC:EB:AF:A4:A9:AF:22:B9:E4:9A:13:DB:BF:A3:EE:82:5B:E3:DA:16:CC:A9:E3:EA:1B:24:3A", + "66:56:8F:D4:FB:14:C0:13:4F:F4:05:57:62:60:70:38:AD:40:0B:A5:CB:C8:E2:3E:5E:25:26:5A:02:34:46:5C", + ], + }, + }, + ]); + assert.equal( + associationRoute("/.well-known/assetlinks.json").headers["Content-Type"], + "application/json", + ); +}); + +test("remote links reach a generic preview rather than the 404 route", () => { + const remoteRoute = config.routes.find((entry) => entry.dest === "/remote-link.html"); + const developmentRoute = config.routes.find((entry) => entry.dest === "/remote-link-dev.html"); + const catchAllIndex = config.routes.findIndex((entry) => entry.dest === "/404.html"); + assert.ok(remoteRoute); + assert.ok(developmentRoute); + assert.ok(config.routes.indexOf(remoteRoute) < catchAllIndex); + assert.ok(config.routes.indexOf(developmentRoute) < catchAllIndex); + const matches = new RegExp(remoteRoute.src); + const key = "0123456789abcdef01234567"; + assert.ok(matches.test(`/app/prod/remote/${key}`)); + assert.ok(!matches.test(`/app/dev/remote/${key}`)); + assert.ok(!matches.test(`/app/prod/remote/${key}/unexpected`)); + assert.ok(!matches.test(`/app/prod/remote/${key.slice(1)}`)); + assert.ok(!matches.test(`/app/prod/remote/${key}0`)); + assert.ok(!matches.test(`/app/prod/remote/${key.toUpperCase()}`)); + const developmentMatches = new RegExp(developmentRoute.src); + assert.ok(developmentMatches.test(`/app/dev/remote/${key}`)); + assert.ok(!developmentMatches.test(`/app/prod/remote/${key}`)); + assert.ok(!developmentMatches.test(`/app/dev/remote/${key}/unexpected`)); + assert.match(fallback, /property="og:image"/); + assert.match(fallback, /name="robots" content="noindex,nofollow"/); + assert.doesNotMatch(fallback, /location\.pathname|location\.href|document\.URL/); + for (const html of [fallback, developmentFallback]) { + assert.match(html, /name="referrer" content="no-referrer"/); + assert.match(html, /name="robots" content="noindex,nofollow"/); + assert.doesNotMatch(html, / { + for (const key of ["headers", "rewrites", "redirects", "cleanUrls", "trailingSlash"]) { + assert.equal(Object.hasOwn(config, key), false, `Do not mix routes with ${key}`); + } +}); diff --git a/vercel.json b/vercel.json index d054dc4..5ce0a82 100644 --- a/vercel.json +++ b/vercel.json @@ -4,6 +4,16 @@ "buildCommand": "pnpm run build", "outputDirectory": "dist/public", "routes": [ + { + "src": "^/\\.well-known/apple-app-site-association$", + "dest": "/.well-known/apple-app-site-association", + "headers": { "Content-Type": "application/json" } + }, + { + "src": "^/\\.well-known/assetlinks\\.json$", + "dest": "/.well-known/assetlinks.json", + "headers": { "Content-Type": "application/json" } + }, { "handle": "filesystem" }, @@ -36,6 +46,14 @@ "src": "/(features|contributors|ask-keeper|privacy-policy|terms-of-service)/?", "dest": "/$1/index.html" }, + { + "src": "^/app/prod/remote/[0-9a-f]{24}/?$", + "dest": "/remote-link.html" + }, + { + "src": "^/app/dev/remote/[0-9a-f]{24}/?$", + "dest": "/remote-link-dev.html" + }, { "src": "/", "dest": "/index.html"