当前位置: 首页 > 知识库问答 >
问题:

SSL错误SSL3_GET_Server_Certifice:证书验证失败

黄景胜
2023-03-14
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
openssl.cafile = "/etc/ssl/certs/cacert.pem"
echo file_get_contents("/etc/ssl/certs/cacert.pem");
$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_Certifice:证书验证失败

共有1个答案

仰雅昶
2023-03-14

您下载的文件(http://curl.haxx.se/ca/cacert.pem)是来自主要受信任证书颁发机构的根证书包。您说远程主机有一个自签名的SSL证书,所以它没有使用受信任的证书。openssl.cafile设置需要指向用于在远程主机上签署SSL证书的CA证书。PHP 5.6比以前的PHP版本有所改进,现在默认情况下可以验证对等证书和主机名(http://PHP.net/manual/en/migration56.openssl.PHP)

您需要找到在签署SSL证书的服务器上生成的CA证书,并将其复制到此服务器。如果使用自签名证书,则需要将用于签署远程主机SSL证书的CA证书添加到您所连接的服务器上的受信任存储区,或者使用流上下文为每个单独的请求使用该证书。将其添加到受信任证书是最简单的解决方案。只需将远程主机CA证书的内容添加到下载的cacert.pem文件的末尾。

前文:

<?php

$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("tcp://{$host}:{$port}", $errno, $errstr, 20, STREAM_CLIENT_CONNECT, $context);

if (!$fp) {

    echo "$errstr ({$errno})<br />\n";

}else{
    
    $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 (!feof($fp)) {
        $this->response .= fgets($fp);
    }

    fclose($fp);

}
 类似资料:
  • 问题内容: 在Windows Vista SP2 + Python 2.7.10上,我可以连接到https://www.python.org,但不能连接到https://codereview.appspot.com 剧本: 并输出: 如何解决问题,https://codereview.appspot.com/到底有什么问题? 问题答案: 我的猜测是,它与OpenSSL中的替代链处理有关,如Pyth

  • 问题内容: 这段代码 给我这个错误 我对SSL几乎一无所知,但我曾尝试下载该站点的证书并使用该选项指向该文件,但是它没有用。我想念什么吗? 问题答案: 正如评论中已经指出的那样:从SSLLabs报告中可以看出,该网站的SSL实施不正确。该报告中有关您的问题的主要部分是: 该服务器的证书链不完整。等级上限为B。 这意味着服务器没有发送验证证书所需的完整证书链。这意味着您需要在验证时自行添加丢失的证书

  • 当我想要在cPanel上安装证书时,我会看到以下错误: 错误证书验证失败! 已执行/usr/bin/openssl verify-capath/var/cpanel/ssl/installed/cabundles: stdin:CN=example.com 0深度查找时错误20:无法获取本地颁发者证书

  • 我使用Let's encrypt free SSL(默认情况下,我的主机提供商支持它),我检查了我在SSLShopper.com的网站(唯一的警告是:)和https://www.geocerts.com/SSL_checker。结果是我的网站通过了所有测试,除了。所以我不认为问题出在证书上,据我所知,telegram接受自签名证书。 我曾尝试在https://core.telegram.org/b

  • 我正在练习'Web Scraping with Python'中的代码,我一直遇到这个证书问题: 错误是: 顺便说一句,我也在练习scrapy,但一直遇到问题:command not found:scrapy(我在网上尝试了各种解决方案,但都没有奏效……真令人沮丧)