Skip to content

Commit a76a651

Browse files
committed
minor #20935 [Mailer][Mime] Refactor S/MIME encryption handling in SMimeEncryptionListener (alamirault)
This PR was merged into the 7.3 branch. Discussion ---------- [Mailer][Mime] Refactor S/MIME encryption handling in `SMimeEncryptionListener` Fix #20827 Having a `SmimeCertificateRepositoryInterface` implementation is a good thing I think. I don't really how to introduce it. Commits ------- c6a7fe6 [Mailer][Mime] Refactor S/MIME encryption handling in SMimeEncryptionListener
2 parents aefaa95 + c6a7fe6 commit a76a651

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

mailer.rst

+28-3
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ encrypter that automatically applies to all outgoing messages:
15321532
framework:
15331533
mailer:
15341534
smime_encrypter:
1535-
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
1535+
repository: app.my_smime_encrypter
15361536
15371537
.. code-block:: xml
15381538
@@ -1549,7 +1549,7 @@ encrypter that automatically applies to all outgoing messages:
15491549
<framework:config>
15501550
<framework:mailer>
15511551
<framework:smime-encrypter>
1552-
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
1552+
<framework:repository>app.my_smime_encrypter</framework:repository>
15531553
</framework:smime-encrypter>
15541554
</framework:mailer>
15551555
</framework:config>
@@ -1563,10 +1563,35 @@ encrypter that automatically applies to all outgoing messages:
15631563
return static function (FrameworkConfig $framework): void {
15641564
$mailer = $framework->mailer();
15651565
$mailer->smimeEncrypter()
1566-
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
1566+
->repository('app.my_smime_encrypter')
15671567
;
15681568
};
15691569
1570+
The ``repository`` option must be a service ID that implements
1571+
:class:`Symfony\\Component\\Mailer\\EventListener\\SmimeCertificateRepositoryInterface`::
1572+
1573+
namespace App\Security;
1574+
1575+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1576+
use Symfony\Component\Mailer\EventListener\SmimeCertificateRepositoryInterface;
1577+
1578+
class LocalFileCertificateRepository implements SmimeCertificateRepositoryInterface
1579+
{
1580+
public function __construct(
1581+
#[Autowire(param: 'kernel.project_dir')]
1582+
private readonly string $projectDir
1583+
){}
1584+
1585+
public function findCertificatePathFor(string $email): ?string
1586+
{
1587+
$hash = hash('sha256', strtolower(trim($email)));
1588+
$path = sprintf('%s/storage/%s.crt', $this->projectDir, $hash);
1589+
1590+
return file_exists($path) ? $path : null;
1591+
}
1592+
}
1593+
1594+
15701595
.. versionadded:: 7.3
15711596

15721597
Global message encryption configuration was introduced in Symfony 7.3.

0 commit comments

Comments
 (0)