Skip to content
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

PHRAS-3900 Check TLS version use for email SMTP sending - TLS 1.0 of 1.1 deprecation #4382

Merged
merged 10 commits into from
Oct 30, 2023
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