diff --git a/app/app.html b/app/app.html index 51d2ae8..ac3447f 100644 --- a/app/app.html +++ b/app/app.html @@ -78,7 +78,7 @@

@@ -188,14 +188,14 @@

Set a Backup Key

Your OpenPGP key will be used for secure backup and restore of - your OnlyKey, make sure to store it in a secure location. + your OnlyKey. Make sure to store it in a secure location.

- Need a key? Follow our guide + Need a key? Follow hereour guide for generating an OpenPGP key.

diff --git a/app/scripts/onlyKey/OnlyKeyComm.js b/app/scripts/onlyKey/OnlyKeyComm.js index b37ddd0..be0dda1 100644 --- a/app/scripts/onlyKey/OnlyKeyComm.js +++ b/app/scripts/onlyKey/OnlyKeyComm.js @@ -719,7 +719,7 @@ OnlyKey.prototype.setRSABackupKey = async function (key, passcode, cb) { throw Error(error + "\n\n" + parseError); } - await onlyKeyConfigWizard.initKeySelect(privKey, function (err) { + return onlyKeyConfigWizard.initKeySelect(privKey, function (err) { ui.rsaForm.setError(err || ""); if (typeof cb === "function") cb(err); }); @@ -851,7 +851,7 @@ OnlyKey.prototype.submitRestore = function (fileSelector, cbArg) { } }; -OnlyKey.prototype.setPrivateKey = async function (slot, type, key, callback) { +OnlyKey.prototype.setPrivateKey = function (slot, type, key, callback) { var msg, contentType; if (Array.isArray(key) || key.constructor === Uint8Array) { // RSA private key is an array of DEC bytes @@ -958,11 +958,12 @@ OnlyKey.prototype.setmodkeyMode = function (modkeyMode) { }); }; -OnlyKey.prototype.setbackupKeyMode = function (backupKeyMode) { +OnlyKey.prototype.setbackupKeyMode = function (backupKeyMode, callback) { backupKeyMode = parseInt(backupKeyMode, 10); - this.setSlot("XX", "BACKUPKEYMODE", backupKeyMode, async () => { - return await this.listenforvalue("set Backup Key Mode"); - }); + const cb = callback || async function () { + await this.listenforvalue("set Backup Key Mode"); + }.bind(this); + return this.setSlot("XX", "BACKUPKEYMODE", backupKeyMode, cb); }; OnlyKey.prototype.setTypeSpeed = function (typeSpeed) { @@ -1865,9 +1866,7 @@ async function submitRsaForm(e) { return ui.rsaForm.setError("Passcode cannot be empty."); } - var privKey, - keyObj = {}, - retKey; + let privKey; try { var privKeys = await openpgp.key.readArmored(key); @@ -1899,7 +1898,7 @@ async function submitRsaForm(e) { }; } - await onlyKeyConfigWizard.initKeySelect(allKeys, function (err) { + return onlyKeyConfigWizard.initKeySelect(allKeys, function (err) { ui.rsaForm.setError(err || ""); }); } @@ -1931,8 +1930,7 @@ OnlyKey.prototype.confirmRsaKeySelect = function (keyObj, slot, cb) { var retKey = [...keyObj.p, ...keyObj.q]; } - var slot = - slot !== null ? slot : parseInt(ui.rsaForm.rsaSlot.value || "", 10); + slot = (slot !== null) ? slot : parseInt(ui.rsaForm.rsaSlot.value || "", 10); // set all type modifiers var typeModifier = 0; @@ -1959,31 +1957,27 @@ OnlyKey.prototype.confirmRsaKeySelect = function (keyObj, slot, cb) { console.info("Slot 2 set as signature key" + type); } } + + let keyHandlerFn = submitRsaKey; + if (typeof keyObj.s !== "undefined") { //ECC if (slot < 101) slot += 100; - myOnlyKey.setPrivateKey(slot, type, retKey, (err) => { - // TODO: check for success, then reset - if (typeof cb === "function") cb(err); - ui.rsaForm.reset(); - if (backupsigFlag >= 0) { - backupsigFlag = -1; - //reset backup form - } - this.listen(handleMessage); - }); - } else { - submitRsaKey(slot, type, retKey, (err) => { - // TODO: check for success, then reset - if (typeof cb === "function") cb(err); + keyHandlerFn = myOnlyKey.setPrivateKey; + } + + return keyHandlerFn(slot, type, retKey, (err) => { + if (err) { + return typeof cb === "function" && cb(err); + } else { + //reset backup form ui.rsaForm.reset(); if (backupsigFlag >= 0) { backupsigFlag = -1; - //reset backup form } - this.listen(handleMessage); - }); - } + return this.listen(cb || handleMessage); + } + }); }; function submitRsaKey(slot, type, key, callback) { diff --git a/app/scripts/onlyKey/OnlyKeyWizard.js b/app/scripts/onlyKey/OnlyKeyWizard.js index 1aacb0a..4112839 100644 --- a/app/scripts/onlyKey/OnlyKeyWizard.js +++ b/app/scripts/onlyKey/OnlyKeyWizard.js @@ -22,6 +22,7 @@ if (chrome.passwordsPrivate) { } Wizard.prototype.init = function (myOnlyKey) { + console.info('Wizard.init() called'); // reset all forms document.querySelectorAll('form').forEach(form => form.reset()); @@ -243,13 +244,11 @@ if (chrome.passwordsPrivate) { if (this.direction === NEXT) { if (!this.checkInitialized() && this.advancedSetup) { const backupKeyMode = this.initForm.backupKeyMode; - this.onlyKey.setbackupKeyMode(backupKeyMode.value, this.submitBackupKey.bind(this, cb)); - } else { - // not going to next step due to [Previous] click - this.submitBackupKey(cb); + return this.onlyKey.setbackupKeyMode(backupKeyMode.value, this.submitBackupKey.bind(this, cb)); } + return this.submitBackupKey(cb); } else { - cb(); + return cb(); } } }, @@ -262,8 +261,8 @@ if (chrome.passwordsPrivate) { this.onlyKey.flushMessage(); }, exitFn: (cb) => { - const backupKeyMode = this.initForm.backupKeyMode; - this.onlyKey.setbackupKeyMode(backupKeyMode.value, this.submitBackupRSAKey.bind(this, cb)); + const backupKeyMode = this.initForm.backupKeyModePGP; + return this.onlyKey.setbackupKeyMode(backupKeyMode.value, this.submitBackupRSAKey.bind(this, cb)); } }, Step10: { //Restore from backup @@ -332,7 +331,7 @@ if (chrome.passwordsPrivate) { document.getElementById('step8-2-text').innerHTML = `

+
@@ -605,8 +605,8 @@ if (chrome.passwordsPrivate) { }; - Wizard.prototype.initKeySelect = async function (rawKey, cb) { - console.info(rawKey); + Wizard.prototype.initKeySelect = function (rawKey, cb) { + console.info({ rawKey }); //Check if PGP or SSH if (rawKey.type == 'ed25519') { @@ -709,16 +709,18 @@ if (chrome.passwordsPrivate) { // then there is only one key, set it to slot this.rsaSlot_selection.value const signingKeySlot = this.rsaSlot_selection.value === '99' ? 2 : this.rsaSlot_selection.value; - this.onlyKey.confirmRsaKeySelect(signingKey, signingKeySlot, err => { + return this.onlyKey.confirmRsaKeySelect(signingKey, signingKeySlot, (err, res) => { + if (err) return cb(err); const decryptionKey = this.onlyKey.tempRsaKeys[1]; if (decryptionKey) { - this.onlyKey.confirmRsaKeySelect(decryptionKey, 1, err => { + this.onlyKey.confirmRsaKeySelect(decryptionKey, 1, (err, res) => { + if (err) return cb(err); + this.onlyKey.tempRsaKeys = null; + return cb(null, res); }); - this.onlyKey.tempRsaKeys = null; - this.reset(); } else { this.onlyKey.tempRsaKeys = null; - this.reset(); + return cb(null, res); } }); } else { @@ -734,7 +736,6 @@ if (chrome.passwordsPrivate) { this.dialog.open(this.selectPrivateKeyDialog, true); } - return cb(); }; @@ -806,13 +807,21 @@ if (chrome.passwordsPrivate) { } if (!passcode) { - this.initConfigErrors.innerHTML = 'Passcode cannot be empty.'; + this.initConfigErrors.innerHTML = 'Passphrase cannot be empty.'; return false; } - backuprsaKey.value = ''; - backuprsaPasscode.value = ''; - this.onlyKey.setRSABackupKey(key, passcode, cb); + this.onlyKey.setRSABackupKey(key, passcode, (err, res) => { + if (err) { + return cb(err); + } + + // reset form fields + backuprsaKey.value = ''; + backuprsaPasscode.value = ''; + + return cb(null, res); + }); }; Wizard.prototype.setSlot = function () { @@ -1415,7 +1424,7 @@ function makeRadioButton(name, value, text) { function toggleAdvancedUI(e) { e && e.preventDefault && e.preventDefault(); - this.advancedSetup = e.target.checked; + this.setAdvancedSetup(e.target.checked); this.initSteps(); }