Skip to content

Commit

Permalink
PHRAS-3900 Check TLS version use for email SMTP sending - TLS 1.0 of …
Browse files Browse the repository at this point in the history
…1.1 deprecation (#4382)

* swift tls 1.2

* add tls 1.1 and 1.2 option

* tlsv1.2 by default
  • Loading branch information
aynsix authored Oct 30, 2023
1 parent 2c81981 commit ebe9153
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions lib/Alchemy/Phrasea/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,20 @@ private function setupSwiftMailer()
);

$encryption = null;

if (in_array($app['conf']->get(['registry', 'email', 'smtp-secure-mode']), ['ssl', 'tls'])) {
$encryption = $app['conf']->get(['registry', 'email', 'smtp-secure-mode']);
$secureMode = '';

if (in_array($app['conf']->get(['registry', 'email', 'smtp-secure-mode']), ['ssl', 'tls', 'tlsv1.1', 'tlsv1.2'])) {
$secureMode = $app['conf']->get(['registry', 'email', 'smtp-secure-mode']);

if ($secureMode == 'ssl') {
$encryption = 'ssl';
} else {
$encryption = 'tls';
if ($secureMode == 'tls') {
// by default use tlsv1.2
$secureMode = 'tlsv1.2';
}
}
}

$options = $app['swiftmailer.options'] = array_replace([
Expand All @@ -706,6 +717,10 @@ private function setupSwiftMailer()
// tls or ssl
$transport->setEncryption($options['encryption']);

if ($options['encryption'] == 'tls') {
$transport->setStreamOptions(['ssl' =>[$secureMode => true]]);
}

if ($app['conf']->get(['registry', 'email', 'smtp-auth-enabled'])) {
$transport->setUsername($options['username']);
$transport->setPassword($options['password']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private function getDefaultData(array $config)
'smtp-auth-enabled' => false,
'smtp-host' => null,
'smtp-port' => null,
'smtp-secure-mode' => 'tls',
'smtp-secure-mode' => 'tlsv1.2',
'smtp-user' => null,
'smtp-password' => isset($config['email']['smtp-password']) ? $config['email']['smtp-password'] : null,
],
Expand Down
2 changes: 1 addition & 1 deletion lib/Alchemy/Phrasea/Form/Configuration/EmailFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]);
$builder->add('smtp-secure-mode', ChoiceType::class, [
'label' => 'SMTP encryption',
'choices' => ['none' => 'None', 'ssl' => 'SSL', 'tls' => 'TLS'],
'choices' => ['none' => 'None', 'ssl' => 'SSL', 'tlsv1.1' => 'TLSV1.1', 'tlsv1.2' => 'TLSV1.2'],
]);
$builder->add('smtp-user', TextType::class, [
'label' => 'SMTP user',
Expand Down

0 comments on commit ebe9153

Please sign in to comment.