This commit is contained in:
the-djmaze 2023-02-02 12:39:21 +01:00
parent af3cecb2e1
commit a52881fb67
43 changed files with 79 additions and 11 deletions

View file

@ -12,8 +12,15 @@ import { OpenPgpKeyPopupView } from 'View/Popup/OpenPgpKey';
import { AskPopupView } from 'View/Popup/Ask';
const
askPassphrase = async (privateKey, btnTxt = 'LABEL_SIGN') =>
await AskPopupView.password('GnuPG key<br>' + privateKey.id + ' ' + privateKey.emails[0], 'OPENPGP/'+btnTxt),
passphrases = new Map(),
askPassphrase = async (privateKey, btnTxt = 'LABEL_SIGN') => {
const key = privateKey.id,
pass = passphrases.has(key)
? {password:passphrases.get(key), remember:false}
: await AskPopupView.password('GnuPG key<br>' + key + ' ' + privateKey.emails[0], 'OPENPGP/'+btnTxt);
pass && pass.remember && passphrases.set(key, pass.password);
return pass.password;
},
findGnuPGKey = (keys, query/*, sign*/) =>
keys.find(key =>

View file

@ -18,15 +18,21 @@ const
key.emails.includes(query) || query == key.id || query == key.fingerprint
),
passphrases = new Map(),
decryptKey = async (privateKey, btnTxt = 'LABEL_SIGN') => {
if (privateKey.key.isDecrypted()) {
return privateKey.key;
}
const passphrase = await AskPopupView.password(
'OpenPGP.js key<br>' + privateKey.id + ' ' + privateKey.emails[0],
'OPENPGP/'+btnTxt
);
if (null !== passphrase) {
const key = privateKey.id,
pass = passphrases.has(key)
? {password:passphrases.get(key), remember:false}
: await AskPopupView.password(
'OpenPGP.js key<br>' + privateKey.id + ' ' + privateKey.emails[0],
'OPENPGP/'+btnTxt
);
if (pass) {
pass.remember && passphrases.set(key, pass.password);
let passphrase = pass.password;
return await openpgp.decryptKey({
privateKey: privateKey.key,
passphrase