From 1392fa36dc83e139572a9771bbd9f563bdff3c72 Mon Sep 17 00:00:00 2001 From: Richard Danklof <271785+rdanklof@users.noreply.github.com> Date: Thu, 17 Jan 2019 11:13:22 +0100 Subject: [PATCH] Adding passphrase support (#9) * Added passphrase for parameter for private key * Updated README.md --- README.md | 1 + src/Mailer.php | 2 +- src/Message.php | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 70b97cf..d191f6b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Vitalybaev\LaravelDkim\DkimMailServiceProvider::class, 'dkim_private_key' => env('MAIL_DKIM_PRIVATE_KEY'), // path to private key, required 'dkim_identity' => env('MAIL_DKIM_IDENTITY'), // identity (optional) 'dkim_algo' => env('MAIL_DKIM_ALGO'), // sign algorithm (defaults to rsa-sha256) +'dkim_passphrase' => env('MAIL_DKIM_PASSPHRASE'), // private key passphrase (optional) ``` ## License diff --git a/src/Mailer.php b/src/Mailer.php index ce1b0cb..f27e995 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -20,7 +20,7 @@ protected function createMessage() if (in_array(strtolower(config('mail.driver')), ['smtp', 'sendmail', 'log'])) { if (config('mail.dkim_private_key') && file_exists(config('mail.dkim_private_key'))) { if (config('mail.dkim_selector') && config('mail.dkim_domain')) { - $message->attachDkim(config('mail.dkim_selector'), config('mail.dkim_domain'), file_get_contents(config('mail.dkim_private_key'))); + $message->attachDkim(config('mail.dkim_selector'), config('mail.dkim_domain'), file_get_contents(config('mail.dkim_private_key')), config('mail.dkim_passphrase')); } } } diff --git a/src/Message.php b/src/Message.php index 22e44bd..7bd647a 100644 --- a/src/Message.php +++ b/src/Message.php @@ -10,12 +10,13 @@ class Message extends \Illuminate\Mail\Message * @param $selector * @param $domain * @param $privateKey + * @param $passphrase * * @return $this */ - public function attachDkim($selector, $domain, $privateKey) + public function attachDkim($selector, $domain, $privateKey, $passphrase = '') { - $signer = new Swift_Signers_DKIMSigner($privateKey, $domain, $selector); + $signer = new Swift_Signers_DKIMSigner($privateKey, $domain, $selector, $passphrase); $signer->setHashAlgorithm(config('mail.dkim_algo', 'rsa-sha256')); if (config('mail.dkim_identity')) { $signer->setSignerIdentity(config('mail.dkim_identity'));