Make nice password prompts, handle enter key on modals, minor UI tweaks
This commit is contained in:
parent
57698559d9
commit
02a4f1d3fe
@ -135,7 +135,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
<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>
|
</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-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<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>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
@ -158,12 +158,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||||||
<span id="signatureRemoteUrlLabel"></span>
|
<span id="signatureRemoteUrlLabel"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="list-group-item">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<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>
|
</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-content">
|
||||||
<div class="modal-body p-1"></div>
|
<div class="modal-body p-1"></div>
|
||||||
<div class="modal-footer p-1">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
129
src/js/crypto.js
129
src/js/crypto.js
@ -20,27 +20,29 @@ function loadKeyFromLocalStorage(callback) {
|
|||||||
}
|
}
|
||||||
$("#lockstatus").css("display", "none");
|
$("#lockstatus").css("display", "none");
|
||||||
if (!inStorage("signingkey") || getStorage("signingkey") == "undefined") {
|
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.");
|
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) {
|
generatePrivateKey(getStorage("notary_name") + " <null@null.com>", pass, function (key) {
|
||||||
if (typeof key == "undefined") {
|
if (typeof key == "undefined") {
|
||||||
callback("Could not generate key.", false);
|
callback("Could not generate key.", false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keymgr = key;
|
keymgr = key;
|
||||||
keyring.add_key_manager(keymgr);
|
keyring.add_key_manager(keymgr);
|
||||||
setStorage("signingkey", keymgr.armored_pgp_private);
|
setStorage("signingkey", keymgr.armored_pgp_private);
|
||||||
callback("Signing key generated.", true);
|
callback("Signing key generated.", true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var pass = prompt("Enter password to unlock signing key:");
|
showPasswordPrompt("Enter password to unlock signing key:", function (pass) {
|
||||||
loadPrivateKey(getStorage("signingkey"), pass, function (key) {
|
loadPrivateKey(getStorage("signingkey"), pass, function (key) {
|
||||||
if (typeof key == "undefined") {
|
if (typeof key == "undefined") {
|
||||||
callback("Could not unlock key. Password is probably incorrect.", false);
|
callback("Could not unlock key. Password is probably incorrect.", false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keymgr = key;
|
keymgr = key;
|
||||||
keyring.add_key_manager(keymgr);
|
keyring.add_key_manager(keymgr);
|
||||||
callback("Signing key unlocked.", true);
|
callback("Signing key unlocked.", true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,42 +203,44 @@ function exportPublicKey() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function exportPrivateKey() {
|
function exportPrivateKey() {
|
||||||
var pass = prompt("Enter password for private key:");
|
showPasswordPrompt("Enter password for private key:", function (pass) {
|
||||||
const savepriv = function (key) {
|
const savepriv = function (key) {
|
||||||
var pass2 = prompt("Enter a password to protect the key backup:");
|
showPasswordPrompt("Enter a password to protect the key backup:", function (pass2) {
|
||||||
openSaveFileDialog(function (path) {
|
openSaveFileDialog(function (path) {
|
||||||
key.export_pgp_private({
|
key.export_pgp_private({
|
||||||
passphrase: pass2
|
passphrase: pass2
|
||||||
}, function (err, pgp_private) {
|
}, function (err, pgp_private) {
|
||||||
if (err) {
|
if (err) {
|
||||||
showAlert("Something went wrong.");
|
showAlert("Something went wrong.");
|
||||||
} else {
|
} else {
|
||||||
writeToFile(path, pgp_private);
|
writeToFile(path, pgp_private);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}, "private-key.asc", ".asc");
|
||||||
});
|
});
|
||||||
}, "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);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showAlert("Could not unlock key: " + err);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showAlert("Could not unlock key: " + err);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,15 +253,16 @@ function importPrivateKey() {
|
|||||||
keymgr = null;
|
keymgr = null;
|
||||||
openFileDialog(function (path) {
|
openFileDialog(function (path) {
|
||||||
var keyfile = getFileAsString(path);
|
var keyfile = getFileAsString(path);
|
||||||
var pass = prompt("Enter password for imported key (password was set when exported):");
|
showPasswordPrompt("Enter password for imported key (password was set when exported):", function (pass) {
|
||||||
loadPrivateKey(keyfile, pass, function (key) {
|
loadPrivateKey(keyfile, pass, function (key) {
|
||||||
if (typeof key == "undefined") {
|
if (typeof key == "undefined") {
|
||||||
showAlert("Could not import key. Password is probably incorrect.");
|
showAlert("Could not import key. Password is probably incorrect.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keymgr = key;
|
keymgr = key;
|
||||||
setStorage("signingkey", keymgr.armored_pgp_private);
|
setStorage("signingkey", keymgr.armored_pgp_private);
|
||||||
showAlert("Private key imported.");
|
showAlert("Private key imported.");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, ".asc");
|
}, ".asc");
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,25 @@ function showAlert(message) {
|
|||||||
new bootstrap.Modal(document.getElementById('alertModal')).show();
|
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 () {
|
$(document).ready(function () {
|
||||||
setButtonSize(getStorage("button_size"));
|
setButtonSize(getStorage("button_size"));
|
||||||
setAppTheme(getStorage("color_theme"));
|
setAppTheme(getStorage("color_theme"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user