From c7130a3bbb7cba2c9404ef45eb6dead4551329c6 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 12 Apr 2019 14:47:50 +1000 Subject: [PATCH] Added password confirmation dialog before showing seeds. --- _locales/en/messages.json | 3 +++ background.html | 34 +++++++++++++++++++------ js/views/seed_dialog_view.js | 45 +++++++++++++++++++++++++++++++--- stylesheets/_conversation.scss | 4 +++ 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index fa09d7599..02d3d29de 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -846,6 +846,9 @@ "copySeed": { "message": "Copy Seed" }, + "confirm": { + "message": "Confirm" + }, "failedToSend": { "message": "Failed to send to some recipients. Check your network connection." diff --git a/background.html b/background.html index b153ca8ca..66593c33f 100644 --- a/background.html +++ b/background.html @@ -235,15 +235,33 @@ diff --git a/js/views/seed_dialog_view.js b/js/views/seed_dialog_view.js index 1f0d89d76..4f514d191 100644 --- a/js/views/seed_dialog_view.js +++ b/js/views/seed_dialog_view.js @@ -1,4 +1,4 @@ -/* global Whisper, i18n */ +/* global Whisper, i18n, Signal, passwordUtil */ // eslint-disable-next-line func-names (function() { @@ -11,23 +11,60 @@ templateName: 'seed-dialog', initialize(options = {}) { this.okText = options.okText || i18n('ok'); + this.cancelText = options.cancelText || i18n('cancel'); + this.confirmText = options.confirmText || i18n('confirm'); this.copyText = options.copyText || i18n('copySeed'); this.seed = options.seed || '-'; this.render(); + this.showSeedView(false); + this.initPasswordHash(); }, events: { - 'click .ok': 'ok', + 'click .ok': 'close', + 'click .confirm': 'confirmPassword', 'click .copy-seed': 'copySeed', }, render_attributes() { return { - seed: this.seed, ok: this.okText, copyText: this.copyText, + confirm: this.confirmText, + cancel: this.cancelText, }; }, - ok() { + async initPasswordHash() { + const hash = await Signal.Data.getPasswordHash(); + this.passwordHash = hash; + this.showSeedView(!hash); + }, + showSeedView(show) { + const seedView = this.$('.seedView'); + const passwordView = this.$('.passwordView'); + if (show) { + this.$('.seed').html(this.seed); + seedView.show(); + passwordView.hide(); + } else { + this.$('.seed').html(''); + passwordView.show(); + seedView.hide(); + } + }, + confirmPassword() { + this.$('.error').html(); + const password = this.$('#password').val(); + if ( + this.passwordHash && + !passwordUtil.matchesHash(password, this.passwordHash) + ) { + this.$('.error').html(`Error: ${i18n('invalidPassword')}`); + return; + } + + this.showSeedView(true); + }, + close() { this.remove(); }, copySeed() { diff --git a/stylesheets/_conversation.scss b/stylesheets/_conversation.scss index 4545eabae..2f1fee424 100644 --- a/stylesheets/_conversation.scss +++ b/stylesheets/_conversation.scss @@ -440,6 +440,10 @@ font-weight: bold; } + .fields { + margin-top: 20px; + } + .seed { padding: 20px 0; font-style: oblique;