Skip to content

Commit

Permalink
(dev/core#2258) Read+write SMTP password using 'crypto.token'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
totten committed Dec 21, 2020
1 parent 3cbd473 commit f9899e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CRM/Admin/Form/Setting/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f9899e6

Please sign in to comment.