diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js index 7b3e60af..df2d907b 100644 --- a/client/src/builtin/E2EE.js +++ b/client/src/builtin/E2EE.js @@ -18,9 +18,9 @@ import { Utils } from 'common'; import E2EEComponent from './E2EEComponent.vue'; import E2EEMessageButton from './E2EEMessageButton.vue'; import aes256 from 'aes256'; -import crypto from 'node-crypto'; +import nodecrypto from 'node-crypto'; -let seed = crypto.randomBytes(64).toString('hex'); +let seed = Security.randomBytes(); export default new class E2EE extends BuiltinModule { @@ -31,7 +31,7 @@ export default new class E2EE extends BuiltinModule { } setMaster(key) { - seed = crypto.randomBytes(64).toString('hex'); + seed = Security.randomBytes(); const newMaster = this.encrypt(seed, key); // TODO re-encrypt everything with new master return (this.master = newMaster); diff --git a/client/src/modules/security.js b/client/src/modules/security.js index 7209cc20..15db8c40 100644 --- a/client/src/modules/security.js +++ b/client/src/modules/security.js @@ -41,6 +41,10 @@ export default class Security { return decrypt; } + static randomBytes(length = 64, to = 'hex') { + return nodecrypto.randomBytes(length).toString(to); + } + static async createHmac(key, data, algorithm = 'sha256') { const hmac = nodecrypto.createHmac(algorithm, key); return new Promise((resolve, reject) => {