Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
feature #893 Added suport for encrypted private keys (by a passprase)…
Browse files Browse the repository at this point in the history
… in DKIM Signer (dariogz)

This PR was submitted for the 5.x branch but it was merged into the 6.0-dev branch instead (closes #893).

Discussion
----------

Added suport for encrypted private keys (by a passprase) in DKIM Signer

## **Problem**
I noticed that when I want to use a private key, encrypted with a passprase, it was not possible to pass this passprase as a parameter, causing the **openssl_get_privatekey**() method to throw an exception.

This method accepts as an optional parameter a string passphrase
Documentation: http://php.net/manual/es/function.openssl-pkey-get-private.php

## **Added**
- passphrase attribute
- passphrase parameter as optional
- second parameter passphrase to openssl_get_privatekey()

Commits
-------

2ec5736 Added suport for encrypted private keys (by a passprase) in DKIM Signer
  • Loading branch information
fabpot committed May 19, 2017
2 parents 94fb1f9 + 2ec5736 commit 341960e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/classes/Swift/Signers/DKIMSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
*/
protected $selector;

private $passphrase = '';

/**
* Hash algorithm used.
*
Expand Down Expand Up @@ -169,13 +171,15 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
* @param string $privateKey
* @param string $domainName
* @param string $selector
* @param string $passphrase
*/
public function __construct($privateKey, $domainName, $selector)
public function __construct($privateKey, $domainName, $selector, $passphrase = '')
{
$this->privateKey = $privateKey;
$this->domainName = $domainName;
$this->signerIdentity = '@'.$domainName;
$this->selector = $selector;
$this->passphrase = $passphrase;
}

/**
Expand Down Expand Up @@ -670,7 +674,7 @@ private function getEncryptedHash()
$algorithm = OPENSSL_ALGO_SHA256;
break;
}
$pkeyId = openssl_get_privatekey($this->privateKey);
$pkeyId = openssl_get_privatekey($this->privateKey, $this->passphrase);
if (!$pkeyId) {
throw new Swift_SwiftException('Unable to load DKIM Private Key ['.openssl_error_string().']');
}
Expand Down

0 comments on commit 341960e

Please sign in to comment.