Disable E2EE if master password is invalid

This commit is contained in:
Jiiks 2018-08-15 02:34:35 +03:00
parent 8b180ea423
commit 34e2833555
1 changed files with 11 additions and 14 deletions

View File

@ -37,24 +37,21 @@ export default new class E2EE extends BuiltinModule {
this.handlePublicKey = this.handlePublicKey.bind(this);
}
// TODO Handle bad master key
async enabled(e) {
Events.on('discord:MESSAGE_CREATE', this.handlePublicKey);
seed = Security.randomBytes();
let newMaster = '';
try {
newMaster = await Modals.input('E2EE', 'Master Key:', true).promise;
const newMaster = await Modals.input('Open Database', 'Master Password', true).promise;
this.setMaster(newMaster);
this.patchDispatcher();
this.patchMessageContent();
const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton');
const cta = await ReactComponents.getComponent('ChannelTextArea', { selector });
this.patchChannelTextArea(cta);
this.patchChannelTextAreaSubmit(cta);
cta.forceUpdateAll();
} catch (err) {
Toasts.error('Failed to set master key!');
Settings.getSetting(...this.settingPath).value = false;
Toasts.error('Invalid master password! E2EE Disabled');
}
this.master = Security.encrypt(seed, newMaster);
this.patchDispatcher();
this.patchMessageContent();
const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton');
const cta = await ReactComponents.getComponent('ChannelTextArea', { selector });
this.patchChannelTextArea(cta);
this.patchChannelTextAreaSubmit(cta);
cta.forceUpdateAll();
}
async disabled(e) {