|
|
@@ -133,6 +133,7 @@ class Socket
|
|
|
$scheme = $this->_config['protocol'] . '://';
|
|
|
}
|
|
|
|
|
|
+ $this->_setSslContext($this->_config['host']);
|
|
|
if (!empty($this->_config['context'])) {
|
|
|
$context = stream_context_create($this->_config['context']);
|
|
|
} else {
|
|
|
@@ -173,6 +174,45 @@ class Socket
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Configure the SSL context options.
|
|
|
+ *
|
|
|
+ * @param string $host The host name being connected to.
|
|
|
+ */
|
|
|
+ protected function _setSslContext($host) {
|
|
|
+ foreach ($this->_config as $key => $value) {
|
|
|
+ if (substr($key, 0, 4) !== 'ssl_') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $contextKey = substr($key, 4);
|
|
|
+ if (empty($this->_config['context']['ssl'][$contextKey])) {
|
|
|
+ $this->_config['context']['ssl'][$contextKey] = $value;
|
|
|
+ }
|
|
|
+ unset($this->_config[$key]);
|
|
|
+ }
|
|
|
+ if (!isset($this->_config['context']['ssl']['SNI_enabled'])) {
|
|
|
+ $this->_config['context']['ssl']['SNI_enabled'] = true;
|
|
|
+ }
|
|
|
+ if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
|
|
|
+ if (empty($this->_config['context']['ssl']['peer_name'])) {
|
|
|
+ $this->_config['context']['ssl']['peer_name'] = $host;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (empty($this->_config['context']['ssl']['SNI_server_name'])) {
|
|
|
+ $this->_config['context']['ssl']['SNI_server_name'] = $host;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($this->_config['context']['ssl']['cafile'])) {
|
|
|
+ $dir = dirname(__DIR__);
|
|
|
+ $this->_config['context']['ssl']['cafile'] = $dir . DIRECTORY_SEPARATOR .
|
|
|
+ 'config' . DIRECTORY_SEPARATOR . 'cacert.pem';
|
|
|
+ }
|
|
|
+ if (!empty($this->_config['context']['ssl']['verify_host'])) {
|
|
|
+ $this->_config['context']['ssl']['CN_match'] = $host;
|
|
|
+ }
|
|
|
+ unset($this->_config['context']['ssl']['verify_host']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* socket_stream_client() does not populate errNum, or $errStr when there are
|
|
|
* connection errors, as in the case of SSL verification failure.
|
|
|
*
|