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