【发布时间】:2015-11-19 14:07:23
【问题描述】:
升级到 PHP 5.6 后,尝试通过 fsockopen().. 连接到服务器时出现错误。
服务器(主机)上的证书是自签名的
PHP 警告:fsockopen():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
代码
if($fp = fsockopen($host, $port, $errno, $errstr, 20)){
$this->request = 'POST '.substr($this->url, strlen($this->host)).' HTTP/1.1'.$crlf
.'Host: '.$this->host.$crlf
.'Content-Length: '.$content_length.$crlf
.'Connection: Close'.$crlf.$crlf
.$body;
fwrite($fp, $this->request);
while($line = fgets($fp)){
if($line !== false){
$this->response .= $line;
}
}
fclose($fp);
}
试过了
# cd /etc/ssl/certs/
# wget http://curl.haxx.se/ca/cacert.pem
php.ini
openssl.cafile = "/etc/ssl/certs/cacert.pem"
但脚本仍然无法运行
更新
这行得通
echo file_get_contents("/etc/ssl/certs/cacert.pem");
更新 2
$contextOptions = array(
'ssl' => array(
'verify_peer' => true, // You could skip all of the trouble by changing this to false, but it's WAY uncool for security reasons.
'cafile' => '/etc/ssl/certs/cacert.pem',
//'CN_match' => 'example.com', // Change this to your certificates Common Name (or just comment this line out if not needed)
'ciphers' => 'HIGH:!SSLv2:!SSLv3',
'disable_compression' => true,
)
);
$context = stream_context_create($contextOptions);
$fp = stream_socket_client("{$host}:{$port}", $errno, $errstr, 20, STREAM_CLIENT_CONNECT, $context);
错误
PHP 警告:stream_socket_client():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
【问题讨论】:
-
已经试过了.. 我不能
locate文件 -
你得看看细节。有多种可能的原因,但不使用证书中显示的相同域是一种常见的原因。您可以使用
curl -v无错误地访问它吗?另请注意,除非那些版本的 openssl 已反向移植所有安全补丁,否则您可能需要升级。 -
问题不在于服务器。它有效。它是导致问题的客户端
-
您使用的是哪个操作系统?