diff --git a/libraries/src/Http/Transport/StreamTransport.php b/libraries/src/Http/Transport/StreamTransport.php index 647b3ed7a56ec..4cc5986c09ecc 100644 --- a/libraries/src/Http/Transport/StreamTransport.php +++ b/libraries/src/Http/Transport/StreamTransport.php @@ -158,18 +158,24 @@ public function request($method, Uri $uri, $data = null, array $headers = null, // Add our options to the current ones, if any. $contextOptions['http'] = isset($contextOptions['http']) ? array_merge($contextOptions['http'], $options) : $options; - // Create the stream context for the request. - $context = stream_context_create( - array( - 'http' => $options, - 'ssl' => array( - 'verify_peer' => true, - 'cafile' => $this->options->get('stream.certpath', __DIR__ . '/cacert.pem'), - 'verify_depth' => 5, - ), - ) + $streamOptions = array( + 'http' => $options, + 'ssl' => array( + 'verify_peer' => true, + 'cafile' => $this->options->get('stream.certpath', __DIR__ . '/cacert.pem'), + 'verify_depth' => 5, + ), ); + // Ensure the ssl peer name is verified where possible + if (version_compare(PHP_VERSION, '5.6.0') >= 0) + { + $streamOptions['ssl']['verify_peer_name'] = true; + } + + // Create the stream context for the request. + $context = stream_context_create($streamOptions); + // Authentication, if needed if ($this->options->get('userauth') && $this->options->get('passwordauth')) {