Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] E2E password generator #24114

Merged
merged 17 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/e2e/client/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import ByteBuffer from 'bytebuffer';

import { getRandomFraction } from '../../../lib/random';

const StaticArrayBufferProto = new ArrayBuffer().__proto__;

export function toString(thing) {
Expand Down Expand Up @@ -122,6 +124,20 @@ export async function readFileAsArrayBuffer(file) {
});
}

export async function generateMnemonicPhrase(n, sep = ' ') {
const { default: wordList } = await import('./wordList');
const result = new Array(n);
let len = wordList.length;
const taken = new Array(len);

while (n--) {
const x = Math.floor(getRandomFraction() * len);
result[n] = wordList[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result.join(sep);
}

export class Deferred {
constructor() {
const p = new Promise((resolve, reject) => {
Expand Down
8 changes: 4 additions & 4 deletions app/e2e/client/rocketchat.e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { ReactiveVar } from 'meteor/reactive-var';
import { EJSON } from 'meteor/ejson';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
Expand All @@ -18,6 +17,7 @@ import {
importRSAKey,
importRawKey,
deriveKey,
generateMnemonicPhrase,
} from './helper';
import * as banners from '../../../client/lib/banners';
import { Rooms, Subscriptions, Messages } from '../../models/client';
Expand Down Expand Up @@ -136,7 +136,7 @@ class E2E extends Emitter {
if (!this.db_public_key || !this.db_private_key) {
await call('e2e.setUserPublicAndPrivateKeys', {
public_key: Meteor._localStorage.getItem('public_key'),
private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), this.createRandomPassword()),
private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), await this.createRandomPassword()),
});
}

Expand Down Expand Up @@ -256,8 +256,8 @@ class E2E extends Emitter {
call('e2e.requestSubscriptionKeys');
}

createRandomPassword() {
const randomPassword = `${Random.id(3)}-${Random.id(3)}-${Random.id(3)}`.toLowerCase();
async createRandomPassword() {
const randomPassword = await generateMnemonicPhrase(5);
Meteor._localStorage.setItem('e2e.randomPassword', randomPassword);
return randomPassword;
}
Expand Down
Loading