diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 797c2ee34..31e3ca516 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -114,17 +114,16 @@ export const PgpUserStore = new class { * Returns the first library that can. */ async getKeyForSigning(email) { -/* // TODO: sign in PHP fails - let key = GnuPGUserStore.getPrivateKeyFor(email, 1); - if (key) { - return ['gnupg', key]; - } -*/ let key = OpenPGPUserStore.getPrivateKeyFor(email, 1); if (key) { return ['openpgp', key]; } + key = GnuPGUserStore.getPrivateKeyFor(email, 1); + if (key) { + return ['gnupg', key]; + } + // return await this.getMailvelopePrivateKeyFor(email, 1); } diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 8cf099c01..043909876 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -431,6 +431,7 @@ class ComposePopupView extends AbstractViewPopup { if (sign && !draft && sign[1]) { if ('openpgp' == sign[0]) { // Doesn't sign attachments + params.Html = params.Text = ''; let signed = new MimePart; signed.headers['Content-Type'] = 'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"'; @@ -441,19 +442,17 @@ class ComposePopupView extends AbstractViewPopup { signature.headers['Content-Transfer-Encoding'] = '7Bit'; signature.body = await OpenPGPUserStore.sign(data.toString(), sign[1], 1); signed.children.push(signature); + params.Signed = signed.toString(); + params.Boundary = signed.boundary; data = signed; -/* - } else if ('gnupg' == sign[0])) { + } else if ('gnupg' == sign[0]) { // TODO: sign in PHP fails +// params.SignData = data.toString(); params.SignFingerprint = sign[1].fingerprint; params.SignPassphrase = await GnuPGUserStore.sign(sign[1]); -*/ } else { throw 'Signing with ' + sign[0] + ' not yet implemented'; } - params.Signed = data.toString(); - params.Boundary = data.boundary; - params.Html = params.Text = ''; } if (encrypt) { if ('openpgp' == encrypt) { diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamFilters/LineEndings.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamFilters/LineEndings.php new file mode 100644 index 000000000..bc9bb6fbb --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamFilters/LineEndings.php @@ -0,0 +1,34 @@ +data = \preg_replace('/\R/s', "\r\n", \rtrim($bucket->data, "\r")); +// $bucket->data = \preg_replace('/\R/s', "\n", \rtrim($bucket->data, "\r")); + $consumed += $bucket->datalen; + \stream_bucket_append($out, $bucket); + } +/* + private $buffer = ''; + while ($bucket = \stream_bucket_make_writeable($in)) { + $this->buffer += $bucket->data; + $consumed += $bucket->datalen; + } + $this->buffer = \preg_replace('/\R/s', "\r\n", $this->buffer); + \stream_bucket_append($out, \stream_bucket_new($this->stream, $this->buffer)); + $this->buffer = ''; +*/ + return PSFS_PASS_ON; + } + + public static function appendTo($fp) + { + \stream_filter_append($fp, 'crlf', STREAM_FILTER_ALL); + } +} + +\stream_filter_register('crlf', 'MailSo\\Base\\StreamFilters\\LineEndings'); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/PartCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/PartCollection.php index 17172c8a6..e5f7f4395 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/PartCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/PartCollection.php @@ -54,7 +54,7 @@ class PartCollection extends \MailSo\Base\Collection $aResult[] = "\r\n--{$this->sBoundary}\r\n"; $aResult[] = $oPart->ToStream(); } - $aResult[] = "\r\n--{$this->sBoundary}--"; + $aResult[] = "\r\n--{$this->sBoundary}--\r\n"; return \MailSo\Base\StreamWrappers\SubStreams::CreateStream($aResult); } return null; 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 b46c321ea..63aa43665 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 @@ -1271,21 +1271,23 @@ trait Messages $sFingerprint = $this->GetActionParam('SignFingerprint', ''); $sPassphrase = $this->GetActionParam('SignPassphrase', ''); if ($sFingerprint) { - // TODO: but verify is still invalid - throw new \Exception('Sign using GnuPG not working yet'); -/* $GPG = $this->GnuPG(); $oBody = $oMessage->GetRootPart(); $fp = \fopen('php://memory', 'r+b'); $resource = $oBody->ToStream(); -// \MailSo\Base\StreamFilters\LineEndings::appendTo($resource); + $oBody->Body = null; + $oBody->SubParts->Clear(); + $oMessage->SubParts->Clear(); + $oMessage->Attachments()->Clear(); + + \MailSo\Base\StreamFilters\LineEndings::appendTo($resource); \stream_copy_to_stream($resource, $fp); $GPG->addSignKey($sFingerprint, $sPassphrase); $GPG->setsignmode(GNUPG_SIG_MODE_DETACH); $sSignature = $GPG->signStream($fp); - - $oMessage->SubParts->Clear(); - $oMessage->Attachments()->Clear(); + if (!$sSignature) { + throw new \Exception('GnuPG sign() failed'); + } $oPart = new MimePart; $oPart->Headers->AddByName( @@ -1296,16 +1298,13 @@ trait Messages \rewind($fp); $oBody->Raw = $fp; - $oBody->Body = null; - $oBody->SubParts->Clear(); $oPart->SubParts->append($oBody); - $oAlternativePart = new MimePart; - $oAlternativePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'application/pgp-signature; name="signature.asc"'); - $oAlternativePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, '7Bit'); - $oAlternativePart->Body = $sSignature; - $oPart->SubParts->append($oAlternativePart); -*/ + $oSignaturePart = new MimePart; + $oSignaturePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'application/pgp-signature; name="signature.asc"'); + $oSignaturePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, '7Bit'); + $oSignaturePart->Body = $sSignature; + $oPart->SubParts->append($oSignaturePart); } $aFingerprints = \json_decode($this->GetActionParam('EncryptFingerprints', ''), true);