Browse Source

Fix setting up 2FA

master
morethanwords 3 years ago
parent
commit
4e61c4be0b
  1. 4
      .env
  2. 5
      src/helpers/bytes.ts
  3. 20
      src/lib/crypto/srp.ts

4
.env

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
API_ID=1025907
API_HASH=452b0359b988148995f22ff0f4229750
VERSION=0.9.1
VERSION_FULL=0.9.1 (20)
BUILD=20
VERSION_FULL=0.9.1 (21)
BUILD=21

5
src/helpers/bytes.ts

@ -10,8 +10,9 @@ @@ -10,8 +10,9 @@
*/
export function bytesToHex(bytes: ArrayLike<number>) {
const arr: string[] = new Array(bytes.length);
for(let i = 0; i < bytes.length; ++i) {
const length = bytes.length;
const arr: string[] = new Array(length);
for(let i = 0; i < length; ++i) {
arr[i] = (bytes[i] < 16 ? '0' : '') + (bytes[i] || 0).toString(16);
}
return arr.join('');

20
src/lib/crypto/srp.ts

@ -44,11 +44,9 @@ export async function computeSRP(password: string, state: AccountPassword, isNew @@ -44,11 +44,9 @@ export async function computeSRP(password: string, state: AccountPassword, isNew
//console.log('computeSRP:', password, state, isNew, algo);
const p = str2bigInt(bytesToHex(algo.p), 16);
const B = str2bigInt(bytesToHex(state.srp_B), 16);
const g = int2bigInt(algo.g, 32, 256);
//log('p', bigInt2str(p, 16));
//log('B', bigInt2str(B, 16));
/* if(B.compareTo(BigInteger.ZERO) < 0) {
console.error('srp_B < 0')
@ -83,14 +81,6 @@ export async function computeSRP(password: string, state: AccountPassword, isNew @@ -83,14 +81,6 @@ export async function computeSRP(password: string, state: AccountPassword, isNew
return addPadding(arr, len, true, true, true);
};
const pForHash = padArray(bytesFromHex(bigInt2str(p, 16)), 256);
const gForHash = padArray(bytesFromHex(bigInt2str(g, 16)), 256); // like uint8array
const b_for_hash = padArray(bytesFromHex(bigInt2str(B, 16)), 256);
/* log(bytesToHex(pForHash));
log(bytesToHex(gForHash));
log(bytesToHex(b_for_hash)); */
const v = powMod(g, x, p);
const flipper = (arr: Uint8Array | number[]) => {
@ -111,6 +101,16 @@ export async function computeSRP(password: string, state: AccountPassword, isNew @@ -111,6 +101,16 @@ export async function computeSRP(password: string, state: AccountPassword, isNew
return padArray(/* (isBigEndian ? bytes.reverse() : bytes) */bytes, 256);
}
const B = str2bigInt(bytesToHex(state.srp_B), 16);
//log('B', bigInt2str(B, 16));
const pForHash = padArray(bytesFromHex(bigInt2str(p, 16)), 256);
const gForHash = padArray(bytesFromHex(bigInt2str(g, 16)), 256); // like uint8array
const b_for_hash = padArray(bytesFromHex(bigInt2str(B, 16)), 256);
/* log(bytesToHex(pForHash));
log(bytesToHex(gForHash));
log(bytesToHex(b_for_hash)); */
//log('g_x', bigInt2str(g_x, 16));
const kHash = await CryptoWorker.invokeCrypto('sha256-hash', bufferConcats(pForHash, gForHash));

Loading…
Cancel
Save