commit 846b1e7ec1ec7099ea2d8654f6f0d2655cfae802
parent 01ee40218f4e7b934fa9169253eb29446697a211
Author: Florian Dold <dold@taler.net>
Date: Mon, 23 Nov 2026 22:46:45 +0100
wallet: reject stale confirmations after an exchange changes currency
The master key can stay the same across a currency change. Check the
currency the user saw before clearing the warning. Older clients can
still confirm with just the key.
Diffstat:
7 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/doc/wallet-observations.md b/doc/wallet-observations.md
@@ -184,6 +184,9 @@ exchange currencies, and blocked refreshes leave the inbox when their
underlying conditions resolve. When accepting
exchange terms, pass the displayed ETag as `expectedEtag` to
`setExchangeTosAccepted` so the user accepts the version they reviewed.
+When confirming an exchange identity change, pass the displayed
+`currentMasterPub` and `currentCurrency` to `confirmExchangeKeyChange`.
+If either has changed, the warning stays pending for review.
`markAllUserAttentionRead({})` marks every active unread occurrence as read.
`clearReadUserAttention({})` dismisses every active occurrence that is both
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts
@@ -257,6 +257,8 @@ export interface DetailsMap {
exchangeBaseUrl: string;
currentMasterPub: string | undefined;
confirmedMasterPub: string;
+ currentCurrency?: string;
+ confirmedCurrency?: string;
};
[TalerErrorCode.WALLET_EXCHANGE_KEYS_NOT_ACCEPTED]: {
exchangeBaseUrl: string;
diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts
@@ -2877,6 +2877,8 @@ export interface ConfirmExchangeKeyChangeRequest {
* different one than the user was looking at.
*/
currentMasterPub: string;
+ /** Currency shown alongside the key when the user confirmed the change. */
+ currentCurrency?: string;
}
export const codecForConfirmExchangeKeyChangeRequest =
@@ -2884,6 +2886,7 @@ export const codecForConfirmExchangeKeyChangeRequest =
buildCodecForObject<ConfirmExchangeKeyChangeRequest>()
.property("exchangeBaseUrl", codecForCanonBaseUrl())
.property("currentMasterPub", codecForString())
+ .property("currentCurrency", codecOptional(codecForString()))
.build("ConfirmExchangeKeyChangeRequest");
export interface GetWithdrawalDetailsForUriRequest {
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
@@ -911,17 +911,22 @@ export async function confirmExchangeKeyChange(
"the exchange has no unconfirmed key change",
);
}
- // Guards a stale UI: the key on screen when the user decided must be the
- // one in force now, or they confirmed something else.
- if (r.detailsPointer?.masterPublicKey !== req.currentMasterPub) {
+ const current = r.detailsPointer;
+ if (
+ current?.masterPublicKey !== req.currentMasterPub ||
+ (req.currentCurrency !== undefined &&
+ current.currency !== req.currentCurrency)
+ ) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_EXCHANGE_KEY_CHANGE_MISMATCH,
{
exchangeBaseUrl: req.exchangeBaseUrl,
- currentMasterPub: r.detailsPointer?.masterPublicKey,
+ currentMasterPub: current?.masterPublicKey,
confirmedMasterPub: req.currentMasterPub,
+ currentCurrency: current?.currency,
+ confirmedCurrency: req.currentCurrency,
},
- "the confirmed master public key is not the one the exchange uses",
+ "The exchange identity changed. Review its current master key and currency.",
);
}
const oldExchangeState = getExchangeState(r);
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -2181,6 +2181,10 @@ export const walletApiExpectedErrors = {
[WalletApiOperation.GetExchangeTos]: [
TalerErrorCode.WALLET_EXCHANGE_ENTRY_NOT_FOUND,
],
+ [WalletApiOperation.ConfirmExchangeKeyChange]: [
+ TalerErrorCode.WALLET_EXCHANGE_NO_KEY_CHANGE_PENDING,
+ TalerErrorCode.WALLET_EXCHANGE_KEY_CHANGE_MISMATCH,
+ ],
[WalletApiOperation.DeleteExchange]: [
TalerErrorCode.WALLET_EXCHANGE_ENTRY_NOT_FOUND,
TalerErrorCode.WALLET_EXCHANGE_ENTRY_USED,
diff --git a/packages/taler-wallet-core/src/wallet-notifications.test.ts b/packages/taler-wallet-core/src/wallet-notifications.test.ts
@@ -27,6 +27,7 @@ import {
openPromise,
RefreshReason,
SetTimeoutTimerAPI,
+ TalerError,
TalerErrorCode,
TransactionMajorState,
TransactionMinorState,
@@ -76,7 +77,6 @@ import { runnerFactories } from "./db/testing/runners.js";
import { getBalances } from "./balance.js";
import {
acceptExchangeTermsOfService,
- confirmExchangeKeyChange,
doExchangeAutoRefresh,
markExchangeUsed,
waitReadyExchange,
@@ -87,6 +87,8 @@ import {
processPurchase,
} from "./pay-merchant.js";
import { RefreshTransactionContext } from "./refresh.js";
+import { dispatchRequestInternal } from "./requests.js";
+import { WalletApiOperation } from "./wallet-api-types.js";
import { processRefreshBalance } from "./refreshBalance.js";
import { WithdrawTransactionContext } from "./withdraw.js";
import {
@@ -477,16 +479,32 @@ for (const makeRunner of runnerFactories) {
await f.wex.runWalletDbTx(initializeAttention);
assert.equal((await getUserAttention(f.wex)).unreadCount, 0);
- f.exchange.supersededKeySet.currency = "OTHER";
+ f.exchange.supersededKeySet.currency = first.currentCurrency;
+ f.exchange.detailsPointer!.currency = "OTHER";
await f.wex.runWalletDbTx((tx) => tx.upsertExchange(f.exchange));
const next = await getUserAttention(f.wex);
assert.equal(next.items.length, 1);
assert.equal(next.unreadCount, 1);
assert.notEqual(next.items[0].attentionId, first.attentionId);
- await confirmExchangeKeyChange(f.wex, {
- exchangeBaseUrl: exchangeUrl,
- currentMasterPub: master,
- });
+ const confirm = (currentCurrency: string) =>
+ dispatchRequestInternal(
+ f.wex,
+ WalletApiOperation.ConfirmExchangeKeyChange,
+ {
+ exchangeBaseUrl: exchangeUrl,
+ currentMasterPub: master,
+ currentCurrency,
+ },
+ );
+ await assert.rejects(
+ confirm(first.currentCurrency),
+ (e) =>
+ e instanceof TalerError &&
+ e.hasErrorCode(TalerErrorCode.WALLET_EXCHANGE_KEY_CHANGE_MISMATCH),
+ );
+ assert.deepEqual(await getUserAttention(f.wex), next);
+ assert.equal(next.items[0].type, "exchange-currency-changed");
+ await confirm(next.items[0].currentCurrency);
assert.deepEqual((await getUserAttention(f.wex)).items, []);
} finally {
await f.close();
diff --git a/packages/wallet-webui/src/routes/ManagementRoutes.tsx b/packages/wallet-webui/src/routes/ManagementRoutes.tsx
@@ -256,6 +256,7 @@ export function ExchangeDetailRoute() {
{
exchangeBaseUrl: exchangeUrl,
currentMasterPub: entry.unconfirmedKeyChange.currentMasterPub,
+ currentCurrency: entry.unconfirmedKeyChange.currentCurrency,
},
["exchanges", "balances", "transactions"],
);