Get S/MIME encryption working #259

This commit is contained in:
the-djmaze 2024-02-20 12:38:57 +01:00
parent 196dffa8d8
commit 1762198642
4 changed files with 60 additions and 39 deletions

View file

@ -1179,22 +1179,31 @@ trait Messages
}
$oMessage->addPgpEncrypted($GPG->encryptStream($fp));
} else {
$aCertificates = \json_decode($this->GetActionParam('encryptCertificates', ''), true);
$aCertificates = $this->GetActionParam('encryptCertificates', []);
if ($aCertificates) {
$tmp = new \SnappyMail\File\Temporary('mimepart');
$tmp->writeFromStream($oMessage->GetRootPart()->ToStream());
$oBody = $oMessage->GetRootPart();
$resource = $oBody->ToStream();
\MailSo\Base\StreamFilters\LineEndings::appendTo($resource);
$tmp = new \SnappyMail\File\Temporary('mimepart');
$tmp->writeFromStream($resource);
$oBody->Body = null;
$oBody->SubParts->Clear();
$oMessage->SubParts->Clear();
$oMessage->Attachments()->Clear();
$SMIME = $this->SMIME();
/*
foreach ($aCertificates as $sCertificate) {
$SMIME->addEncryptKey($sCertificate);
}
*/
$sEncrypted = $SMIME->encrypt($tmp, $aCertificates);
$oMessage->addSMimeEncrypted($sEncrypted);
$oPart = new MimePart;
$oMessage->SubParts->append($oPart);
$oPart->Headers->AddByName(
MimeEnumHeader::CONTENT_TYPE,
'application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"'
);
$oPart->Headers->AddByName(MimeEnumHeader::CONTENT_TRANSFER_ENCODING, 'base64');
$oPart->Body = $sEncrypted;
}
}