From 3b2b6a6412111209fd984f43bcb91480e49d0d35 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 20 Jul 2021 23:21:57 +0300 Subject: [PATCH] [MTProto] add padding to encryptedData [MTProto] throw error if getRandomValues is unsupported --- src/lib/mtproto/authorizer.ts | 2 +- src/lib/polyfill.ts | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lib/mtproto/authorizer.ts b/src/lib/mtproto/authorizer.ts index ac6d69b7..1bad3f41 100644 --- a/src/lib/mtproto/authorizer.ts +++ b/src/lib/mtproto/authorizer.ts @@ -293,7 +293,7 @@ export class Authorizer { }; const keyAesEncrypted = await getKeyAesEncrypted(); - const encryptedData = await CryptoWorker.invokeCrypto('rsa-encrypt', keyAesEncrypted, auth.publicKey); + const encryptedData = addPadding(await CryptoWorker.invokeCrypto('rsa-encrypt', keyAesEncrypted, auth.publicKey), 256, true, true, true); const req_DH_params: req_DH_params = { nonce: auth.nonce, diff --git a/src/lib/polyfill.ts b/src/lib/polyfill.ts index af133d46..a6ef2c7d 100644 --- a/src/lib/polyfill.ts +++ b/src/lib/polyfill.ts @@ -5,13 +5,10 @@ */ import { bytesToHex, bytesFromHex, bufferConcats } from '../helpers/bytes'; -import { nextRandomInt } from '../helpers/random'; - -//export const secureRandom = new SecureRandom(); Object.defineProperty(Uint8Array.prototype, 'hex', { get: function(): string { - return bytesToHex([...this]); + return bytesToHex(this); }, set: function(str: string) { @@ -22,13 +19,10 @@ Object.defineProperty(Uint8Array.prototype, 'hex', { }); Uint8Array.prototype.randomize = function() { - //secureRandom.nextBytes(this); if(crypto && 'getRandomValues' in crypto) { crypto.getRandomValues(this); } else { - for(let i = 0; i < this.length; ++i) { - this[i] = nextRandomInt(255); - } + throw new Error('NO_SECURE_RANDOM'); } return this;