使用cURL与SNI(服务器名称指示) [英] Use cURL with SNI (Server Name Indication)
问题描述
我想使用cURL发布到刚刚开始使用SNI的API(所以他们可以在1个IP地址上托管多个SSL证书)。
I am trying to use cURL to post to an API that just started using SNI (so they could host multiple ssl certs on 1 IP address).
我的cURL由于这个移动到SNI而停止工作。他们解释说,这是因为cURL得到* .domain-a.com而不是* .domain-b.com,所以SSL失败。
My cURL stopped working as a result of this move to SNI. They explained that it's because cURL is getting *.domain-a.com back instead of *.domain-b.com so the SSL fails.
这似乎是cURL中的错误,因为从浏览器访问时,API网址没有错误。
This seems to be a bug in cURL because the API URL has no errors when visited from a browser.
使用这个代码,它工作:
Using this code, it does work:
exec('curl -k -d "parameters=here", https://urlhere.com/', $output);
print_r($output);
但是,使用-k不好,因为它不验证SSL证书。
However, using -k is bad because it doesn't verify the SSL cert.
使用此代码不起作用:
exec('curl -d "parameters=here", https://urlhere.com/', $output);
print_r($output);
所以我的问题是,如何使用curl与SNI,并仍然验证SSL使用-k)。
So my question is, how can I use curl with SNI and still verify the SSL (not have to use -k). Is there another setting in PHP or a cURL option I can set to work around this?
推荐答案
为了能够使用SNI,需要三个条件:
To be able to use SNI, three conditions are required:
- 使用支持它的Curl版本,至少7.18.1,根据更改日志。
- 使用针对支持SNI的库编译的Curl版本,例如OpenSSL 0.9.8j(取决于某些旧版本的编辑选项)。
- 至少使用TLS 1.0(不是SSLv3)。
请注意,Curl的调试代码( -v
)只显示主版本号(主要用于区分SSLv2和SSLv3 +类型的消息, ssl_tls_trace
),因此当您使用TLS 1.0或更高版本(因为它们实际上是SSL v3.1或更高版本,3是相同的主版本号)时,它仍然会显示SSLv3。
Note that Curl's debug code (-v
) only displays the major version number (mainly to distinguish between SSLv2 and SSLv3+ types of messages, see ssl_tls_trace
), so it will still display "SSLv3" when you use TLS 1.0 or above (because they're effectively SSL v3.1 or above, 3 is the same major version number).
您可以检查您安装的curl版本可以使用Wireshark使用SNI。如果您使用 curl -1 https:// something
建立连接,如果展开Client Hello消息,您应该可以看到一个 server_name
。
You could check that your installed version of curl can use SNI using Wireshark. If you make a connection using curl -1 https://something
, if you expand the "Client Hello" message, you should be able to see a "server_name
" extension.
我不知道默认情况下使用哪个SSL / TLS版本(取决于您的编译选项)您使用 curl
而不使用 -1
(对于TLS 1.0)或 -3
(对于SSLv3),但您可以尝试强制 -1
在您的命令,因为它将无法使用SSLv3。
I'm not sure which SSL/TLS version is used by default (depending on your compilation options) when you use curl
without -1
(for TLS 1.0) or -3
(for SSLv3), but you can try to force -1
on your command, since it won't work with SSLv3 anyway.
这篇关于使用cURL与SNI(服务器名称指示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!