commit 8ba894b138ba661156fbe3ce5aa1a3cad3d9ac0e
parent 7ff6ebfe8e2300ae720587f192922c70f7c38377
Author: Florian Dold <dold@taler.net>
Date: Tue, 24 Nov 2026 14:47:03 +0100
wallet-core: return a distinct error for unusable purse signing keys
Callers can distinguish an unknown or out-of-validity signing key from
a failed purse status signature check using the error code alone.
Issue: https://bugs.taler.net/n/12166
Diffstat:
4 files changed, 63 insertions(+), 27 deletions(-)
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts
@@ -345,6 +345,10 @@ export interface DetailsMap {
[TalerErrorCode.WALLET_EXCHANGE_SIGNATURE_INVALID]: {
exchangeBaseUrl?: string;
};
+ [TalerErrorCode.WALLET_EXCHANGE_SIGNING_KEY_UNUSABLE]: {
+ exchangeBaseUrl: string;
+ exchangePub: string;
+ };
[TalerErrorCode.WALLET_EXCHANGE_ENTRY_OUTDATED]: {
exchangeBaseUrl: string;
};
diff --git a/packages/taler-util/src/taler-error-codes.ts b/packages/taler-util/src/taler-error-codes.ts
@@ -5585,6 +5585,14 @@ export enum TalerErrorCode {
/**
+ * The wallet has no matching exchange signing key that is valid at the time used to verify the response.
+ * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
+ * (A value of 0 indicates that the error is generated client-side).
+ */
+ WALLET_EXCHANGE_SIGNING_KEY_UNUSABLE = 7084,
+
+
+ /**
* The service encountered a timeout with its payment backend.
* Returned with an HTTP status code of #MHD_HTTP_GATEWAY_TIMEOUT (504).
* (A value of 0 indicates that the error is generated client-side).
diff --git a/packages/taler-wallet-core/src/exchange-signatures.test.ts b/packages/taler-wallet-core/src/exchange-signatures.test.ts
@@ -19,6 +19,8 @@ import {
AmountString,
Duration,
EddsaPublicKeyString,
+ TalerError,
+ TalerErrorCode,
TalerProtocolTimestamp,
} from "@gnu-taler/taler-util";
import assert from "node:assert";
@@ -69,6 +71,7 @@ test("exchange response keys must match and cover the signing time", () => {
function verificationContext(args: {
cryptoValid: boolean;
knownPub: string;
+ expired?: boolean;
}): any {
const now = AbsoluteTime.now();
const key: WalletExchangeSignkeys = {
@@ -112,14 +115,14 @@ function verificationContext(args: {
return { rowId: 1 };
},
async getExchangeSignKeysByDetailsRowId() {
- return [key];
+ return [args.expired ? signKey(args.knownPub) : key];
},
});
},
};
}
-test("purse status requires a valid signature from a known exchange key", async () => {
+test("purse status requires a valid signature from a known exchange key", async (ctx) => {
const status = {
balance: "TESTKUDOS:1",
deposit_timestamp: TalerProtocolTimestamp.fromSeconds(1),
@@ -141,16 +144,32 @@ test("purse status requires a valid signature from a known exchange key", async
"https://exchange.example/",
status,
),
- /invalid purse status signature/,
- );
- await assert.rejects(
- requireValidExchangePurseStatus(
- verificationContext({ cryptoValid: true, knownPub: "different-key" }),
- "https://exchange.example/",
- status,
- ),
- /invalid purse status signature/,
+ (e) =>
+ e instanceof TalerError &&
+ e.errorDetail.code ===
+ TalerErrorCode.WALLET_TRANSACTION_PROTOCOL_VIOLATION &&
+ /invalid purse status signature/.test(e.message),
);
+ for (const key of [
+ { knownPub: "different-key" },
+ { knownPub: "response-key", expired: true },
+ ]) {
+ const wex = verificationContext({ cryptoValid: true, ...key });
+ const verify = ctx.mock.method(wex.cryptoApi, "isValidPurseStatus");
+ const exchangeBaseUrl = "https://exchange.example/";
+ await assert.rejects(
+ requireValidExchangePurseStatus(wex, exchangeBaseUrl, status),
+ (e) =>
+ e instanceof TalerError &&
+ e.hasErrorCode(TalerErrorCode.WALLET_EXCHANGE_SIGNING_KEY_UNUSABLE) &&
+ /purse status signing key is unknown or outside its validity period/.test(
+ e.message,
+ ) &&
+ e.errorDetail.exchangeBaseUrl === exchangeBaseUrl &&
+ e.errorDetail.exchangePub === status.exchange_pub,
+ );
+ assert.equal(verify.mock.callCount(), 0);
+ }
});
test("direct refund confirmation requires signature and exchange key", async () => {
diff --git a/packages/taler-wallet-core/src/exchange-signatures.ts b/packages/taler-wallet-core/src/exchange-signatures.ts
@@ -115,22 +115,27 @@ export async function requireValidExchangePurseStatus(
exchangeBaseUrl: string,
status: ExchangePurseStatus,
): Promise<void> {
- const [knownKey, signatureResult] = await Promise.all([
- isKnownExchangeSigningKey(
- wex,
- exchangeBaseUrl,
- status.exchange_pub,
- AbsoluteTime.now(),
- ),
- wex.cryptoApi.isValidPurseStatus({
- balance: status.balance,
- depositTimestamp: status.deposit_timestamp,
- mergeTimestamp: status.merge_timestamp,
- exchangePub: status.exchange_pub,
- exchangeSig: status.exchange_sig,
- }),
- ]);
- if (!knownKey || !signatureResult.valid) {
+ const knownKey = await isKnownExchangeSigningKey(
+ wex,
+ exchangeBaseUrl,
+ status.exchange_pub,
+ AbsoluteTime.now(),
+ );
+ if (!knownKey) {
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_EXCHANGE_SIGNING_KEY_UNUSABLE,
+ { exchangeBaseUrl, exchangePub: status.exchange_pub },
+ "purse status signing key is unknown or outside its validity period for this exchange",
+ );
+ }
+ const signatureResult = await wex.cryptoApi.isValidPurseStatus({
+ balance: status.balance,
+ depositTimestamp: status.deposit_timestamp,
+ mergeTimestamp: status.merge_timestamp,
+ exchangePub: status.exchange_pub,
+ exchangeSig: status.exchange_sig,
+ });
+ if (!signatureResult.valid) {
throw invalidExchangeSignature(
"exchange returned an invalid purse status signature",
);