-
-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(dev/core#2258) Support for rotating key on SMTP password
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Crypto; | ||
|
||
use Civi\Core\Event\GenericHookEvent; | ||
|
||
/** | ||
* Class RotateKeys | ||
* | ||
* @package Civi\Crypto | ||
*/ | ||
class RotateKeys { | ||
|
||
/** | ||
* The SMTP password is stored inside of the 'mailing_backend' setting. | ||
* | ||
* @see CRM_Utils_Hook::cryptoRotateKey() | ||
*/ | ||
public static function rotateSmtp(GenericHookEvent $e) { | ||
if ($e->tag !== 'CRED') { | ||
return; | ||
} | ||
|
||
$mand = \Civi::settings()->getMandatory('mailing_backend'); | ||
if ($mand !== NULL && !empty($mand['smtpPassword'])) { | ||
$e->log->warning('The settings override for smtpPassword cannot be changed automatically.'); | ||
} | ||
|
||
$exp = \Civi::settings()->getExplicit('mailing_backend'); | ||
if ($exp !== NULL && !empty($exp['smtpPassword'])) { | ||
$cryptoToken = \Civi::service('crypto.token'); | ||
$newValue = $cryptoToken->rekey($exp['smtpPassword'], 'CRED'); | ||
if ($newValue !== NULL) { | ||
$exp['smtpPassword'] = $newValue; | ||
\Civi::settings()->set('mailing_backend', $exp); | ||
$e->log->info('Updated mailing_backend.smtpPassword'); | ||
} | ||
} | ||
} | ||
|
||
} |