From f9899e62fdd3fa59296e5b21031ceed58836e111 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 18 Dec 2020 15:55:02 -0800 Subject: [PATCH] (dev/core#2258) Read+write SMTP password using 'crypto.token' Before ------ The format of the 'smtpPassword' subfield depends on the available PECL extensions: * The field is ciphertext... if PHP has `mcrypt` enabled * The field is plaintext... if PHP has `mcrypt` disabled After ----- The format of the `smtpPassword` subfield is specified by `crypto.token` which means: * The field is ciphertext... if it begins with `chr(2)` * The field is plaintext... if it begins with any printable character --- CRM/Admin/Form/Setting/Smtp.php | 4 ++-- CRM/Utils/Mail.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Admin/Form/Setting/Smtp.php b/CRM/Admin/Form/Setting/Smtp.php index 79e0da4f7782..3968cc86a4b1 100644 --- a/CRM/Admin/Form/Setting/Smtp.php +++ b/CRM/Admin/Form/Setting/Smtp.php @@ -198,7 +198,7 @@ public function postProcess() { // if password is present, encrypt it if (!empty($formValues['smtpPassword'])) { - $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']); + $formValues['smtpPassword'] = \Civi::service('crypto.token')->encrypt($formValues['smtpPassword'], 'CRED'); } Civi::settings()->set('mailing_backend', $formValues); @@ -254,7 +254,7 @@ public function setDefaultValues() { $this->_defaults = $mailingBackend; if (!empty($this->_defaults['smtpPassword'])) { - $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']); + $this->_defaults['smtpPassword'] = \Civi::service('crypto.token')->decrypt($this->_defaults['smtpPassword']); } } else { diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index a33c03d86a70..9ab3052d3f57 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -48,7 +48,7 @@ public static function createMailer() { if ($mailingInfo['smtpAuth']) { $params['username'] = $mailingInfo['smtpUsername']; - $params['password'] = CRM_Utils_Crypt::decrypt($mailingInfo['smtpPassword']); + $params['password'] = \Civi::service('crypto.token')->decrypt($mailingInfo['smtpPassword']); $params['auth'] = TRUE; } else {