Add support for Self Signed certificates with smtp

This commit is contained in:
Ian den Hartog 2015-10-01 21:47:30 +02:00
parent 17c3358d77
commit e2c303b2b9
3 changed files with 21 additions and 2 deletions

View file

@ -406,5 +406,19 @@ class CakeSocket {
throw new SocketException($errorMessage); throw new SocketException($errorMessage);
} }
/**
* Accept Self-signed certificate on current stream socket
*
* @return bool True on success
* @see stream_context_set_option
*/
public function enableSelfSigned() {
$options['ssl'] = array(
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
);
return stream_context_set_option($this->connection, $options);
}
} }

View file

@ -118,7 +118,8 @@ class SmtpTransport extends AbstractTransport {
'username' => null, 'username' => null,
'password' => null, 'password' => null,
'client' => null, 'client' => null,
'tls' => false 'tls' => false,
'selfSigned' => false
); );
$this->_config = array_merge($default, $this->_config, $config); $this->_config = array_merge($default, $this->_config, $config);
return $this->_config; return $this->_config;
@ -168,6 +169,9 @@ class SmtpTransport extends AbstractTransport {
$this->_smtpSend("EHLO {$host}", '250'); $this->_smtpSend("EHLO {$host}", '250');
if ($this->_config['tls']) { if ($this->_config['tls']) {
$this->_smtpSend("STARTTLS", '220'); $this->_smtpSend("STARTTLS", '220');
if ($this->_config['selfSigned']) {
$this->_socket->enableSelfSigned();
}
$this->_socket->enableCrypto('tls'); $this->_socket->enableCrypto('tls');
$this->_smtpSend("EHLO {$host}", '250'); $this->_smtpSend("EHLO {$host}", '250');
} }

View file

@ -946,7 +946,8 @@ class CakeEmailTest extends CakeTestCase {
'username' => null, 'username' => null,
'password' => null, 'password' => null,
'client' => null, 'client' => null,
'tls' => false 'tls' => false,
'selfSigned' => false
); );
$this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); $this->assertEquals($expected, $this->CakeEmail->transportClass()->config());