aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-08-22 23:50:02 +0200
committerAndreas Fischer <bantu@phpbb.com>2012-01-28 22:51:35 +0100
commit237ddf9d22e0aeccad5e1db022de3a890871849f (patch)
treebaf3e31af9a7025a3c62cf74e0dc9251a8a50a0d
parentac492d8f1e7ef3420ebaee35131e342a39dfda10 (diff)
downloadforums-237ddf9d22e0aeccad5e1db022de3a890871849f.tar
forums-237ddf9d22e0aeccad5e1db022de3a890871849f.tar.gz
forums-237ddf9d22e0aeccad5e1db022de3a890871849f.tar.bz2
forums-237ddf9d22e0aeccad5e1db022de3a890871849f.tar.xz
forums-237ddf9d22e0aeccad5e1db022de3a890871849f.zip
[ticket/10076] STARTTLS support for SMTP via smtp_class.
PHPBB3-10076
-rw-r--r--phpBB/includes/functions_messenger.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index ccc17865f6..f4e49b1b18 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -1136,6 +1136,7 @@ class smtp_class
{
var $server_response = '';
var $socket = 0;
+ protected $socket_tls = false;
var $responses = array();
var $commands = array();
var $numeric_response_code = 0;
@@ -1292,6 +1293,25 @@ class smtp_class
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 (!$username || !$password)
{
@@ -1372,6 +1392,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
*/
function pop_before_smtp($hostname, $username, $password)