mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 16:07:03 +03:00
#89 Added signing using GnuPG
This commit is contained in:
parent
8d0154530c
commit
2c5322129c
5 changed files with 59 additions and 28 deletions
|
|
@ -114,17 +114,16 @@ export const PgpUserStore = new class {
|
||||||
* Returns the first library that can.
|
* Returns the first library that can.
|
||||||
*/
|
*/
|
||||||
async getKeyForSigning(email) {
|
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);
|
let key = OpenPGPUserStore.getPrivateKeyFor(email, 1);
|
||||||
if (key) {
|
if (key) {
|
||||||
return ['openpgp', key];
|
return ['openpgp', key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key = GnuPGUserStore.getPrivateKeyFor(email, 1);
|
||||||
|
if (key) {
|
||||||
|
return ['gnupg', key];
|
||||||
|
}
|
||||||
|
|
||||||
// return await this.getMailvelopePrivateKeyFor(email, 1);
|
// return await this.getMailvelopePrivateKeyFor(email, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -431,6 +431,7 @@ class ComposePopupView extends AbstractViewPopup {
|
||||||
if (sign && !draft && sign[1]) {
|
if (sign && !draft && sign[1]) {
|
||||||
if ('openpgp' == sign[0]) {
|
if ('openpgp' == sign[0]) {
|
||||||
// Doesn't sign attachments
|
// Doesn't sign attachments
|
||||||
|
params.Html = params.Text = '';
|
||||||
let signed = new MimePart;
|
let signed = new MimePart;
|
||||||
signed.headers['Content-Type'] =
|
signed.headers['Content-Type'] =
|
||||||
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
|
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
|
||||||
|
|
@ -441,19 +442,17 @@ class ComposePopupView extends AbstractViewPopup {
|
||||||
signature.headers['Content-Transfer-Encoding'] = '7Bit';
|
signature.headers['Content-Transfer-Encoding'] = '7Bit';
|
||||||
signature.body = await OpenPGPUserStore.sign(data.toString(), sign[1], 1);
|
signature.body = await OpenPGPUserStore.sign(data.toString(), sign[1], 1);
|
||||||
signed.children.push(signature);
|
signed.children.push(signature);
|
||||||
|
params.Signed = signed.toString();
|
||||||
|
params.Boundary = signed.boundary;
|
||||||
data = signed;
|
data = signed;
|
||||||
/*
|
} else if ('gnupg' == sign[0]) {
|
||||||
} else if ('gnupg' == sign[0])) {
|
|
||||||
// TODO: sign in PHP fails
|
// TODO: sign in PHP fails
|
||||||
|
// params.SignData = data.toString();
|
||||||
params.SignFingerprint = sign[1].fingerprint;
|
params.SignFingerprint = sign[1].fingerprint;
|
||||||
params.SignPassphrase = await GnuPGUserStore.sign(sign[1]);
|
params.SignPassphrase = await GnuPGUserStore.sign(sign[1]);
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
||||||
}
|
}
|
||||||
params.Signed = data.toString();
|
|
||||||
params.Boundary = data.boundary;
|
|
||||||
params.Html = params.Text = '';
|
|
||||||
}
|
}
|
||||||
if (encrypt) {
|
if (encrypt) {
|
||||||
if ('openpgp' == encrypt) {
|
if ('openpgp' == encrypt) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailSo\Base\StreamFilters;
|
||||||
|
|
||||||
|
class LineEndings extends \php_user_filter
|
||||||
|
{
|
||||||
|
public function filter($in, $out, &$consumed, $closing)
|
||||||
|
{
|
||||||
|
while ($bucket = \stream_bucket_make_writeable($in)) {
|
||||||
|
$bucket->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');
|
||||||
|
|
@ -54,7 +54,7 @@ class PartCollection extends \MailSo\Base\Collection
|
||||||
$aResult[] = "\r\n--{$this->sBoundary}\r\n";
|
$aResult[] = "\r\n--{$this->sBoundary}\r\n";
|
||||||
$aResult[] = $oPart->ToStream();
|
$aResult[] = $oPart->ToStream();
|
||||||
}
|
}
|
||||||
$aResult[] = "\r\n--{$this->sBoundary}--";
|
$aResult[] = "\r\n--{$this->sBoundary}--\r\n";
|
||||||
return \MailSo\Base\StreamWrappers\SubStreams::CreateStream($aResult);
|
return \MailSo\Base\StreamWrappers\SubStreams::CreateStream($aResult);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1271,21 +1271,23 @@ trait Messages
|
||||||
$sFingerprint = $this->GetActionParam('SignFingerprint', '');
|
$sFingerprint = $this->GetActionParam('SignFingerprint', '');
|
||||||
$sPassphrase = $this->GetActionParam('SignPassphrase', '');
|
$sPassphrase = $this->GetActionParam('SignPassphrase', '');
|
||||||
if ($sFingerprint) {
|
if ($sFingerprint) {
|
||||||
// TODO: but verify is still invalid
|
|
||||||
throw new \Exception('Sign using GnuPG not working yet');
|
|
||||||
/*
|
|
||||||
$GPG = $this->GnuPG();
|
$GPG = $this->GnuPG();
|
||||||
$oBody = $oMessage->GetRootPart();
|
$oBody = $oMessage->GetRootPart();
|
||||||
$fp = \fopen('php://memory', 'r+b');
|
$fp = \fopen('php://memory', 'r+b');
|
||||||
$resource = $oBody->ToStream();
|
$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);
|
\stream_copy_to_stream($resource, $fp);
|
||||||
$GPG->addSignKey($sFingerprint, $sPassphrase);
|
$GPG->addSignKey($sFingerprint, $sPassphrase);
|
||||||
$GPG->setsignmode(GNUPG_SIG_MODE_DETACH);
|
$GPG->setsignmode(GNUPG_SIG_MODE_DETACH);
|
||||||
$sSignature = $GPG->signStream($fp);
|
$sSignature = $GPG->signStream($fp);
|
||||||
|
if (!$sSignature) {
|
||||||
$oMessage->SubParts->Clear();
|
throw new \Exception('GnuPG sign() failed');
|
||||||
$oMessage->Attachments()->Clear();
|
}
|
||||||
|
|
||||||
$oPart = new MimePart;
|
$oPart = new MimePart;
|
||||||
$oPart->Headers->AddByName(
|
$oPart->Headers->AddByName(
|
||||||
|
|
@ -1296,16 +1298,13 @@ trait Messages
|
||||||
|
|
||||||
\rewind($fp);
|
\rewind($fp);
|
||||||
$oBody->Raw = $fp;
|
$oBody->Raw = $fp;
|
||||||
$oBody->Body = null;
|
|
||||||
$oBody->SubParts->Clear();
|
|
||||||
$oPart->SubParts->append($oBody);
|
$oPart->SubParts->append($oBody);
|
||||||
|
|
||||||
$oAlternativePart = new MimePart;
|
$oSignaturePart = new MimePart;
|
||||||
$oAlternativePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'application/pgp-signature; name="signature.asc"');
|
$oSignaturePart->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');
|
$oSignaturePart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, '7Bit');
|
||||||
$oAlternativePart->Body = $sSignature;
|
$oSignaturePart->Body = $sSignature;
|
||||||
$oPart->SubParts->append($oAlternativePart);
|
$oPart->SubParts->append($oSignaturePart);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$aFingerprints = \json_decode($this->GetActionParam('EncryptFingerprints', ''), true);
|
$aFingerprints = \json_decode($this->GetActionParam('EncryptFingerprints', ''), true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue