Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/native-links.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions client/public/.well-known/apple-app-site-association
Original file line number Diff line number Diff line change
@@ -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/*"]
}
]
}
}
13 changes: 13 additions & 0 deletions client/public/.well-known/assetlinks.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
]
27 changes: 27 additions & 0 deletions client/public/remote-link-dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex,nofollow" />
<meta name="referrer" content="no-referrer" />
<title>Development remote key link</title>
<meta name="description" content="This remote key link requires a matching Bitcoin Keeper development build." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Bitcoin Keeper development remote key link" />
<meta property="og:description" content="Ask the person coordinating this test for the matching development build." />
<meta property="og:image" content="https://www.bitcoinkeeper.app/wp-content/uploads/2025/07/Remote-Key-Sharing-1.png" />
<meta name="twitter:card" content="summary_large_image" />
<style>
body { font-family: system-ui, sans-serif; max-width: 34rem; margin: 12vh auto; padding: 0 1.5rem; line-height: 1.5; color: #1c2521; }
h1 { line-height: 1.2; }
</style>
</head>
<body>
<main>
<h1>This link is for a development build</h1>
<p>Ask the person coordinating this test for the matching Bitcoin Keeper development build and instructions for opening the original link.</p>
<p>Android development links do not open the app automatically from this website. The public store app cannot open this development link.</p>
</main>
</body>
</html>
29 changes: 29 additions & 0 deletions client/public/remote-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex,nofollow" />
<meta name="referrer" content="no-referrer" />
<title>Open a remote key link in Bitcoin Keeper</title>
<meta name="description" content="Open this remote key exchange link on a device with Bitcoin Keeper installed." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Bitcoin Keeper remote key exchange" />
<meta property="og:description" content="Open this link on a device with Bitcoin Keeper installed to continue a remote key exchange." />
<meta property="og:image" content="https://www.bitcoinkeeper.app/wp-content/uploads/2025/07/Remote-Key-Sharing-1.png" />
<meta name="twitter:card" content="summary_large_image" />
<style>
body { font-family: system-ui, sans-serif; max-width: 34rem; margin: 12vh auto; padding: 0 1.5rem; line-height: 1.5; color: #1c2521; }
h1 { line-height: 1.2; }
a { color: #17674d; }
</style>
</head>
<body>
<main>
<h1>Open this link in Bitcoin Keeper</h1>
<p>Install Bitcoin Keeper on this device, then open the original link again to continue the remote key exchange.</p>
<p><a href="https://apps.apple.com/us/app/bitcoin-keeper/id1545535925" rel="noreferrer">Get Bitcoin Keeper for iPhone</a></p>
<p><a href="https://play.google.com/store/apps/details?id=io.hexawallet.bitcoinkeeper" rel="noreferrer">Get Bitcoin Keeper for Android</a></p>
</main>
</body>
</html>
129 changes: 129 additions & 0 deletions scripts/android-development-association.test.mjs
Original file line number Diff line number Diff line change
@@ -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`);
});
98 changes: 98 additions & 0 deletions scripts/native-links.test.mjs
Original file line number Diff line number Diff line change
@@ -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, /<script\b|location\.|document\.|<input\b|<form\b/i);
}
assert.doesNotMatch(developmentFallback, /apps\.apple\.com|play\.google\.com/);
assert.match(developmentFallback, /person coordinating this test/);
assert.match(developmentFallback, /Android development links do not open the app automatically/);
});

test("Vercel legacy routes do not mix incompatible high-level routing fields", () => {
for (const key of ["headers", "rewrites", "redirects", "cleanUrls", "trailingSlash"]) {
assert.equal(Object.hasOwn(config, key), false, `Do not mix routes with ${key}`);
}
});
Loading
Loading