mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Add support for Self Signed certificates with smtp
This commit is contained in:
parent
17c3358d77
commit
e2c303b2b9
3 changed files with 21 additions and 2 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue