commit 217cbeb018e5fd65141e491b97d2b029f221949c
parent e91aff1074f8442a4fe88c6b0474f47289522932
Author: Florian Dold <dold@taler.net>
Date: Fri, 20 Nov 2026 19:35:19 +0100
harness: add the Riegel lock and signing-key CLI
Expose key management, challenge creation, signing and verification
through taler-harness riegel. Exercise a paid door opening with the CLI
wallet for each supported device algorithm.
Diffstat:
5 files changed, 324 insertions(+), 0 deletions(-)
diff --git a/packages/taler-harness/README.md b/packages/taler-harness/README.md
@@ -4,6 +4,55 @@ This package implements the `taler-harness` CLI tool. It contains integration
tests for GNU Taler and GNU anastasis, as well as various helpers for managing
deployments of GNU Taler.
+## Riegel text-mode lock and key
+
+`taler-harness riegel` uses an unencrypted JSON store. The default path is
+`$XDG_STATE_HOME/taler-harness/riegel.json`, falling back to
+`~/.local/state/taler-harness/riegel.json`. Use `--store FILE` before the
+role or keyring command to select a different lock or signer. The file is
+owner-readable and writable. Store updates use the system `flock` utility
+and atomic replacement. Anyone with the JSON file can use its private keys.
+
+For a merchant-backed door, import the OTP device's public key (algorithm
+`3` for P-256 or `4` for Ed25519) and set the template that uses the device.
+Each command runs once. The first imported key is selected for the lock.
+
+```sh
+riegel() { taler-harness riegel --store ./door.json "$@"; }
+riegel keys import "$DEVICE_PUBLIC_KEY" --algorithm 4 --label "Test door"
+riegel lock template 'taler://pay-template/merchant.example/door'
+
+uri=$(riegel lock begin)
+taler-wallet-cli --wallet-db ./funded-test-wallet.sqlite handle-uri "$uri"
+# Paste the 103-character confirmation printed by the wallet.
+read -r response
+riegel lock verify "$uri" "$response"
+```
+
+To test offline with a separate signing key, create a new lock store and
+exchange the same public key URLs as the Android app.
+
+```sh
+signer() { taler-harness riegel --store ./signer.json "$@"; }
+door() { taler-harness riegel --store ./offline-door.json "$@"; }
+id=$(signer keys generate "Demo key" --algorithm 3)
+door keys import "$(signer keys export "$id")"
+uri=$(door lock begin)
+door lock verify "$uri" "$(signer key sign "$uri")"
+```
+
+`keys list` shows IDs and role selections. Use `lock select ID` or
+`key select ID` to switch. Key exports default to public material.
+`keys export ID --private` explicitly exports a signing key.
+`key sign`, `lock verify`, `lock cancel`, and `lock status` accept a raw
+challenge or its payment URI. Each challenge expires after 120 seconds.
+Verification prints `Opened` on success (exit 0), or the recorded outcome
+on rejection (exit 1). Malformed input and command errors exit 2.
+Changing the lock key or template cancels pending challenges.
+
+Run `taler-harness run-integrationtests riegel` with the built
+`taler-harness` and `taler-wallet-cli` on PATH for the two-algorithm wallet test.
+
## Challenge confirmations
Generate an offline-device challenge and verify the payment confirmation:
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts
@@ -17,6 +17,7 @@
/**
* Imports.
*/
+import { registerRiegel } from "./riegel-cli.js";
import { runConfirmationValidator } from "./challenge-confirmation.js";
import {
AbsoluteTime,
@@ -165,6 +166,8 @@ export const talerHarnessCli = clk
help: "Enable verbose output.",
});
+registerRiegel(talerHarnessCli);
+
const testingCli = talerHarnessCli.subcommand("testingArgs", "testing", {
help: "Subcommands for advanced operations (only use if you know what you're doing!).",
});
diff --git a/packages/taler-harness/src/integrationtests/test-riegel.ts b/packages/taler-harness/src/integrationtests/test-riegel.ts
@@ -0,0 +1,93 @@
+/*
+ This file is part of GNU Taler
+ (C) 2026 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+import { join } from "node:path";
+import { TalerMerchantInstanceHttpClient } from "@gnu-taler/taler-util";
+import {
+ createSimpleTestkudosEnvironmentV3,
+ withdrawViaBankV4,
+} from "../harness/environments.js";
+import {
+ GlobalTestState,
+ harnessHttpLib,
+ harnessLongpollQueue,
+ runCommand,
+} from "../harness/harness.js";
+import { createOtpTemplate } from "./test-otp.js";
+
+/** Exercise the two command-line entry points exactly as a manual door test does. */
+export async function runRiegelTest(t: GlobalTestState) {
+ const env = await createSimpleTestkudosEnvironmentV3(t);
+ const merchant = new TalerMerchantInstanceHttpClient(
+ env.merchant.makeInstanceBaseUrl(),
+ { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue },
+ );
+ await (
+ await withdrawViaBankV4(t, { ...env, amount: "TESTKUDOS:20" })
+ ).withdrawalFinishedCond;
+ for (const alg of [3, 4]) {
+ const templateId = "door-" + alg;
+ const device = await createOtpTemplate(
+ merchant,
+ env.merchantAdminAccessToken,
+ alg,
+ templateId,
+ templateId,
+ );
+ t.assertTrue(device != null && "otp_device_pub" in device);
+ const door = async (...args: string[]) =>
+ (
+ await runCommand(t, "riegel-" + args[1], "taler-harness", [
+ "riegel",
+ "--store",
+ join(t.testDir, "lock-" + alg + ".json"),
+ ...args,
+ ])
+ ).trim();
+ await door(
+ "keys",
+ "import",
+ device.otp_device_pub,
+ "--algorithm",
+ String(alg),
+ );
+ await door(
+ "lock",
+ "template",
+ "taler+http://pay-template/localhost:" +
+ env.merchant.port +
+ "/" +
+ templateId,
+ );
+ const uri = await door("lock", "begin");
+ const output = await runCommand(t, "wallet-pay", "taler-wallet-cli", [
+ "--wallet-connection",
+ env.walletService.socketPath,
+ "handle-uri",
+ "--yes",
+ uri,
+ ]);
+ const responses = output
+ .split(/\r?\n/)
+ .filter((l) => /^[0-9A-HJKMNP-TV-Z]{103}$/.test(l));
+ t.assertTrue(responses.length === 1);
+ t.assertDeepEqual(
+ await door("lock", "verify", uri, responses[0]),
+ "Opened",
+ );
+ t.assertDeepEqual(await door("lock", "status", uri), "Opened");
+ }
+}
+runRiegelTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -155,6 +155,7 @@ import { runMerchantTokenfamiliesTest } from "./test-merchant-tokenfamilies.js";
import { runMerchantSettlementTest } from "./test-merchant-settlement.js";
import { runMerchantWireTest } from "./test-merchant-wire.js";
import { runMultiExchangeTest } from "./test-multiexchange.js";
+import { runRiegelTest } from "./test-riegel.js";
import {
runEcdsaChallengeConfirmationTest,
runEddsaChallengeConfirmationTest,
@@ -497,6 +498,7 @@ const allTests: TestMainFunction[] = [
runWalletCoinRecoveryV27Test,
runWalletCoinRecoveryV27CsAgeTest,
runOtpTest,
+ runRiegelTest,
runEcdsaChallengeConfirmationTest,
runEddsaChallengeConfirmationTest,
runExchangeManagementTest,
diff --git a/packages/taler-harness/src/riegel-cli.ts b/packages/taler-harness/src/riegel-cli.ts
@@ -0,0 +1,177 @@
+/*
+ This file is part of GNU Taler
+ (C) 2026 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+import { clk } from "@gnu-taler/taler-util/clk";
+import type { talerHarnessCli } from "./index.js";
+import * as door from "./riegel.js";
+
+function run(store: string | undefined, f: (s: door.Store) => string) {
+ try {
+ const result = door.withStore(store, f);
+ if (result) console.log(result);
+ } catch (e) {
+ console.error(e instanceof Error ? e.message : "Riegel command failed");
+ process.exitCode = 2;
+ }
+}
+
+export function registerRiegel(root: typeof talerHarnessCli) {
+ const r = root
+ .subcommand("riegel", "riegel", {
+ help: "Test a Riegel lock or signing key using text.",
+ })
+ .maybeOption("store", ["--store"], clk.STRING, {
+ help: "Path to unencrypted JSON key and attempt store.",
+ });
+ const keys = r.subcommand("keys", "keys", {
+ help: "Manage Riegel credentials.",
+ });
+ keys
+ .subcommand("generate", "generate", {
+ help: "Generate a signing key and print its ID.",
+ })
+ .requiredArgument("label", clk.STRING)
+ .requiredOption("algorithm", ["--algorithm"], clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) =>
+ door.generateKey(s, a.generate.algorithm, a.generate.label),
+ ),
+ );
+ keys
+ .subcommand("list", "list", {
+ help: "Show key IDs, labels, fingerprints and selected roles.",
+ })
+ .action((a) =>
+ run(a.riegel.store, (s) =>
+ JSON.stringify(
+ s.keys.map(({ id, label, algorithm, secret }) => ({
+ id,
+ label,
+ algorithm,
+ fingerprint: id.slice(0, 16).match(/.{4}/g)!.join(" "),
+ privateKeyAvailable: !!secret,
+ lock: s.lock === id,
+ key: s.key === id,
+ })),
+ null,
+ 2,
+ ),
+ ),
+ );
+ keys
+ .subcommand("importKey", "import", {
+ help: "Import a Riegel key URL or raw Base32 material.",
+ })
+ .requiredArgument("input", clk.STRING)
+ .maybeOption("algorithm", ["--algorithm"], clk.STRING)
+ .maybeOption("label", ["--label"], clk.STRING)
+ .flag("private", ["--private"])
+ .action((a) =>
+ run(a.riegel.store, (s) =>
+ door.importKey(
+ s,
+ a.importKey.input,
+ a.importKey.algorithm,
+ a.importKey.label,
+ a.importKey.private,
+ ),
+ ),
+ );
+ keys
+ .subcommand("exportKey", "export", {
+ help: "Print a public key URL, or a private URL with --private.",
+ })
+ .requiredArgument("id", clk.STRING)
+ .flag("private", ["--private"])
+ .action((a) =>
+ run(a.riegel.store, (s) =>
+ door.exportKey(door.findKey(s, a.exportKey.id), !!a.exportKey.private),
+ ),
+ );
+ keys
+ .subcommand("rename", "rename")
+ .requiredArgument("id", clk.STRING)
+ .requiredArgument("label", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) =>
+ door.renameKey(s, a.rename.id, a.rename.label),
+ ),
+ );
+ keys
+ .subcommand("deleteKey", "delete")
+ .requiredArgument("id", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => door.removeKey(s, a.deleteKey.id)),
+ );
+
+ const lock = r.subcommand("lock", "lock", {
+ help: "Issue and verify door challenges.",
+ });
+ const key = r.subcommand("key", "key", { help: "Sign a challenge offline." });
+ lock
+ .subcommand("select", "select")
+ .requiredArgument("id", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => door.selectKey(s, "lock", a.select.id)),
+ );
+ key
+ .subcommand("select", "select")
+ .requiredArgument("id", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => door.selectKey(s, "key", a.select.id)),
+ );
+ lock
+ .subcommand("template", "template")
+ .maybeArgument("uri", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => door.template(s, a.template.uri)),
+ );
+ lock
+ .subcommand("begin", "begin", {
+ help: "Print a payment URI valid for 120 seconds.",
+ })
+ .action((a) => run(a.riegel.store, door.begin));
+ lock
+ .subcommand("status", "status")
+ .requiredArgument("challenge", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => door.attempt(s, a.status.challenge).state),
+ );
+ lock
+ .subcommand("cancel", "cancel")
+ .requiredArgument("challenge", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => {
+ const attempt = door.attempt(s, a.cancel.challenge);
+ if (attempt.state === "Pending") attempt.state = "Cancelled";
+ return attempt.state;
+ }),
+ );
+ lock
+ .subcommand("verify", "verify")
+ .requiredArgument("challenge", clk.STRING)
+ .requiredArgument("response", clk.STRING)
+ .action((a) =>
+ run(a.riegel.store, (s) => {
+ const outcome = door.verify(s, a.verify.challenge, a.verify.response);
+ if (outcome !== "Opened") process.exitCode = 1;
+ return outcome;
+ }),
+ );
+ key
+ .subcommand("sign", "sign")
+ .requiredArgument("challenge", clk.STRING)
+ .action((a) => run(a.riegel.store, (s) => door.sign(s, a.sign.challenge)));
+}