From 574fd820a6360273d0382b500edeabe906b9259a Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 4 Mar 2024 15:01:47 +0100 Subject: [PATCH] S/MIME don't post identity key and certificate, just fetch from server --- dev/Stores/User/GnuPG.js | 4 +-- dev/View/Popup/Compose.js | 7 ++--- .../libraries/RainLoop/Actions/Messages.php | 26 ++++++++++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/dev/Stores/User/GnuPG.js b/dev/Stores/User/GnuPG.js index b7e3ab696..66a7ad2a5 100644 --- a/dev/Stores/User/GnuPG.js +++ b/dev/Stores/User/GnuPG.js @@ -69,7 +69,7 @@ export const GnuPGUserStore = new class { } }; if (isPrivate) { - key.password = async (btnTxt = 'CRYPTO/SIGN') => { + key.password = async btnTxt => { const pass = await Passphrases.ask(key, 'GnuPG key
' + key.id + ' ' + key.emails[0], btnTxt @@ -228,7 +228,7 @@ export const GnuPGUserStore = new class { } async sign(privateKey) { - return await privateKey.password(); + return await privateKey.password('CRYPTO/SIGN'); } }; diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 4384c5b25..cb0010873 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -1561,12 +1561,13 @@ export class ComposePopupView extends AbstractViewPopup { } if ('S/MIME' == signOptions[i][0]) { // TODO: sign in PHP fails - params.signCertificate = identity.smimeCertificate(); - params.signPrivateKey = identity.smimeKey(); + params.sign = 'S/MIME'; +// params.signCertificate = identity.smimeCertificate(); +// params.signPrivateKey = identity.smimeKey(); if (identity.smimeKeyEncrypted()) { const pass = await Passphrases.ask(identity, i18n('SMIME/PRIVATE_KEY_OF', {EMAIL: identity.email()}), - 'CRYPTO/DECRYPT' + 'CRYPTO/SIGN' ); if (null != pass) { params.signPassphrase = pass.password; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index f168a9fa5..2a120bf5f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -930,14 +930,15 @@ trait Messages $oMessage->DoesNotAddDefaultXMailer(); } - $sFrom = $this->GetActionParam('from', ''); - $oMessage->SetFrom(\MailSo\Mime\Email::Parse($sFrom)); + $oMessage->SetFrom(\MailSo\Mime\Email::Parse($this->GetActionParam('from', ''))); + $oFrom = $oMessage->GetFrom(); + /* - $oFromIdentity = $this->GetIdentityByID($oAccount, $this->GetActionParam('identityID', '')); - if ($oFromIdentity) + $oIdentity = $this->GetIdentityByID($oAccount, $this->GetActionParam('identityID', '')); + if ($oIdentity) { $oMessage->SetFrom(new \MailSo\Mime\Email( - $oFromIdentity->Email(), $oFromIdentity->Name())); + $oIdentity->Email(), $oIdentity->Name())); if ($oAccount->Domain()->OutSetSender()) { $oMessage->SetSender(\MailSo\Mime\Email::Parse($oAccount->Email())); } @@ -947,14 +948,13 @@ trait Messages $oMessage->SetFrom(\MailSo\Mime\Email::Parse($oAccount->Email())); } */ - $oFrom = $oMessage->GetFrom(); $oMessage->RegenerateMessageId($oFrom ? $oFrom->GetDomain() : ''); $oMessage->SetReplyTo(new \MailSo\Mime\EmailCollection($this->GetActionParam('replyTo', ''))); if (!empty($this->GetActionParam('readReceiptRequest', 0))) { // Read Receipts Reference Main Account Email, Not Identities #147 -// $oMessage->SetReadReceipt(($oFromIdentity ?: $oAccount)->Email()); +// $oMessage->SetReadReceipt(($oIdentity ?: $oAccount)->Email()); $oMessage->SetReadReceipt($oFrom->GetEmail()); } @@ -1169,6 +1169,18 @@ trait Messages } else { $sCertificate = $this->GetActionParam('signCertificate', ''); $sPrivateKey = $this->GetActionParam('signPrivateKey', ''); + if ('S/MIME' === $this->GetActionParam('sign', '')) { + $sID = $this->GetActionParam('identityID', ''); + foreach ($this->GetIdentities($oAccount) as $oIdentity) { + if ($oIdentity && $oIdentity->smimeCertificate && $oIdentity->smimeKey + && ($oIdentity->Id() === $sID || $oIdentity->Email() === $oFrom->GetEmail()) + ) { + $sCertificate = $oIdentity->smimeCertificate; + $sPrivateKey = $oIdentity->smimeKey; + break; + } + } + } if ($sCertificate && $sPrivateKey) { $oBody = $oMessage->GetRootPart();