Skip to content
Open
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
37 changes: 37 additions & 0 deletions .github/workflows/cli-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: cli-checks

on:
pull_request:
paths:
- 'cli/**'
- '.github/workflows/cli-checks.yml'
push:
branches: [main]
paths:
- 'cli/**'
- '.github/workflows/cli-checks.yml'

permissions:
contents: read

concurrency:
group: cli-checks-${{ github.ref }}
cancel-in-progress: true

jobs:
onekey-release-sign:
runs-on: ubuntu-24.04
defaults:
run:
working-directory: cli/onekey-release-sign
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: 24.21.0
- name: Verify GnuPG is available
run: gpg --version
- name: Run CLI unit and end-to-end GPG multisig tests
run: npm run check
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ app-modules/
├── native-modules/ # 32 Nitro modules (headless native APIs)
├── native-views/ # 13 Fabric views (native UI)
├── chain-runtimes/ # Rust Zcash and Monero runtimes, built separately
├── cli/ # standalone Node.js release & security CLIs
├── example/react-native/ # example app consuming every package via workspace:*
├── docs/ # development requirements, release process, README guide
├── scripts/ # generators, versioning and publishing tooling
Expand Down
10 changes: 10 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CLI tools

Standalone Node.js command-line packages for OneKey release engineering and
security tooling. These are not React Native packages and are not part of the
root Yarn workspaces or their synchronized RN version/publish commands.

- [onekey-release-sign](./onekey-release-sign/README.md) — Multi-signature
OpenPGP/YubiKey release signing, RFC 4880 `.asc` merging, and verification
for OneKey OTA (`metadata.json.info`) and full-release (`SHA256SUMS.asc`)
artifacts.
21 changes: 21 additions & 0 deletions cli/onekey-release-sign/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) OneKeyHQ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
104 changes: 104 additions & 0 deletions cli/onekey-release-sign/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# `@onekeyfe/onekey-release-sign`

Multi-signature OpenPGP/YubiKey CLI and zero-dependency Node.js library for signing, merging, and verifying OneKey OTA (`metadata.json.info`) and full-release (`SHA256SUMS.asc`) artifacts.

## Why single-file RFC 4880 multi-signature?

Two or more release signers on separate machines sign the exact same canonical payload with their own YubiKey OpenPGP keys (`gpg --clearsign --digest-algo SHA256`). `onekey-release-sign merge` validates and packs their OpenPGP Signature Packets (`Tag 2`, type `0x01`, `SHA-256/384/512`) into **one standard RFC 4880 `.asc` file**:

- Zero API/filename changes (`jsBundle.signature` stays one string; `<installer>.SHA256SUMS.asc` stays one file).
- 100% compatible with standard `gpg --verify` and `openpgp.js` multi-key verification.
- Verification deduplicates strictly by **Primary Key Fingerprint**, preventing duplicate-signature or primary+subkey bypasses.

> **Compatibility note for shipped clients**: Currently shipped Android (`BundleCryptoCore.kt` `signatureList[0]`) and Desktop (`result[0]`) verifiers check only the **first** signature packet against the legacy embedded OneKey release key. Independently keyed multi-signature `.asc` files produced by this CLI are **release-gate / server-side verified** until client trust-store upgrades roll out to verify `>= 2` distinct embedded YubiKey public keys on-device.

## Requirements

- Node.js `>= 20`
- `gpg` (GnuPG 2.2+ with `pinentry-mac` on macOS or Gpg4win on Windows)
- Optional: `ykman` (YubiKey Manager CLI) for touch-policy diagnostics

## Quick Start

### 1. Check local GPG & YubiKey setup

```sh
npx @onekeyfe/onekey-release-sign doctor
```

### 2. Sign independently (Signer A & Signer B on separate machines)

```sh
# Signer A (validates payload & metadata.json SHA-256 on one immutable byte snapshot before invoking GPG pinentry + touch)
onekey-release-sign sign \
--in electron.metadata.json.info \
--artifact metadata.json \
--key <SIGNER_A_FPR> \
--out sig-a.asc

# Signer B (on another machine, exact same payload)
onekey-release-sign sign \
--in electron.metadata.json.info \
--artifact metadata.json \
--key <SIGNER_B_FPR> \
--out sig-b.asc
```

### 3. Merge into one standard RFC 4880 `.asc` (Release Gate / Dashboard Backend)

```sh
onekey-release-sign merge \
--in sig-a.asc \
--in sig-b.asc \
--payload electron.metadata.json.info \
--keyring trusted-yubikeys.asc \
--threshold 2 \
--artifact metadata.json \
--out electron.metadata.json.info.asc
```

### 4. Verify multi-signature `.asc`

```sh
onekey-release-sign verify \
--in electron.metadata.json.info.asc \
--keyring trusted-yubikeys.asc \
--threshold 2 \
--artifact metadata.json \
--json
```

### 5. Full-release installer checksum helper

```sh
onekey-release-sign checksum \
--artifact OneKey-Wallet-6.8.0-mac-arm64.zip \
--out OneKey-Wallet-6.8.0-mac-arm64.zip.SHA256SUMS
```

## Programmatic Usage (e.g. Dashboard Backend)

```js
import {
mergeCleartextSignatures,
verifyMultisigCleartext,
} from '@onekeyfe/onekey-release-sign';

const merged = mergeCleartextSignatures([sigA, sigB]);

const result = verifyMultisigCleartext({
signedText: merged.armored,
keyringTexts: [trustedPublicKeysArmored],
threshold: 2,
});
```

## Development

```sh
cd cli/onekey-release-sign
npm test
npm run check
```

See [docs/SPEC.md](docs/SPEC.md) for the authoritative security contract.
11 changes: 11 additions & 0 deletions cli/onekey-release-sign/bin/onekey-release-sign.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
import { runCli } from '../src/cli.mjs';

const result = runCli(process.argv.slice(2));
if (result.stdout) {
process.stdout.write(result.stdout);
}
if (result.stderr) {
process.stderr.write(result.stderr);
}
process.exitCode = result.exitCode;
79 changes: 79 additions & 0 deletions cli/onekey-release-sign/docs/SPEC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# `@onekeyfe/onekey-release-sign` Specification

## Purpose

Provide a zero-dependency Node.js CLI and programmatic library for OneKey's
M-of-N (default 2-of-N) YubiKey/OpenPGP release-signing workflow covering:

1. **OTA hot-update metadata** (`*.metadata.json.info` JSON referencing `metadata.json` SHA-256).
2. **Full-release installers/APKs** (`*.SHA256SUMS` / `*.SHA256SUMS.asc`).

Multiple independent signers on separate machines sign the exact same canonical
payload with their own YubiKey OpenPGP keys. Their individual clear-signed
messages are merged into a **single RFC 4880 Cleartext Signed Message** (`.asc`)
whose signature armor block packs all `Signature Packet` (tag 2) binary packets
in sequence.

> **Rollout compatibility boundary**: Shipped Android (`BundleCryptoCore.kt`
> `signatureList[0]`) and Desktop (`result[0]`) verifiers inspect only the first
> signature packet against the legacy embedded release key. Independently keyed
> multi-signature `.asc` output is **release-gate / server-side verified** until
> client binaries ship multi-key threshold verification.

## Security Contract & Invariants

