mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/10076] STARTTLS support for SMTP via smtp_class.
PHPBB3-10076
This commit is contained in:
parent
ac492d8f1e
commit
237ddf9d22
1 changed files with 57 additions and 0 deletions
|
@ -1136,6 +1136,7 @@ class smtp_class
|
||||||
{
|
{
|
||||||
var $server_response = '';
|
var $server_response = '';
|
||||||
var $socket = 0;
|
var $socket = 0;
|
||||||
|
protected $socket_tls = false;
|
||||||
var $responses = array();
|
var $responses = array();
|
||||||
var $commands = array();
|
var $commands = array();
|
||||||
var $numeric_response_code = 0;
|
var $numeric_response_code = 0;
|
||||||
|
@ -1292,6 +1293,25 @@ class smtp_class
|
||||||
return $hello_result;
|
return $hello_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SMTP STARTTLS (RFC 3207)
|
||||||
|
if (!$this->socket_tls)
|
||||||
|
{
|
||||||
|
$this->socket_tls = $this->starttls();
|
||||||
|
|
||||||
|
if ($this->socket_tls)
|
||||||
|
{
|
||||||
|
// Switched to TLS
|
||||||
|
// RFC 3207: "The client MUST discard any knowledge obtained from the server, [...]"
|
||||||
|
// So say hello again
|
||||||
|
$hello_result = $this->hello($local_host);
|
||||||
|
|
||||||
|
if (!is_null($hello_result))
|
||||||
|
{
|
||||||
|
return $hello_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we are not authenticated yet, something might be wrong if no username and passwd passed
|
// If we are not authenticated yet, something might be wrong if no username and passwd passed
|
||||||
if (!$username || !$password)
|
if (!$username || !$password)
|
||||||
{
|
{
|
||||||
|
@ -1371,6 +1391,43 @@ class smtp_class
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP STARTTLS (RFC 3207)
|
||||||
|
*
|
||||||
|
* @return bool Returns true if TLS was started
|
||||||
|
* Otherwise false
|
||||||
|
*/
|
||||||
|
protected function starttls()
|
||||||
|
{
|
||||||
|
if (!function_exists('stream_socket_enable_crypto'))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->commands['STARTTLS']))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->server_send('STARTTLS');
|
||||||
|
|
||||||
|
if ($err_msg = $this->server_parse('220', __LINE__))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$stream_meta = stream_get_meta_data($this->socket);
|
||||||
|
|
||||||
|
if (socket_set_blocking($this->socket, 1));
|
||||||
|
{
|
||||||
|
$result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
|
||||||
|
socket_set_blocking($this->socket, (int) $stream_meta['blocked']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pop before smtp authentication
|
* Pop before smtp authentication
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue