wallet-core: check master public key in /wire response
This commit is contained in:
parent
3022777363
commit
7944a36e30
@ -24,6 +24,7 @@ import path from "path";
|
|||||||
import {
|
import {
|
||||||
addPaytoQueryParams,
|
addPaytoQueryParams,
|
||||||
Amounts,
|
Amounts,
|
||||||
|
codecForExchangeWireJson,
|
||||||
Configuration,
|
Configuration,
|
||||||
decodeCrock,
|
decodeCrock,
|
||||||
j2s,
|
j2s,
|
||||||
@ -47,7 +48,7 @@ import { lintExchangeDeployment } from "./lint.js";
|
|||||||
import { runEnvFull } from "./env-full.js";
|
import { runEnvFull } from "./env-full.js";
|
||||||
import { clk } from "@gnu-taler/taler-util/clk";
|
import { clk } from "@gnu-taler/taler-util/clk";
|
||||||
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
||||||
import { BankAccessApiClient } from "@gnu-taler/taler-wallet-core";
|
import { BankAccessApiClient, validateWireInfo } from "@gnu-taler/taler-wallet-core";
|
||||||
|
|
||||||
const logger = new Logger("taler-harness:index.ts");
|
const logger = new Logger("taler-harness:index.ts");
|
||||||
|
|
||||||
@ -84,6 +85,14 @@ const advancedCli = testingCli.subcommand("advancedArgs", "advanced", {
|
|||||||
help: "Subcommands for advanced operations (only use if you know what you're doing!).",
|
help: "Subcommands for advanced operations (only use if you know what you're doing!).",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
advancedCli
|
||||||
|
.subcommand("validateWireResponse", "validate-wire-response")
|
||||||
|
.action((args) => {
|
||||||
|
const wireResp = fs.readFileSync(0, "utf8");
|
||||||
|
const respJson = JSON.parse(wireResp);
|
||||||
|
const wireInfo = codecForExchangeWireJson().decode(respJson);
|
||||||
|
});
|
||||||
|
|
||||||
advancedCli
|
advancedCli
|
||||||
.subcommand("decode", "decode", {
|
.subcommand("decode", "decode", {
|
||||||
help: "Decode base32-crockford.",
|
help: "Decode base32-crockford.",
|
||||||
|
@ -843,6 +843,7 @@ export interface AccountInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ExchangeWireJson {
|
export interface ExchangeWireJson {
|
||||||
|
master_public_key: string;
|
||||||
accounts: AccountInfo[];
|
accounts: AccountInfo[];
|
||||||
fees: { [methodName: string]: WireFeesJson[] };
|
fees: { [methodName: string]: WireFeesJson[] };
|
||||||
}
|
}
|
||||||
@ -1432,6 +1433,7 @@ export const codecForExchangeWireJson = (): Codec<ExchangeWireJson> =>
|
|||||||
buildCodecForObject<ExchangeWireJson>()
|
buildCodecForObject<ExchangeWireJson>()
|
||||||
.property("accounts", codecForList(codecForAccountInfo()))
|
.property("accounts", codecForList(codecForAccountInfo()))
|
||||||
.property("fees", codecForMap(codecForList(codecForWireFeesJson())))
|
.property("fees", codecForMap(codecForList(codecForWireFeesJson())))
|
||||||
|
.property("master_public_key", codecForString())
|
||||||
.build("ExchangeWireJson");
|
.build("ExchangeWireJson");
|
||||||
|
|
||||||
export const codecForProposal = (): Codec<Proposal> =>
|
export const codecForProposal = (): Codec<Proposal> =>
|
||||||
|
@ -63,7 +63,7 @@ import {
|
|||||||
ExchangeRecord,
|
ExchangeRecord,
|
||||||
WalletStoresV1,
|
WalletStoresV1,
|
||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { isWithdrawableDenom } from "../index.js";
|
import { isWithdrawableDenom, TalerCryptoInterface } from "../index.js";
|
||||||
import { InternalWalletState, TrustInfo } from "../internal-wallet-state.js";
|
import { InternalWalletState, TrustInfo } from "../internal-wallet-state.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant } from "../util/invariants.js";
|
||||||
import {
|
import {
|
||||||
@ -236,12 +236,25 @@ export async function acceptExchangeTermsOfService(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateWireInfo(
|
export interface ValidateWireInfoArgs {
|
||||||
ws: InternalWalletState,
|
cryptoApi: TalerCryptoInterface;
|
||||||
versionCurrent: number,
|
|
||||||
wireInfo: ExchangeWireJson,
|
/**
|
||||||
masterPublicKey: string,
|
* Exchange major protocol version.
|
||||||
|
*/
|
||||||
|
versionCurrent?: number;
|
||||||
|
|
||||||
|
wireInfo: ExchangeWireJson;
|
||||||
|
|
||||||
|
insecureTrustExchange?: boolean;
|
||||||
|
|
||||||
|
masterPublicKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function validateWireInfo(
|
||||||
|
args: ValidateWireInfoArgs,
|
||||||
): Promise<WireInfo> {
|
): Promise<WireInfo> {
|
||||||
|
const { wireInfo, masterPublicKey, insecureTrustExchange } = args;
|
||||||
for (const a of wireInfo.accounts) {
|
for (const a of wireInfo.accounts) {
|
||||||
logger.trace("validating exchange acct");
|
logger.trace("validating exchange acct");
|
||||||
let isValid = false;
|
let isValid = false;
|
||||||
@ -632,6 +645,11 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
throw Error("unexpected invalid version");
|
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(
|
const wireInfo = await validateWireInfo(
|
||||||
ws,
|
ws,
|
||||||
version.current,
|
version.current,
|
||||||
|
Loading…
Reference in New Issue
Block a user