php - ssl_verify_result 为 0,当没有可用的 https 版本时

标签 php curl ssl

我有一个使用 http 而不是 https 的网站。当我现在使用 cURL 时,http 版本获得 http_code = 200。当我现在使用 https 版本时,它得到 0,这没关系,因为该站点没有 https 版本。但问题是,ssl_verifiy_result 为 0,这意味着:

操作成功

来源:http://www.openssl.org/docs/apps/verify.html#VERIFY_OPERATION

这是为什么?

最佳答案

这确实是 openSSL 中的一个错误。此功能仅在您具备以下条件时才有用:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

另见:

如果没有提供对等证书,则返回的结果代码为 X509_V_OK。这是因为没有出现验证错误,但并不表示成功。 SSL_get_verify_result() 仅在与 SSL_get_peer_certificate(3) 结合时有用。

http://www.openssl.org/docs/ssl/SSL_get_verify_result.html#bugs

请记住,当您希望 cURL 连接到 SSL 并验证证书时,您必须先下载 CA 证书(firefox 可以这样做)并将其保存到您的应用程序,并在您的 cURL 调用中引用它。例如:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/CACertificats/AddTrustExternalCARoot.crt");

关于这个的小教程:http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

关于php - ssl_verify_result 为 0,当没有可用的 https 版本时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21377200/

相关文章:

php - MYSQL语法错误

javascript - 单击选择的选项时将数组行回显到文本区域中

PHP stream_context_set_option SSL 证书作为字符串

php - 使用 php 和 cURL 从外部网站提取元素/数据

tomcat - Grails,需要使用 url 读取文本文件以获得 ssl 证书

PHP foreach 不工作

php - 使用curl登录并获取 session

ssl - SNI 是否在浏览器中实际使用和支持?

java - 从 Weblogic 服务器到 IIS SSL 服务的 x509 客户端身份验证(无法加载服务器信任的 CA java.lang.NullPointerException)

php - Imagemagick 去饱和黑/白?