commit b67126a32aa8bb788d90ebdc06ce17dfc8096690
parent 81116c28e80fad44b4ca52278d2a3f731c384a08
Author: Florian Dold <dold@taler.net>
Date: Thu, 24 Sep 2026 22:27:21 +0200
harness: verify merchant challenge confirmations with both device types
Diffstat:
6 files changed, 321 insertions(+), 27 deletions(-)
diff --git a/packages/taler-harness/README.md b/packages/taler-harness/README.md
@@ -4,6 +4,37 @@ 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.
+## Challenge confirmations
+
+Generate an offline-device challenge and verify the payment confirmation:
+
+```sh
+taler-harness testing challenge-confirmation \
+ --algorithm EDDSA_CHALLENGE \
+ --public-key "$DEVICE_PUBLIC_KEY" \
+ --template-uri taler://pay-template/merchant.example/coffee
+```
+
+The public key is the merchant OTP device's `otp_device_pub`. Algorithms
+`ECDSA_CHALLENGE` (3, P-256) and `EDDSA_CHALLENGE` (4, Ed25519) are supported.
+The command prints a fresh 32-byte challenge and a payment URI, then reads one
+confirmation from stdin. Pay the URI with `taler-wallet-cli handle-uri`; the
+wallet prints `pos_confirmation` after payment. Paste that code into the
+validator. Exit statuses are 0 (valid), 1 (invalid signature), and 2 (malformed
+input or EOF). The validator makes no network requests and keeps no replay log.
+
+Template preparation accepts `challenge` either in the
+pay-template URI or as a `preparePayForTemplateV2` request field. Conflicting
+challenges are rejected. Hosts retrieve confirmations through the existing
+payment transaction's `posConfirmation` field.
+
+Run the merchant-backed tests with a freshly built wallet CLI on `PATH`:
+
+```sh
+taler-harness run-integrationtests '*challenge-confirmation*'
+taler-harness run-integrationtests otp
+```
+
## Integration test selection
`run-integrationtests` runs enabled suites by default. Suites that require
diff --git a/packages/taler-harness/src/challenge-confirmation.test.ts b/packages/taler-harness/src/challenge-confirmation.test.ts
@@ -0,0 +1,85 @@
+/*
+ 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 assert from "node:assert/strict";
+import { generateKeyPairSync, sign } from "node:crypto";
+import { test } from "node:test";
+import { decodeCrockFixed, encodeCrock } from "@gnu-taler/taler-util";
+import { validateInteractiveConfirmation } from "./challenge-confirmation.js";
+
+test("interactive validator generates a challenge, prints URI and verifies returned code", async () => {
+ const pair = generateKeyPairSync("ed25519");
+ const publicKey = encodeCrock(
+ Buffer.from(pair.publicKey.export({ format: "jwk" }).x!, "base64url"),
+ );
+ const lines: string[] = [];
+ const code = await validateInteractiveConfirmation(
+ {
+ algorithm: "4",
+ publicKey,
+ templateUri: "taler://pay-template/example.com/coffee?amount=KUDOS%3A1",
+ },
+ {
+ print: (line) => lines.push(line),
+ readConfirmation: async () => {
+ const challenge = lines[0].slice("Challenge: ".length);
+ assert.ok(lines[1].includes(`challenge=${challenge}`));
+ assert.ok(lines[1].includes("amount=KUDOS%3A1"));
+ return encodeCrock(
+ sign(
+ null,
+ Buffer.concat([
+ Buffer.from("taler-pos-challenge-v1"),
+ decodeCrockFixed(challenge, 32),
+ ]),
+ pair.privateKey,
+ ),
+ );
+ },
+ },
+ );
+ assert.equal(code, 0);
+ assert.equal(lines.at(-1), "VALID");
+ assert.equal(
+ await validateInteractiveConfirmation(
+ { algorithm: "4", publicKey },
+ { print() {}, readConfirmation: async () => undefined },
+ ),
+ 2,
+ );
+ assert.equal(
+ await validateInteractiveConfirmation(
+ { algorithm: "4", publicKey },
+ {
+ print() {},
+ readConfirmation: async () => encodeCrock(new Uint8Array(64)),
+ },
+ ),
+ 1,
+ );
+ assert.equal(
+ await validateInteractiveConfirmation(
+ { algorithm: "unknown", publicKey },
+ {
+ print() {},
+ readConfirmation: async () => {
+ throw Error("should not read");
+ },
+ },
+ ),
+ 2,
+ );
+});
diff --git a/packages/taler-harness/src/challenge-confirmation.ts b/packages/taler-harness/src/challenge-confirmation.ts
@@ -0,0 +1,98 @@
+/*
+ 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 { createInterface } from "node:readline";
+import {
+ decodeConfirmationPublicKey,
+ generateConfirmationChallenge,
+ parseChallengeConfirmationAlgorithm,
+ Result,
+ TalerUriAction,
+ TalerUris,
+ verifyChallengeConfirmation,
+} from "@gnu-taler/taler-util";
+
+export interface ConfirmationValidatorIo {
+ print(line: string): void;
+ readConfirmation(): Promise<string | undefined>;
+}
+
+export async function validateInteractiveConfirmation(
+ args: {
+ algorithm: string;
+ publicKey: string;
+ templateUri?: string;
+ },
+ io: ConfirmationValidatorIo,
+): Promise<number> {
+ try {
+ const algorithm = parseChallengeConfirmationAlgorithm(args.algorithm);
+ decodeConfirmationPublicKey(algorithm, args.publicKey);
+ const template =
+ args.templateUri === undefined
+ ? undefined
+ : Result.orUndefined(
+ TalerUris.parseRestricted(
+ args.templateUri,
+ TalerUriAction.PayTemplate,
+ ),
+ );
+ if (args.templateUri !== undefined && !template)
+ throw Error("Expected a pay-template URI");
+ const challenge = generateConfirmationChallenge();
+ io.print(`Challenge: ${challenge}`);
+ if (template)
+ io.print(
+ `Payment URI: ${TalerUris.stringify({ ...template, challenge })}`,
+ );
+ io.print("Enter payment confirmation:");
+ const confirmation = await io.readConfirmation();
+ if (!confirmation?.trim()) throw Error("No confirmation received");
+ const valid = verifyChallengeConfirmation({
+ algorithm,
+ publicKey: args.publicKey,
+ challenge,
+ confirmation: confirmation.trim(),
+ });
+ io.print(valid ? "VALID" : "INVALID");
+ return valid ? 0 : 1;
+ } catch {
+ io.print(
+ "ERROR: malformed algorithm, key, URI or confirmation, or end of input",
+ );
+ return 2;
+ }
+}
+
+export async function runConfirmationValidator(args: {
+ algorithm: string;
+ publicKey: string;
+ templateUri?: string;
+}): Promise<number> {
+ const reader = createInterface({ input: process.stdin, crlfDelay: Infinity });
+ const lines = reader[Symbol.asyncIterator]();
+ try {
+ return await validateInteractiveConfirmation(args, {
+ print: (line) => console.log(line),
+ readConfirmation: async () => {
+ const line = await lines.next();
+ return line.done ? undefined : line.value;
+ },
+ });
+ } finally {
+ reader.close();
+ }
+}
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts
@@ -17,6 +17,7 @@
/**
* Imports.
*/
+import { runConfirmationValidator } from "./challenge-confirmation.js";
import {
AbsoluteTime,
AccessToken,
@@ -168,6 +169,19 @@ const testingCli = talerHarnessCli.subcommand("testingArgs", "testing", {
help: "Subcommands for advanced operations (only use if you know what you're doing!).",
});
+testingCli
+ .subcommand("challengeConfirmation", "challenge-confirmation", {
+ help: "Generate a DD97 challenge and verify a payment confirmation offline.",
+ })
+ .requiredOption("algorithm", ["--algorithm"], clk.STRING)
+ .requiredOption("publicKey", ["--public-key"], clk.STRING)
+ .maybeOption("templateUri", ["--template-uri"], clk.STRING)
+ .action(async (args) => {
+ process.exitCode = await runConfirmationValidator(
+ args.challengeConfirmation,
+ );
+ });
+
talerHarnessCli
.subcommand("challengerTester", "challenger-tester", {
help: "Run a local Web site for testing a configured Challenger service.",
diff --git a/packages/taler-harness/src/integrationtests/test-otp.ts b/packages/taler-harness/src/integrationtests/test-otp.ts
@@ -14,10 +14,50 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
+export async function createOtpTemplate(
+ merchantClient: TalerMerchantInstanceHttpClient,
+ merchantAdminAccessToken: AccessToken,
+ algorithm: number,
+ deviceId: string,
+ templateId: string,
+) {
+ const device = succeedOrThrow(
+ await merchantClient.addOtpDevice(merchantAdminAccessToken, {
+ otp_algorithm: algorithm,
+ otp_device_description: "Hello",
+ otp_device_id: deviceId,
+ ...(algorithm < 3 ? { otp_key: randomRfc3548Base32Key() } : {}),
+ }),
+ );
+
+ succeedOrThrow(
+ await merchantClient.addTemplate(merchantAdminAccessToken, {
+ template_description: "my template",
+ template_id: templateId,
+ otp_id: deviceId,
+ template_contract: {
+ template_type: TemplateType.FIXED_ORDER,
+ summary: "test",
+ amount: "TESTKUDOS:1",
+ minimum_age: 0,
+ pay_duration: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ hours: 1 }),
+ ),
+ },
+ }),
+ );
+
+ return device;
+}
+
/**
* Imports.
*/
import {
+ AccessToken,
+ generateConfirmationChallenge,
+ parseChallengeConfirmationAlgorithm,
+ verifyChallengeConfirmation,
ConfirmPayResultType,
Duration,
TalerMerchantInstanceHttpClient,
@@ -43,7 +83,7 @@ import {
/**
* Verify merchant OTP device and template setup and an OTP-confirmed payment.
*/
-export async function runOtpTest(t: GlobalTestState) {
+async function runOtpAlgorithmTest(t: GlobalTestState, algorithm: number) {
// Set up test environment
const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } =
@@ -53,30 +93,12 @@ export async function runOtpTest(t: GlobalTestState) {
merchant.makeInstanceBaseUrl(),
{ httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue },
);
- succeedOrThrow(
- await merchantClient.addOtpDevice(merchantAdminAccessToken, {
- otp_algorithm: 1,
- otp_device_description: "Hello",
- otp_device_id: "mydevice",
- otp_key: randomRfc3548Base32Key(),
- }),
- );
-
- succeedOrThrow(
- await merchantClient.addTemplate(merchantAdminAccessToken, {
- template_description: "my template",
- template_id: "tpl1",
- otp_id: "mydevice",
- template_contract: {
- template_type: TemplateType.FIXED_ORDER,
- summary: "test",
- amount: "TESTKUDOS:1",
- minimum_age: 0,
- pay_duration: Duration.toTalerProtocolDuration(
- Duration.fromSpec({ hours: 1 }),
- ),
- },
- }),
+ const device = await createOtpTemplate(
+ merchantClient,
+ merchantAdminAccessToken,
+ algorithm,
+ "mydevice",
+ "tpl1",
);
const getTemplateResp = succeedOrThrow(
@@ -93,10 +115,12 @@ export async function runOtpTest(t: GlobalTestState) {
});
await wres.withdrawalFinishedCond;
+ const challenge =
+ algorithm >= 3 ? generateConfirmationChallenge() : undefined;
const preparePayResult = await walletClient.call(
WalletApiOperation.PreparePayForTemplateV2,
{
- talerPayTemplateUri: `taler+http://pay-template/localhost:${merchant.port}/tpl1`,
+ talerPayTemplateUri: `taler+http://pay-template/localhost:${merchant.port}/tpl1${challenge ? `?challenge=${challenge}` : ""}`,
templateParams: {},
},
);
@@ -132,6 +156,42 @@ export async function runOtpTest(t: GlobalTestState) {
t.assertTrue(transaction.type === TransactionType.Payment);
t.assertTrue(transaction.posConfirmation != null);
t.assertTrue(transaction.posConfirmation.length > 10);
+ if (challenge) {
+ t.assertTrue(device != null && "otp_device_pub" in device);
+ const publicKey = (device as { otp_device_pub: string }).otp_device_pub;
+ const args = {
+ algorithm: parseChallengeConfirmationAlgorithm(String(algorithm)),
+ publicKey,
+ challenge,
+ confirmation: transaction.posConfirmation!,
+ };
+ t.assertTrue(verifyChallengeConfirmation(args));
+ t.assertTrue(
+ !verifyChallengeConfirmation({
+ ...args,
+ challenge: generateConfirmationChallenge(),
+ }),
+ );
+ const reread = await walletClient.call(
+ WalletApiOperation.GetTransactionById,
+ { transactionId: preparePayResult.transactionId },
+ );
+ t.assertTrue(
+ reread.type === TransactionType.Payment &&
+ reread.posConfirmation === transaction.posConfirmation,
+ );
+ }
}
+export async function runOtpTest(t: GlobalTestState) {
+ await runOtpAlgorithmTest(t, 1);
+}
+export async function runEcdsaChallengeConfirmationTest(t: GlobalTestState) {
+ await runOtpAlgorithmTest(t, 3);
+}
+export async function runEddsaChallengeConfirmationTest(t: GlobalTestState) {
+ await runOtpAlgorithmTest(t, 4);
+}
+runEcdsaChallengeConfirmationTest.suites = ["merchant", "wallet"];
+runEddsaChallengeConfirmationTest.suites = ["merchant", "wallet"];
runOtpTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -155,7 +155,11 @@ 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 { runOtpTest } from "./test-otp.js";
+import {
+ runEcdsaChallengeConfirmationTest,
+ runEddsaChallengeConfirmationTest,
+ runOtpTest,
+} from "./test-otp.js";
import { runPaivanaHeadTest } from "./test-paivana-head.js";
import { runPaivanaRepurchaseTest } from "./test-paivana-repurchase.js";
import { runPayPaidTest } from "./test-pay-paid.js";
@@ -493,6 +497,8 @@ const allTests: TestMainFunction[] = [
runWalletCoinRecoveryV27Test,
runWalletCoinRecoveryV27CsAgeTest,
runOtpTest,
+ runEcdsaChallengeConfirmationTest,
+ runEddsaChallengeConfirmationTest,
runExchangeManagementTest,
runWalletBadNetworkTest,
runWalletProgressTokenTest,