Get S/MIME decrypt working for #259

This commit is contained in:
the-djmaze 2024-02-20 13:04:12 +01:00
parent 1762198642
commit 18d0ba4acb
3 changed files with 74 additions and 4 deletions

View file

@ -71,6 +71,47 @@ trait SMime
return $this->DefaultResponse($result ?: false);
}
public function DoSMimeDecryptMessage() : array
{
$sFolderName = $this->GetActionParam('folder', '');
$iUid = (int) $this->GetActionParam('uid', 0);
$sPartId = $this->GetActionParam('partId', '');
$sCertificate = $this->GetActionParam('certificate', '');
$sPrivateKey = $this->GetActionParam('privateKey', '');
$sPassphrase = $this->GetActionParam('passphrase', '');
$this->logMask($sPassphrase);
$this->initMailClientConnection();
$oImapClient = $this->ImapClient();
$oImapClient->FolderExamine($sFolderName);
if ('TEXT' === $sPartId) {
$oFetchResponse = $oImapClient->Fetch([
FetchType::BODY_PEEK.'['.$sPartId.']',
// An empty section specification refers to the entire message, including the header.
// But Dovecot does not return it with BODY.PEEK[1], so we also use BODY.PEEK[1.MIME].
FetchType::BODY_HEADER_PEEK
], $iUid, true)[0];
$sBody = $oFetchResponse->GetFetchValue(FetchType::BODY_HEADER);
} else {
$oFetchResponse = $oImapClient->Fetch([
FetchType::BODY_PEEK.'['.$sPartId.']',
// An empty section specification refers to the entire message, including the header.
// But Dovecot does not return it with BODY.PEEK[1], so we also use BODY.PEEK[1.MIME].
FetchType::BODY_PEEK.'['.$sPartId.'.MIME]'
], $iUid, true)[0];
$sBody = $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.'.MIME]');
}
$sBody .= $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.']');
$SMIME = $this->SMIME();
$SMIME->setCertificate($sCertificate);
$SMIME->setPrivateKey($sPrivateKey, $sPassphrase);
$result = $SMIME->decrypt($sBody);
return $this->DefaultResponse($result ?: false);
}
public function DoSMimeVerifyMessage() : array
{
$sFolderName = $this->GetActionParam('folder', '');

View file

@ -307,10 +307,8 @@
<div data-bind="visible: message().smimeEncrypted()">
<div class="crypto-control encrypted" data-bind="css: {success: message().smimeDecrypted()}">
<span data-icon="🔒" data-i18n="OPENPGP/ENCRYPTED_MESSAGE"></span>
<!-- TODO
<span data-icon="🔒" data-i18n="SMIME/ENCRYPTED_MESSAGE"></span>
<button class="btn" data-bind="click: smimeDecrypt" data-i18n="CRYPTO/DECRYPT"></button>
-->
</div>
</div>
<div data-bind="visible: message().smimeSigned()">