From ce971de919197f2f01c64c5220b3304314798951 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 24 Jan 2022 13:43:53 +0100 Subject: [PATCH] Get PGP verify message working using Promise. #89 --- dev/Settings/User/OpenPgp.js | 6 ++ dev/Stores/User/Pgp.js | 31 ++++--- dev/View/User/MailBox/MessageView.js | 86 ++++++++++--------- .../app/libraries/snappymail/pgp/gnupg.php | 4 +- .../templates/Views/User/SettingsOpenPGP.html | 5 ++ 5 files changed, 74 insertions(+), 58 deletions(-) diff --git a/dev/Settings/User/OpenPgp.js b/dev/Settings/User/OpenPgp.js index 1c1a0d5ab..03cd5e028 100644 --- a/dev/Settings/User/OpenPgp.js +++ b/dev/Settings/User/OpenPgp.js @@ -21,6 +21,7 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ { this.canOpenPGP = !!PgpUserStore.openpgpKeyring; // this.canOpenPGP = Settings.capa(Capa.OpenPGP); + this.canMailvelope = !!window.mailvelope; this.allowDraftAutosave = SettingsUserStore.allowDraftAutosave; @@ -41,6 +42,11 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ { } } + onBuild() { + window.mailvelope + && mailvelope.createSettingsContainer('#mailvelope-settings'/*[, keyring], options*/); + } + /** * @param {OpenPgpKeyModel} openPgpKeyToRemove * @returns {void} diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 74934261b..ebb66c206 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -270,21 +270,24 @@ export const PgpUserStore = new class { * @returns {void} */ deleteKey(openPgpKeyToRemove) { - if (openPgpKeyToRemove && openPgpKeyToRemove.deleteAccess() && this.openpgpKeyring) { - let findedItem = this.openpgpPublicKeys.find(key => openPgpKeyToRemove === key); - if (findedItem) { - this.openpgpPublicKeys.remove(findedItem); - this.openpgpKeyring.publicKeys.removeForId(findedItem.guid); - } else { - findedItem = this.openpgpPrivateKeys.find(key => openPgpKeyToRemove === key); - if (findedItem) { - this.openpgpPrivateKeys.remove(findedItem); - this.openpgpKeyring.privateKeys.removeForId(findedItem.guid); - } + const openpgpKeyring = this.openpgpKeyring; + if (openPgpKeyToRemove && openPgpKeyToRemove.deleteAccess() && openpgpKeyring) { + let items = [ + this.openpgpPrivateKeys.find(key => openPgpKeyToRemove === key), + this.openpgpPublicKeys.find(key => openPgpKeyToRemove === key) + ]; + if (items[0]) { + this.openpgpPrivateKeys.remove(items[0]); + openpgpKeyring.privateKeys.removeForId(items[0].guid); + delegateRunOnDestroy(items[0]); } - if (findedItem) { - delegateRunOnDestroy(findedItem); - this.openpgpKeyring.store(); + if (items[1]) { + this.openpgpPublicKeys.remove(items[1]); + openpgpKeyring.publicKeys.removeForId(items[1].guid); + delegateRunOnDestroy(items[1]); + } + if (items[0] || items[1]) { + openpgpKeyring.store(); } // this.reloadOpenPgpKeys(); } diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 50610fad7..a8db6de92 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -635,52 +635,54 @@ export class MailMessageView extends AbstractViewRight { pgpVerify(self) { const message = self.message(); if (message && PgpUserStore.isSupported()) { - const mode = PgpUserStore.hasPublicKeyForEmails([message.from[0].email()]); - if ('gnupg' === mode) { - let params = message.pgpSigned(); // { BodyPartId: "1", SigPartId: "2", MicAlg: "pgp-sha256" } - if (params) { - params.Folder = message.folder; - params.Uid = message.uid; - rl.app.Remote.post('MessagePgpVerify', null, params) - .then(data => { - // TODO - console.dir(data); - }) - .catch(error => { - // TODO - console.dir(error); - }); - } - } else if ('openpgp' === mode) { - let text = null; - try { - text = PgpUserStore.openpgp.cleartext.readArmored(message.plain); - } catch (e) { - console.error(e); - } - if (text && text.getText && text.verify) { - PgpUserStore.verifyMessage(text, (validKey, signingKeyIds) => { - console.dir([validKey, signingKeyIds]); -/* - if (validKey) { - i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', { - USER: validKey.user + ' (' + validKey.id + ')' + PgpUserStore.hasPublicKeyForEmails([message.from[0].email]).then(mode => { + if ('gnupg' === mode) { + let params = message.pgpSigned(); // { BodyPartId: "1", SigPartId: "2", MicAlg: "pgp-sha256" } + if (params) { + params.Folder = message.folder; + params.Uid = message.uid; + rl.app.Remote.post('MessagePgpVerify', null, params) + .then(data => { + // TODO + console.dir(data); + }) + .catch(error => { + // TODO + console.dir(error); }); - message.getText() - } else { - const keyIds = arrayLength(signingKeyIds) ? signingKeyIds : null, - additional = keyIds - ? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ') - : ''; + } + } else if ('openpgp' === mode) { + let text = null; + try { + // TODO: if message.pgpSigned().SigPartId then fetch raw from server + text = PgpUserStore.openpgp.cleartext.readArmored(message.plain); + } catch (e) { + console.error(e); + } + if (text && text.getText && text.verify) { + PgpUserStore.verifyMessage(text, (validKey, signingKeyIds) => { + console.dir([validKey, signingKeyIds]); +/* + if (validKey) { + i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', { + USER: validKey.user + ' (' + validKey.id + ')' + }); + message.getText() + } else { + const keyIds = arrayLength(signingKeyIds) ? signingKeyIds : null, + additional = keyIds + ? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ') + : ''; - i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (additional ? ' (' + additional + ')' : ''); - } + i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (additional ? ' (' + additional + ')' : ''); + } */ - }); - } else { -// controlsHelper(dom, this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR')); + }); + } else { +// controlsHelper(dom, this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR')); + } } - } + }); } } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/pgp/gnupg.php b/snappymail/v/0.0.0/app/libraries/snappymail/pgp/gnupg.php index 83d3fd425..3444aaccd 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/pgp/gnupg.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/pgp/gnupg.php @@ -602,7 +602,7 @@ class GnuPG return $this->GPG->verify($signed_text, $signature, $plaintext); } if ($this->Crypt_GPG) { - return $this->Crypt_GPG->verify($signed_text, $signature = ''); + return $this->Crypt_GPG->verify($signed_text, $signature); } return false; } @@ -619,7 +619,7 @@ class GnuPG return $this->GPG->verifyFile($filename, $signature, $plaintext); } if ($this->Crypt_GPG) { - return $this->Crypt_GPG->verifyFile($filename, $signature = ''); + return $this->Crypt_GPG->verifyFile($filename, $signature); } return false; } diff --git a/snappymail/v/0.0.0/app/templates/Views/User/SettingsOpenPGP.html b/snappymail/v/0.0.0/app/templates/Views/User/SettingsOpenPGP.html index 527ab96ed..db151c9a8 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/SettingsOpenPGP.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/SettingsOpenPGP.html @@ -83,3 +83,8 @@ + + +