From 7a85a75ca9c352a155c6c57c01670a1c8929fb34 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 8 Aug 2022 09:26:45 +0200 Subject: [PATCH] Allow private keys without passphrase in local browser storage as requested by #429 --- dev/Stores/User/OpenPGP.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dev/Stores/User/OpenPGP.js b/dev/Stores/User/OpenPGP.js index 5e929ec13..24c860492 100644 --- a/dev/Stores/User/OpenPGP.js +++ b/dev/Stores/User/OpenPGP.js @@ -178,16 +178,20 @@ export const OpenPGPUserStore = new class { } } if (privateKey) try { - const passphrase = await askPassphrase(privateKey, 'BUTTON_DECRYPT'); - - if (null !== passphrase) { - const - publicKey = findOpenPGPKey(this.publicKeys, sender/*, sign*/), + let decryptedKey; + if (privateKey.key.isDecrypted()) { + decryptedKey = privateKey; + } else { + const passphrase = await askPassphrase(privateKey, 'BUTTON_DECRYPT'); + if (null !== passphrase) { decryptedKey = await openpgp.decryptKey({ privateKey: privateKey.key, passphrase }); - + } + } + if (decryptedKey) { + const publicKey = findOpenPGPKey(this.publicKeys, sender/*, sign*/); return await openpgp.decrypt({ message, verificationKeys: publicKey && publicKey.key,