Skip to content

Commit 73f2dab

Browse files
committed
Refactor S/MIME encrypter to use certificate repository
Replaces direct certificate path usage with a repository interface for managing S/MIME certificates. This improves flexibility by allowing custom certificate retrieval logic through `SmimeCertificateRepositoryInterface`. Adjusted related tests, configuration, and event listener implementation accordingly.
1 parent 7aff669 commit 73f2dab

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,8 +2314,8 @@ private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enabl
23142314
->canBeEnabled()
23152315
->info('S/MIME encrypter configuration')
23162316
->children()
2317-
->scalarNode('certificate')
2318-
->info('Path to certificate (in PEM format without the `file://` prefix)')
2317+
->scalarNode('repository')
2318+
->info('Path to the S/MIME certificate repository. Shall implement the `Symfony\Component\Mailer\EventListener\SmimeCertificateRepositoryInterface`.')
23192319
->defaultValue('')
23202320
->cannotBeEmpty()
23212321
->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,11 +2893,9 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
28932893
if (!class_exists(SmimeEncryptedMessageListener::class)) {
28942894
throw new LogicException('S/MIME encrypted messages support cannot be enabled as this version of the Mailer component does not support it.');
28952895
}
2896-
$smimeDecrypter = $container->getDefinition('mailer.smime_encrypter');
2897-
$smimeDecrypter->setArgument(0, $config['smime_encrypter']['certificate']);
2898-
$smimeDecrypter->setArgument(1, $config['smime_encrypter']['cipher']);
2896+
$container->setAlias('mailer.smime_encrypter.repository', $config['smime_encrypter']['repository']);
2897+
$container->setParameter('mailer.smime_encrypter.cipher', $config['smime_encrypter']['cipher']);
28992898
} else {
2900-
$container->removeDefinition('mailer.smime_encrypter');
29012899
$container->removeDefinition('mailer.smime_encrypter.listener');
29022900
}
29032901

Resources/config/mailer.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Symfony\Component\Mailer\Transport\TransportInterface;
2727
use Symfony\Component\Mailer\Transport\Transports;
2828
use Symfony\Component\Mime\Crypto\DkimSigner;
29-
use Symfony\Component\Mime\Crypto\SMimeEncrypter;
3029
use Symfony\Component\Mime\Crypto\SMimeSigner;
3130

3231
return static function (ContainerConfigurator $container) {
@@ -102,12 +101,6 @@
102101
abstract_arg('signOptions'),
103102
])
104103

105-
->set('mailer.smime_encrypter', SMimeEncrypter::class)
106-
->args([
107-
abstract_arg('certificate'),
108-
abstract_arg('cipher'),
109-
])
110-
111104
->set('mailer.dkim_signer.listener', DkimSignedMessageListener::class)
112105
->args([
113106
service(DkimSigner::class),
@@ -122,7 +115,8 @@
122115

123116
->set('mailer.smime_encrypter.listener', SmimeEncryptedMessageListener::class)
124117
->args([
125-
service('mailer.smime_encrypter'),
118+
service('mailer.smime_encrypter.repository'),
119+
param('mailer.smime_encrypter.cipher'),
126120
])
127121
->tag('kernel.event_subscriber')
128122

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@
836836
</xsd:complexType>
837837

838838
<xsd:complexType name="mailer_smime_encrypter">
839-
<xsd:attribute name="certificate" type="xsd:string"/>
839+
<xsd:attribute name="repository" type="xsd:string" />
840840
<xsd:attribute name="cipher" type="xsd:integer" />
841841
</xsd:complexType>
842842

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
941941
],
942942
'smime_encrypter' => [
943943
'enabled' => false,
944-
'certificate' => '',
944+
'repository' => '',
945945
'cipher' => null,
946946
],
947947
],

0 commit comments

Comments
 (0)