Skip to content

Commit

Permalink
[FIX] E2E data not cleared on logout (#12254)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hudell authored and sampaiodiego committed Oct 4, 2018
1 parent e34df50 commit 64e8e3b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/rocketchat-e2e/client/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Accounts } from 'meteor/accounts-base';
import { e2e } from 'meteor/rocketchat:e2e';

Accounts.onLogin(() => {
e2e.startClient();
});

Accounts.onLogout(() => {
e2e.stopClient();
});
40 changes: 33 additions & 7 deletions packages/rocketchat-e2e/client/rocketchat.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {
deriveKey,
} from './helper';

import './events.js';
import './accountEncryption.html';
import './accountEncryption.js';

let failedToDecodeKey = false;
let showingE2EAlert = false;

class E2E {
constructor() {
Expand Down Expand Up @@ -109,15 +114,15 @@ class E2E {
} catch (error) {
this.started = false;
failedToDecodeKey = true;
alerts.open({
this.openAlert({
title: TAPi18n.__('Wasn\'t possible to decode your encryption key to be imported.'),
html: '<div>Your encryption password seems wrong. Click here to try again.</div>',
modifiers: ['large', 'danger'],
closable: true,
icon: 'key',
action: () => {
this.startClient();
alerts.close();
this.closeAlert();
},
});
return;
Expand Down Expand Up @@ -145,13 +150,13 @@ class E2E {
sprintf: [randomPassword],
});

alerts.open({
this.openAlert({
title: TAPi18n.__('Save_your_encryption_password'),
html: TAPi18n.__('Click_here_to_view_and_copy_your_password'),
modifiers: ['large'],
closable: false,
icon: 'key',
action() {
action: () => {
modal.open({
title: TAPi18n.__('Save_your_encryption_password'),
html: true,
Expand All @@ -165,7 +170,7 @@ class E2E {
return;
}
localStorage.removeItem('e2e.randomPassword');
alerts.close();
this.closeAlert();
});
},
});
Expand All @@ -179,6 +184,17 @@ class E2E {
this.decryptPendingSubscriptions();
}

async stopClient() {
// This flag is used to avoid closing unrelated alerts.
if (showingE2EAlert) {
alerts.close();
}

localStorage.removeItem('public_key');
localStorage.removeItem('private_key');
this.started = false;
}

setupListeners() {
RocketChat.Notifications.onUser('e2ekeyRequest', async(roomId, keyId) => {
const e2eRoom = await this.getInstanceByRoomId(roomId);
Expand Down Expand Up @@ -323,7 +339,7 @@ class E2E {
cancelButtonText: TAPi18n.__('I_ll_do_it_later'),
}, (password) => {
if (password) {
alerts.close();
this.closeAlert();
resolve(password);
}
}, () => {
Expand All @@ -333,7 +349,7 @@ class E2E {
};

showAlert = () => {
alerts.open({
this.openAlert({
title: TAPi18n.__('Enter_your_E2E_password'),
html: TAPi18n.__('Click_here_to_enter_your_encryption_password'),
modifiers: ['large'],
Expand Down Expand Up @@ -444,6 +460,16 @@ class E2E {
},
}).forEach(this.decryptSubscription.bind(this));
}

openAlert(config) {
showingE2EAlert = true;
alerts.open(config);
}

closeAlert() {
showingE2EAlert = false;
alerts.close();
}
}

export const e2e = new E2E();
Expand Down
3 changes: 0 additions & 3 deletions packages/rocketchat-e2e/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ Package.onUse(function(api) {
]);

api.mainModule('client/rocketchat.e2e.js', 'client');
api.addFiles('client/accountEncryption.html', 'client');
api.addFiles('client/accountEncryption.js', 'client');

api.mainModule('server/index.js', 'server');
});

0 comments on commit 64e8e3b

Please sign in to comment.