wallet-core: trust exchange for exchange benchmark

This commit is contained in:
Florian Dold 2021-12-08 16:23:00 +01:00
parent 09aeaf753a
commit 684c53e105
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 52 additions and 23 deletions

View File

@ -105,6 +105,8 @@ export async function runBench1(configJson: any): Promise<void> {
logger.info(`Finished deposit amount=10 time=${Date.now() - start}`); logger.info(`Finished deposit amount=10 time=${Date.now() - start}`);
} }
} }
wallet.stop();
} }
/** /**

View File

@ -133,6 +133,8 @@ export interface InternalWalletState {
timerGroup: TimerGroup; timerGroup: TimerGroup;
stopped: boolean; stopped: boolean;
insecureTrustExchange: boolean;
/** /**
* Asynchronous condition to interrupt the sleep of the * Asynchronous condition to interrupt the sleep of the
* retry loop. * retry loop.

View File

@ -25,7 +25,7 @@ import { CryptoWorker } from "./cryptoWorkerInterface.js";
import child_process from "child_process"; import child_process from "child_process";
import type internal from "stream"; import type internal from "stream";
import { OpenedPromise, openPromise } from "../../index.js"; import { OpenedPromise, openPromise } from "../../index.js";
import { FreshCoin, Logger } from "@gnu-taler/taler-util"; import { Logger } from "@gnu-taler/taler-util";
const logger = new Logger("synchronousWorker.ts"); const logger = new Logger("synchronousWorker.ts");

View File

@ -218,19 +218,24 @@ export async function acceptExchangeTermsOfService(
} }
async function validateWireInfo( async function validateWireInfo(
ws: InternalWalletState,
versionCurrent: number, versionCurrent: number,
wireInfo: ExchangeWireJson, wireInfo: ExchangeWireJson,
masterPublicKey: string, masterPublicKey: string,
cryptoApi: CryptoApi,
): Promise<WireInfo> { ): Promise<WireInfo> {
for (const a of wireInfo.accounts) { for (const a of wireInfo.accounts) {
logger.trace("validating exchange acct"); logger.trace("validating exchange acct");
const isValid = await cryptoApi.isValidWireAccount( let isValid = false;
versionCurrent, if (ws.insecureTrustExchange) {
a.payto_uri, isValid = true;
a.master_sig, } else {
masterPublicKey, isValid = await ws.cryptoApi.isValidWireAccount(
); versionCurrent,
a.payto_uri,
a.master_sig,
masterPublicKey,
);
}
if (!isValid) { if (!isValid) {
throw Error("exchange acct signature invalid"); throw Error("exchange acct signature invalid");
} }
@ -248,11 +253,16 @@ async function validateWireInfo(
startStamp, startStamp,
wireFee: Amounts.parseOrThrow(x.wire_fee), wireFee: Amounts.parseOrThrow(x.wire_fee),
}; };
const isValid = await cryptoApi.isValidWireFee( let isValid = false;
wireMethod, if (ws.insecureTrustExchange) {
fee, isValid = true;
masterPublicKey, } else {
); isValid = await ws.cryptoApi.isValidWireFee(
wireMethod,
fee,
masterPublicKey,
);
}
if (!isValid) { if (!isValid) {
throw Error("exchange wire fee signature invalid"); throw Error("exchange wire fee signature invalid");
} }
@ -488,10 +498,10 @@ async function updateExchangeFromUrlImpl(
} }
const wireInfo = await validateWireInfo( const wireInfo = await validateWireInfo(
ws,
version.current, version.current,
wireInfoDownload, wireInfoDownload,
keysInfo.masterPublicKey, keysInfo.masterPublicKey,
ws.cryptoApi,
); );
logger.info("finished validating exchange /wire info"); logger.info("finished validating exchange /wire info");
@ -516,11 +526,11 @@ async function updateExchangeFromUrlImpl(
tosFound !== undefined tosFound !== undefined
? tosFound ? tosFound
: await downloadExchangeWithTermsOfService( : await downloadExchangeWithTermsOfService(
baseUrl, baseUrl,
ws.http, ws.http,
timeout, timeout,
"text/plain", "text/plain",
); );
let recoupGroupId: string | undefined = undefined; let recoupGroupId: string | undefined = undefined;

View File

@ -777,10 +777,15 @@ export async function updateWithdrawalDenoms(
denominations.length denominations.length
}) signature of ${denom.denomPubHash}`, }) signature of ${denom.denomPubHash}`,
); );
const valid = await ws.cryptoApi.isValidDenom( let valid: boolean = false;
denom, if (ws.insecureTrustExchange) {
exchangeDetails.masterPublicKey, valid = true;
); } else {
valid = await ws.cryptoApi.isValidDenom(
denom,
exchangeDetails.masterPublicKey,
);
}
logger.trace(`Done validating ${denom.denomPubHash}`); logger.trace(`Done validating ${denom.denomPubHash}`);
if (!valid) { if (!valid) {
logger.warn( logger.warn(

View File

@ -1037,6 +1037,14 @@ export class Wallet {
return this._client; return this._client;
} }
/**
* Trust the exchange, do not validate signatures.
* Only used to benchmark the exchange.
*/
setInsecureTrustExchange() {
this.ws.insecureTrustExchange = true;
}
static async create( static async create(
db: DbAccess<typeof WalletStoresV1>, db: DbAccess<typeof WalletStoresV1>,
http: HttpRequestLibrary, http: HttpRequestLibrary,
@ -1089,6 +1097,8 @@ class InternalWalletStateImpl implements InternalWalletState {
merchantInfoCache: Record<string, MerchantInfo> = {}; merchantInfoCache: Record<string, MerchantInfo> = {};
insecureTrustExchange: boolean = false;
timerGroup: TimerGroup = new TimerGroup(); timerGroup: TimerGroup = new TimerGroup();
latch = new AsyncCondition(); latch = new AsyncCondition();
stopped = false; stopped = false;