diff options
author | Florian Dold <florian@dold.me> | 2023-04-13 14:16:06 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-04-13 14:16:06 +0200 |
commit | 7944a36e30182638b35da6e113b29de8b5f16305 (patch) | |
tree | ee06040d66e53c867fa42a59c35b79cc6c3099a3 /packages/taler-wallet-core/src | |
parent | 30227773630ec1baac73793b5da25dab1bf2c357 (diff) | |
download | wallet-core-7944a36e30182638b35da6e113b29de8b5f16305.tar.xz |
wallet-core: check master public key in /wire response
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index d9051b32f..1fce92caf 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -63,7 +63,7 @@ import { ExchangeRecord, WalletStoresV1, } from "../db.js"; -import { isWithdrawableDenom } from "../index.js"; +import { isWithdrawableDenom, TalerCryptoInterface } from "../index.js"; import { InternalWalletState, TrustInfo } from "../internal-wallet-state.js"; import { checkDbInvariant } from "../util/invariants.js"; import { @@ -236,12 +236,25 @@ export async function acceptExchangeTermsOfService( }); } -async function validateWireInfo( - ws: InternalWalletState, - versionCurrent: number, - wireInfo: ExchangeWireJson, - masterPublicKey: string, +export interface ValidateWireInfoArgs { + cryptoApi: TalerCryptoInterface; + + /** + * Exchange major protocol version. + */ + versionCurrent?: number; + + wireInfo: ExchangeWireJson; + + insecureTrustExchange?: boolean; + + masterPublicKey: string; +} + +export async function validateWireInfo( + args: ValidateWireInfoArgs, ): Promise<WireInfo> { + const { wireInfo, masterPublicKey, insecureTrustExchange } = args; for (const a of wireInfo.accounts) { logger.trace("validating exchange acct"); let isValid = false; @@ -632,6 +645,11 @@ export async function updateExchangeFromUrlHandler( throw Error("unexpected invalid version"); } + if (wireInfoDownload.master_public_key != keysInfo.masterPublicKey) { + // FIXME: introduce error code + throw Error("inconsistent master public key between /keys and /wire"); + } + const wireInfo = await validateWireInfo( ws, version.current, |