Fix setting up 2FA

This commit is contained in:
morethanwords 2021-11-04 00:59:51 +04:00
parent 794433529a
commit 4e61c4be0b
3 changed files with 29 additions and 28 deletions

4
.env
View File

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

View File

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

View File

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