aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-30 00:36:20 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-30 00:36:20 +0100
commitaaf7e1338d6cdb1b4e01ad318938b3eaea2f922b (patch)
tree594129ccdf20757aeb86d434dd62c0c1e8259ed5 /src/crypto
parent809fa186448dbd924f258f89920b9336f1979bb0 (diff)
downloadwallet-core-aaf7e1338d6cdb1b4e01ad318938b3eaea2f922b.tar.xz
wallet robustness WIP
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cryptoApi.ts16
-rw-r--r--src/crypto/cryptoImplementation.ts25
-rw-r--r--src/crypto/primitives/kdf.ts2
-rw-r--r--src/crypto/talerCrypto.ts3
4 files changed, 23 insertions, 23 deletions
diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts
index 46fe2576e..b5eae9beb 100644
--- a/src/crypto/cryptoApi.ts
+++ b/src/crypto/cryptoApi.ts
@@ -27,7 +27,7 @@ import { AmountJson } from "../amounts";
import {
CoinRecord,
DenominationRecord,
- PreCoinRecord,
+ PlanchetRecord,
RefreshSessionRecord,
ReserveRecord,
TipPlanchet,
@@ -38,7 +38,7 @@ import { CryptoWorker } from "./cryptoWorker";
import { ContractTerms, PaybackRequest } from "../talerTypes";
-import { BenchmarkResult, CoinWithDenom, PayCoinInfo } from "../walletTypes";
+import { BenchmarkResult, CoinWithDenom, PayCoinInfo, PlanchetCreationResult } from "../walletTypes";
import * as timer from "../timer";
@@ -173,6 +173,7 @@ export class CryptoApi {
*/
wake(ws: WorkerState, work: WorkItem): void {
if (this.stopped) {
+ console.log("cryptoApi is stopped");
CryptoApi.enableTracing && console.log("not waking, as cryptoApi is stopped");
return;
}
@@ -299,7 +300,6 @@ export class CryptoApi {
priority: number,
...args: any[]
): Promise<T> {
- CryptoApi.enableTracing && console.log("cryptoApi: doRpc called");
const p: Promise<T> = new Promise<T>((resolve, reject) => {
const rpcId = this.nextRpcId++;
const workItem: WorkItem = {
@@ -332,16 +332,14 @@ export class CryptoApi {
throw Error("assertion failed");
});
- return p.then((r: T) => {
- return r;
- });
+ return p;
}
- createPreCoin(
+ createPlanchet(
denom: DenominationRecord,
reserve: ReserveRecord,
- ): Promise<PreCoinRecord> {
- return this.doRpc<PreCoinRecord>("createPreCoin", 1, denom, reserve);
+ ): Promise<PlanchetCreationResult> {
+ return this.doRpc<PlanchetCreationResult>("createPlanchet", 1, denom, reserve);
}
createTipPlanchet(denom: DenominationRecord): Promise<TipPlanchet> {
diff --git a/src/crypto/cryptoImplementation.ts b/src/crypto/cryptoImplementation.ts
index 9ffdec701..7cddf9031 100644
--- a/src/crypto/cryptoImplementation.ts
+++ b/src/crypto/cryptoImplementation.ts
@@ -28,8 +28,7 @@ import {
CoinRecord,
CoinStatus,
DenominationRecord,
- PreCoinRecord,
- RefreshPreCoinRecord,
+ RefreshPlanchetRecord,
RefreshSessionRecord,
ReserveRecord,
TipPlanchet,
@@ -42,6 +41,7 @@ import {
CoinWithDenom,
PayCoinInfo,
Timestamp,
+ PlanchetCreationResult,
} from "../walletTypes";
import { canonicalJson, getTalerStampSec } from "../helpers";
import { AmountJson } from "../amounts";
@@ -154,10 +154,10 @@ export class CryptoImplementation {
* Create a pre-coin of the given denomination to be withdrawn from then given
* reserve.
*/
- createPreCoin(
+ createPlanchet(
denom: DenominationRecord,
reserve: ReserveRecord,
- ): PreCoinRecord {
+ ): PlanchetCreationResult {
const reservePub = decodeCrock(reserve.reservePub);
const reservePriv = decodeCrock(reserve.reservePriv);
const denomPub = decodeCrock(denom.denomPub);
@@ -179,7 +179,7 @@ export class CryptoImplementation {
const sig = eddsaSign(withdrawRequest, reservePriv);
- const preCoin: PreCoinRecord = {
+ const planchet: PlanchetCreationResult = {
blindingKey: encodeCrock(blindingFactor),
coinEv: encodeCrock(ev),
coinPriv: encodeCrock(coinKeyPair.eddsaPriv),
@@ -188,11 +188,10 @@ export class CryptoImplementation {
denomPub: encodeCrock(denomPub),
denomPubHash: encodeCrock(denomPubHash),
exchangeBaseUrl: reserve.exchangeBaseUrl,
- isFromTip: false,
reservePub: encodeCrock(reservePub),
withdrawSig: encodeCrock(sig),
};
- return preCoin;
+ return planchet;
}
/**
@@ -424,7 +423,7 @@ export class CryptoImplementation {
const transferPubs: string[] = [];
const transferPrivs: string[] = [];
- const preCoinsForGammas: RefreshPreCoinRecord[][] = [];
+ const planchetsForGammas: RefreshPlanchetRecord[][] = [];
for (let i = 0; i < kappa; i++) {
const transferKeyPair = createEcdheKeyPair();
@@ -442,7 +441,7 @@ export class CryptoImplementation {
sessionHc.update(amountToBuffer(valueWithFee));
for (let i = 0; i < kappa; i++) {
- const preCoins: RefreshPreCoinRecord[] = [];
+ const planchets: RefreshPlanchetRecord[] = [];
for (let j = 0; j < newCoinDenoms.length; j++) {
const transferPriv = decodeCrock(transferPrivs[i]);
const oldCoinPub = decodeCrock(meltCoin.coinPub);
@@ -456,16 +455,16 @@ export class CryptoImplementation {
const pubHash = hash(coinPub);
const denomPub = decodeCrock(newCoinDenoms[j].denomPub);
const ev = rsaBlind(pubHash, blindingFactor, denomPub);
- const preCoin: RefreshPreCoinRecord = {
+ const planchet: RefreshPlanchetRecord = {
blindingKey: encodeCrock(blindingFactor),
coinEv: encodeCrock(ev),
privateKey: encodeCrock(coinPriv),
publicKey: encodeCrock(coinPub),
};
- preCoins.push(preCoin);
+ planchets.push(planchet);
sessionHc.update(ev);
}
- preCoinsForGammas.push(preCoins);
+ planchetsForGammas.push(planchets);
}
const sessionHash = sessionHc.finish();
@@ -496,7 +495,7 @@ export class CryptoImplementation {
newDenomHashes: newCoinDenoms.map(d => d.denomPubHash),
newDenoms: newCoinDenoms.map(d => d.denomPub),
norevealIndex: undefined,
- preCoinsForGammas,
+ planchetsForGammas: planchetsForGammas,
transferPrivs,
transferPubs,
valueOutput,
diff --git a/src/crypto/primitives/kdf.ts b/src/crypto/primitives/kdf.ts
index 082963074..e1baed408 100644
--- a/src/crypto/primitives/kdf.ts
+++ b/src/crypto/primitives/kdf.ts
@@ -88,5 +88,5 @@ export function kdf(
output.set(chunk, i * 32);
}
- return output;
+ return output.slice(0, outputLength);
}
diff --git a/src/crypto/talerCrypto.ts b/src/crypto/talerCrypto.ts
index b754b0c57..317b1af55 100644
--- a/src/crypto/talerCrypto.ts
+++ b/src/crypto/talerCrypto.ts
@@ -237,6 +237,9 @@ function rsaFullDomainHash(hm: Uint8Array, rsaPub: RsaPub): bigint.BigInteger {
function rsaPubDecode(rsaPub: Uint8Array): RsaPub {
const modulusLength = (rsaPub[0] << 8) | rsaPub[1];
const exponentLength = (rsaPub[2] << 8) | rsaPub[3];
+ if (4 + exponentLength + modulusLength != rsaPub.length) {
+ throw Error("invalid RSA public key (format wrong)");
+ }
const modulus = rsaPub.slice(4, 4 + modulusLength);
const exponent = rsaPub.slice(
4 + modulusLength,