3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\Crypto
;
14 use Civi\Core\Event\GenericHookEvent
;
19 * @package Civi\Crypto
24 * The SMTP password is stored inside of the 'mailing_backend' setting.
26 * @see CRM_Utils_Hook::cryptoRotateKey()
28 public static function rotateSmtp(GenericHookEvent
$e) {
29 if ($e->tag
!== 'CRED') {
33 $mand = \Civi
::settings()->getMandatory('mailing_backend');
34 if ($mand !== NULL && !empty($mand['smtpPassword'])) {
35 $e->log
->warning('The settings override for smtpPassword cannot be changed automatically.');
38 $exp = \Civi
::settings()->getExplicit('mailing_backend');
39 if ($exp !== NULL && !empty($exp['smtpPassword'])) {
40 $cryptoToken = \Civi
::service('crypto.token');
41 $newValue = $cryptoToken->rekey($exp['smtpPassword'], 'CRED');
42 if ($newValue !== NULL) {
43 $exp['smtpPassword'] = $newValue;
44 \Civi
::settings()->set('mailing_backend', $exp);
45 $e->log
->info('Updated mailing_backend.smtpPassword');