Skip to content

[Mailer][Mime] Refactor S/MIME encryption handling in SMimeEncryptionListener #20935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@
framework:
mailer:
smime_encrypter:
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
repository: app.my_smime_encrypter

Check failure on line 1535 in mailer.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In CheckExceptionOnInvalidReferenceBehaviorPass.php line 116: The service "mailer.smime_encrypter.listener" has a dependency on a non-exi stent service "app.my_smime_encrypter".

.. code-block:: xml

Expand All @@ -1549,7 +1549,7 @@
<framework:config>
<framework:mailer>
<framework:smime-encrypter>
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
<framework:repository>app.my_smime_encrypter</framework:repository>
</framework:smime-encrypter>
</framework:mailer>
</framework:config>
Expand All @@ -1563,10 +1563,35 @@
return static function (FrameworkConfig $framework): void {
$mailer = $framework->mailer();
$mailer->smimeEncrypter()
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
->repository('app.my_smime_encrypter')
;
};

Check failure on line 1568 in mailer.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In CheckExceptionOnInvalidReferenceBehaviorPass.php line 116: The service "mailer.smime_encrypter.listener" has a dependency on a non-exi stent service "app.my_smime_encrypter".

The ``repository`` option must be a service ID that implements
:class:`Symfony\\Component\\Mailer\\EventListener\\SmimeCertificateRepositoryInterface`::

namespace App\Security;

use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mailer\EventListener\SmimeCertificateRepositoryInterface;

class LocalFileCertificateRepository implements SmimeCertificateRepositoryInterface
{
public function __construct(
#[Autowire(param: 'kernel.project_dir')]
private readonly string $projectDir
){}

public function findCertificatePathFor(string $email): ?string
{
$hash = hash('sha256', strtolower(trim($email)));
$path = sprintf('%s/storage/%s.crt', $this->projectDir, $hash);

return file_exists($path) ? $path : null;
}
}


.. versionadded:: 7.3

Global message encryption configuration was introduced in Symfony 7.3.
Expand Down
Loading