changed: enter pgp keys as a single file

This commit is contained in:
quenousimporte 2023-07-13 13:55:52 +02:00
parent d710a1f533
commit 723caa07ed
1 changed files with 27 additions and 19 deletions

46
main.js
View File

@ -15,8 +15,7 @@ var defaultsettings =
enablenetwork: false, enablenetwork: false,
titlebydefault: false, titlebydefault: false,
hideheaderbydefault: true, hideheaderbydefault: true,
linksinnewtab: true, linksinnewtab: true
pgp: false
}; };
//builtin //builtin
@ -342,6 +341,10 @@ var commands = [
hint: "Send by SMS", hint: "Send by SMS",
action: sms, action: sms,
remoteonly: true remoteonly: true
},
{
hint: "Edit pgp keys",
action: editpgpkeys
}]; }];
var snippets = [ var snippets = [
@ -878,6 +881,15 @@ function editsettings()
}); });
} }
function editpgpkeys()
{
bindfile(
{
title: "pgpkeys",
content: localStorage.getItem("pgpkeys")
});
}
function showtemporaryinfo(info) function showtemporaryinfo(info)
{ {
alert(info); alert(info);
@ -1143,18 +1155,6 @@ function loadsettings()
{ {
toggletitle(); toggletitle();
} }
if (settings.pgp)
{
if (!localStorage.getItem("publickey"))
{
localStorage.setItem("publickey", prompt("Public key"));
}
if (!localStorage.getItem("privatekey"))
{
localStorage.setItem("privatekey", prompt("Private key"));
}
}
} }
function checksaved() function checksaved()
@ -1450,10 +1450,11 @@ async function queryremote(params)
try try
{ {
var response = xhr.responseText; var response = xhr.responseText;
if (settings.pgp && response.startsWith("-----BEGIN PGP MESSAGE-----")) if (localStorage.getItem("pgpkeys") && response.startsWith("-----BEGIN PGP MESSAGE-----"))
{ {
console.log("decrypting...") console.log("decrypting...");
var privateKey = await openpgp.readKey({ armoredKey: localStorage.getItem("privatekey") }); var key = localStorage.getItem("pgpkeys").split("-----END PGP PUBLIC KEY BLOCK-----")[1];
var privateKey = await openpgp.readKey({ armoredKey: key });
var decrypted = await openpgp.decrypt({ var decrypted = await openpgp.decrypt({
message: await openpgp.readMessage({ armoredMessage: response }), message: await openpgp.readMessage({ armoredMessage: response }),
decryptionKeys: privateKey }); decryptionKeys: privateKey });
@ -1865,6 +1866,12 @@ async function save()
saved = true; saved = true;
return; return;
} }
else if (currentnote.title == "pgpkeys")
{
localStorage.setItem("pgpkeys", md.value);
saved = true;
return;
}
if (!localdata) if (!localdata)
{ {
@ -1901,10 +1908,11 @@ async function save()
if (isremote()) if (isremote())
{ {
var datatosend = JSON.stringify(localdata); var datatosend = JSON.stringify(localdata);
if (settings.pgp) if (localStorage.getItem("pgpkeys"))
{ {
console.log("encrypting..."); console.log("encrypting...");
var publicKey = await openpgp.readKey({ armoredKey: localStorage.getItem("publickey") }); var key = localStorage.getItem("pgpkeys").split("-----BEGIN PGP PRIVATE KEY BLOCK-----")[0];
var publicKey = await openpgp.readKey({ armoredKey: key });
datatosend = await openpgp.encrypt({ datatosend = await openpgp.encrypt({
message: await openpgp.createMessage({ text: datatosend }), message: await openpgp.createMessage({ text: datatosend }),
encryptionKeys: publicKey }); encryptionKeys: publicKey });