Try and fail to fix exported private key having old password no matter what is requested

This commit is contained in:
Skylar Ittner 2021-07-02 01:31:20 -06:00
parent 0db3037450
commit 367daeca57

View File

@ -156,12 +156,12 @@ function exportPublicKey() {
} }
function exportPrivateKey() { function exportPrivateKey() {
loadKeyFromLocalStorage(function (message, ok) { var pass = prompt("Enter password for private key:");
if (ok) { const savepriv = function (key) {
var pass = prompt("Enter a password to protect the backup key:"); var pass2 = prompt("Enter a password to protect the key backup:");
openSaveFileDialog(function (path) { openSaveFileDialog(function (path) {
keymgr.export_pgp_private({ key.export_pgp_private({
passphrase: pass passphrase: pass2
}, function (err, pgp_private) { }, function (err, pgp_private) {
if (err) { if (err) {
alert("Something went wrong."); alert("Something went wrong.");
@ -170,8 +170,27 @@ function exportPrivateKey() {
} }
}); });
}, "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 { } else {
alert("Error: " + message); alert("Could not unlock key. Password is probably incorrect.");
}
});
} else {
console.log("Loaded private key w/o passphrase");
savepriv(key);
}
} else {
alert("Could not unlock key: " + err);
} }
}); });
} }
@ -182,6 +201,7 @@ function importPrivateKey() {
return; return;
} }
} }
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):"); var pass = prompt("Enter password for imported key (password was set when exported):");