Make nice password prompts, handle enter key on modals, minor UI tweaks

master
Skylar Ittner 3 years ago
parent 57698559d9
commit 02a4f1d3fe

@ -135,7 +135,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="signaturePadCallback()">Apply</button>
<button type="button" class="btn btn-primary btn-default" data-bs-dismiss="modal" onclick="signaturePadCallback()">Apply</button>
</div>
</div>
</div>
@ -145,7 +145,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signatureRemoteModalLabel"><i class="fas fa-mobile"></i> Remote Signature Pad Connection</h5>
<h5 class="modal-title" id="signatureRemoteModalLabel"><i class="fas fa-mobile-alt"></i> Remote Signature Pad Connection</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
@ -158,12 +158,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<span id="signatureRemoteUrlLabel"></span>
</div>
<div class="list-group-item">
<div id="signatureRemoteQRCode" class="d-flex justify-content-center p-2" style="background-color: white; border-radius: 0.5em;"></div>
<div id="signatureRemoteQRCode" class="d-flex justify-content-center p-4" style="background-color: white; border-radius: 0.5em;"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary btn-default" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
@ -271,7 +271,22 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<div class="modal-content">
<div class="modal-body p-1"></div>
<div class="modal-footer p-1">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary btn-default" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="passwordModal" tabindex="-1" aria-labelledby="passwordModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-body">
<p id="passwordModalText"></p>
<input class="form-control" type="password" id="passwordModalInput" />
</div>
<div class="modal-footer p-1">
<button type="button" class="btn btn-secondary" onclick="passwordModalCallback('');" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary btn-default" id="passwordModalSubmitBtn" onclick="passwordModalCallback($('#passwordModalInput').val());" data-bs-dismiss="modal">Submit</button>
</div>
</div>
</div>

@ -20,27 +20,29 @@ function loadKeyFromLocalStorage(callback) {
}
$("#lockstatus").css("display", "none");
if (!inStorage("signingkey") || getStorage("signingkey") == "undefined") {
var pass = prompt("Generating a new signing key (might take a while, be patient). Enter a password to protect it. You'll need to save this password somewhere safe; it cannot be recovered.");
generatePrivateKey(getStorage("notary_name") + " <null@null.com>", pass, function (key) {
if (typeof key == "undefined") {
callback("Could not generate key.", false);
return;
}
keymgr = key;
keyring.add_key_manager(keymgr);
setStorage("signingkey", keymgr.armored_pgp_private);
callback("Signing key generated.", true);
showPasswordPrompt("Generating a new signing key (might take a while, be patient). Enter a password to protect it. You'll need to save this password somewhere safe; it cannot be recovered.", function (pass) {
generatePrivateKey(getStorage("notary_name") + " <null@null.com>", pass, function (key) {
if (typeof key == "undefined") {
callback("Could not generate key.", false);
return;
}
keymgr = key;
keyring.add_key_manager(keymgr);
setStorage("signingkey", keymgr.armored_pgp_private);
callback("Signing key generated.", true);
});
});
} else {
var pass = prompt("Enter password to unlock signing key:");
loadPrivateKey(getStorage("signingkey"), pass, function (key) {
if (typeof key == "undefined") {
callback("Could not unlock key. Password is probably incorrect.", false);
return;
}
keymgr = key;
keyring.add_key_manager(keymgr);
callback("Signing key unlocked.", true);
showPasswordPrompt("Enter password to unlock signing key:", function (pass) {
loadPrivateKey(getStorage("signingkey"), pass, function (key) {
if (typeof key == "undefined") {
callback("Could not unlock key. Password is probably incorrect.", false);
return;
}
keymgr = key;
keyring.add_key_manager(keymgr);
callback("Signing key unlocked.", true);
});
});
}
}
@ -201,42 +203,44 @@ function exportPublicKey() {
}
function exportPrivateKey() {
var pass = prompt("Enter password for private key:");
const savepriv = function (key) {
var pass2 = prompt("Enter a password to protect the key backup:");
openSaveFileDialog(function (path) {
key.export_pgp_private({
passphrase: pass2
}, function (err, pgp_private) {
if (err) {
showAlert("Something went wrong.");
showPasswordPrompt("Enter password for private key:", function (pass) {
const savepriv = function (key) {
showPasswordPrompt("Enter a password to protect the key backup:", function (pass2) {
openSaveFileDialog(function (path) {
key.export_pgp_private({
passphrase: pass2
}, function (err, pgp_private) {
if (err) {
showAlert("Something went wrong.");
} else {
writeToFile(path, pgp_private);
}
});
}, "private-key.asc", ".asc");
});
}
kbpgp.KeyManager.import_from_armored_pgp({
armored: getStorage("signingkey")
}, function (err, key) {
if (!err) {
if (key.is_pgp_locked()) {
key.unlock_pgp({
passphrase: pass
}, function (err) {
if (!err) {
savepriv(key);
} else {
showAlert("Could not unlock key. Password is probably incorrect.");
}
});
} else {
writeToFile(path, pgp_private);
console.log("Loaded private key w/o passphrase");
savepriv(key);
}
});
}, "private-key.asc", ".asc");
}
kbpgp.KeyManager.import_from_armored_pgp({
armored: getStorage("signingkey")
}, function (err, key) {
if (!err) {
if (key.is_pgp_locked()) {
key.unlock_pgp({
passphrase: pass
}, function (err) {
if (!err) {
savepriv(key);
} else {
showAlert("Could not unlock key. Password is probably incorrect.");
}
});
} else {
console.log("Loaded private key w/o passphrase");
savepriv(key);
showAlert("Could not unlock key: " + err);
}
} else {
showAlert("Could not unlock key: " + err);
}
});
});
}
@ -249,15 +253,16 @@ function importPrivateKey() {
keymgr = null;
openFileDialog(function (path) {
var keyfile = getFileAsString(path);
var pass = prompt("Enter password for imported key (password was set when exported):");
loadPrivateKey(keyfile, pass, function (key) {
if (typeof key == "undefined") {
showAlert("Could not import key. Password is probably incorrect.");
return;
}
keymgr = key;
setStorage("signingkey", keymgr.armored_pgp_private);
showAlert("Private key imported.");
showPasswordPrompt("Enter password for imported key (password was set when exported):", function (pass) {
loadPrivateKey(keyfile, pass, function (key) {
if (typeof key == "undefined") {
showAlert("Could not import key. Password is probably incorrect.");
return;
}
keymgr = key;
setStorage("signingkey", keymgr.armored_pgp_private);
showAlert("Private key imported.");
});
});
}, ".asc");
}

@ -242,6 +242,25 @@ function showAlert(message) {
new bootstrap.Modal(document.getElementById('alertModal')).show();
}
var passwordModalCallback = function (pass) {};
function showPasswordPrompt(message, callback) {
$("#passwordModalText").html(message);
$("#passwordModalInput").val("");
passwordModalCallback = callback;
new bootstrap.Modal(document.getElementById('passwordModal')).show();
}
$("#passwordModal").on("shown.bs.modal", function () {
$("#passwordModalInput").focus();
});
$(".modal").on("keydown", function (e) {
if (e.keyCode == 13) {
$(this).find(".btn-default").first().click();
}
});
$(document).ready(function () {
setButtonSize(getStorage("button_size"));
setAppTheme(getStorage("color_theme"));

Loading…
Cancel
Save