如何在我的 OS/PHP 上启用 CURLOPT_SSL_VERIFYHOST = 2 支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15552052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable CURLOPT_SSL_VERIFYHOST = 2 support on my OS/PHP
提问by dm03514
I have been developing a site locally that authenticates against a centrailzed signon. One of the steps is requiring me to make a curl request to an https resource to get an access token.
我一直在本地开发一个站点,该站点针对集中式登录进行身份验证。其中一个步骤是要求我向 https 资源发出 curl 请求以获取访问令牌。
Part of the curl config is:
curl 配置的一部分是:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
As you can see I commented out the CURLOPT_SSL_VERIFYHOST option. I have read on php.net and on various blogs/stackoverflow (Security consequences of disabling CURLOPT_SSL_VERIFYHOST (libcurl/openssl)) posts WHAT these options mean.
如您所见,我注释掉了 CURLOPT_SSL_VERIFYHOST 选项。我在 php.net 和各种博客/stackoverflow(禁用 CURLOPT_SSL_VERIFYHOST (libcurl/openssl) 的安全后果)上阅读了这些选项的含义。
On my development machine CURLOPT_SSL_VERIFYHOST 2has been working fine. I am just using the vanilla php install provided in ubuntu 12.04 php5 package, and php5-curl.
在我的开发机器CURLOPT_SSL_VERIFYHOST 2上一直运行良好。我只是使用 ubuntu 12.04 php5 包中提供的 vanilla php 安装和 php5-curl。
On production (rackspace cloudsites) the CURLOPT_SSL_VERIFYHOST 2is not working, which is why I changed it to false to verify this was the issue. Seeing as i didn't explicitly do anything to enable this on my localhost I do not know what directives/config options controls this.
在生产(机架空间云站点)上CURLOPT_SSL_VERIFYHOST 2,它不起作用,这就是为什么我将其更改为 false 以验证这是问题所在。看到我没有明确做任何事情来在我的本地主机上启用它,我不知道什么指令/配置选项控制它。
What I mean by it is "not working" is that on production the curl call is returning an http_codeof 0when the VERIFYHOSTis set to 2. When I set it to FALSEit is returning a status code of 200
我的意思是“不工作”是对生产的卷曲调用返回的http_code的0时候VERIFYHOST被设置为2。当我设置它时,FALSE它返回一个状态代码200
My question is:
我的问题是:
How can i enable SSL_VERIFYHOSTon a linux box?
如何SSL_VERIFYHOST在 linux 机器上启用?
Any help would be greatly appreciated. Thank you.
任何帮助将不胜感激。谢谢你。
回答by Mark Stanislav
For '2' you have to ensure the common name in the SSL certificate matches the hostname being utilized. This is the default and should be straight-forward as long as your SSL certificate is appropriately created for the hostname (common name) you're using it on.
对于“2”,您必须确保 SSL 证书中的通用名称与正在使用的主机名匹配。这是默认设置,只要您的 SSL 证书是为您使用它的主机名(通用名称)适当创建的,就应该是直接的。
From the PHP curl_setopt manual:
来自 PHP curl_setopt 手册:
1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a common name and also verify that it matches the hostname provided. In production environments the value of this option should be kept at 2 (default value).
1 检查 SSL 对等证书中是否存在通用名称。2 检查通用名称是否存在,并验证它是否与提供的主机名匹配。在生产环境中,此选项的值应保持为 2(默认值)。