1. **Single-message framing & mandatory CRC-24**:
- Inputs containing more than one `-----BEGIN PGP SIGNED MESSAGE-----` or
`-----BEGIN PGP SIGNATURE-----` block MUST be rejected.
- ASCII Armor blocks MUST include a valid RFC 4880 CRC-24 checksum line;
omitted or corrupted checksums MUST be rejected.
2. **Strict signature packet validation**:
- Every packet inside the signature armor block MUST be OpenPGP Packet Tag 2 (`Signature`).
- Signature type MUST be `0x01` (`CANONICAL_TEXT_DOCUMENT`).
- Hash algorithm MUST be one of `SHA-256` (`8`), `SHA-384` (`9`), or `SHA-512` (`10`).
3. **Clear-signed-only merge & canonical body identity**:
- `mergeCleartextSignatures` accepts only clear-signed `PGP SIGNED MESSAGE`
inputs (detached signatures without an embedded body are rejected) so every
input undergoes canonical body equality comparison.
- When `expectedBody` (`--payload`) is provided, it is canonicalized using
GnuPG clear-sign framing rules (stripping one framing-equivalent terminal
line ending and per-line trailing spaces/tabs, joining with CRLF).
- Exact duplicate signature packets are rejected.
4. **TOCTOU-safe signing & no CLI passphrases**:
- `sign` reads the payload file once into an immutable byte buffer, validates
it against every supplied `--artifact`, and pipes that exact snapshot to
`gpg --clearsign` via `stdin`.
- Protected keys obtain credentials strictly through GnuPG `pinentry` (never
via CLI argv or subprocess arguments). Subprocess error messages omit full
argument lists.
5. **Isolated verification keyring**:
- Verification MUST run `gpg` in a freshly created temporary `GNUPGHOME`
(`0700`) importing only explicitly provided `--keyring` public keys so the
caller's ambient `~/.gnupg` cannot inject trust.
6. **Primary-key fingerprint deduplication**:
- Valid signatures are counted strictly by distinct **Primary Key
Fingerprint** (normalized 40-hex uppercase from GnuPG `VALIDSIG` field 10).
- Signing twice with the same key, or signing with both a primary key and
its subkey, counts as **1** signer and MUST NOT satisfy `threshold >= 2`.
7. **Strict CLI option validation & complete artifact binding**:
- Every CLI subcommand validates option names and positional counts against
an explicit per-command allowlist and exits non-zero on unknown/misspelled
flags.
- Every repeated `--artifact` path is verified against the manifest (and
`metadata.json.info` rejects `> 1` `--artifact`).
- Release artifact basenames enforce one shared rule across `checksum` and
`inspectReleasePayload` (single-segment basename with no whitespace, path
separators, traversal, or control characters, matching shipped mobile and
desktop `SHA256SUMS` parsers).
8. **Safe subprocess execution**:
- All `gpg` / `ykman` invocations use `execFileSync` with argument arrays
(never shell interpolation).

## CLI Subcommands

- `doctor` — Check `gpg`, optional `ykman`, and plugged-in YubiKey OpenPGP card.
- `checksum` — Generate canonical `<sha256> <basename>` payload for one or more artifacts.
- `inspect` — Parse and display a `metadata.json.info`, `SHA256SUMS`, or `.asc` file (verifying all supplied `--artifact` files).
- `sign` — Validate one immutable payload snapshot & all `--artifact` files locally, pipe that snapshot to `gpg --clearsign --digest-algo SHA256` via stdin, validate RFC 4880 output, and write `.asc`.
- `merge` — Merge 2+ clear-signed `.asc` files into one standard RFC 4880 multi-signature `.asc` (with optional `--payload`, isolated `--keyring`, `--threshold`, `--allow-fingerprint`, and `--artifact` checks).
- `verify` — Verify a multi-signature `.asc` against an explicit `--keyring`, `--threshold` (default `2`), optional `--allow-fingerprint`, and all supplied `--artifact` files (supports `--json`).
51 changes: 51 additions & 0 deletions cli/onekey-release-sign/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@onekeyfe/onekey-release-sign",
"version": "0.1.0",
"description": "Multi-signature OpenPGP/YubiKey CLI and library for OneKey OTA and full-release artifact signing, RFC 4880 .asc merging, and threshold verification.",
"type": "module",
"license": "MIT",
"engines": {
"node": ">=20"
},
"bin": {
"onekey-release-sign": "./bin/onekey-release-sign.mjs"
},
"main": "./src/index.mjs",
"exports": {
".": "./src/index.mjs",
"./package.json": "./package.json"
},
"files": [
"bin",
"src",
"docs/SPEC.md",
"README.md",
"LICENSE"
],
"scripts": {
"test": "node --test test/*.test.mjs",
"check": "node --test test/*.test.mjs && npm pack --dry-run"
},
"keywords": [
"onekey",
"yubikey",
"openpgp",
"gpg",
"multisig",
"release-signing",
"supply-chain"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OneKeyHQ/app-modules.git",
"directory": "cli/onekey-release-sign"
},
"bugs": {
"url": "https://github.com/OneKeyHQ/app-modules/issues"
},
"homepage": "https://github.com/OneKeyHQ/app-modules/tree/main/cli/onekey-release-sign#readme",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
}
}
Loading
Loading