PayPal 最近的 TLS 1.2 / HTTP 1.1 更新以及何时使用它

PayPal's recent TLS 1.2 / HTTP 1.1 updates and when to use it

关于 Paypal 最近的 security update 我已经开始在我的 cURL 代码中添加两个额外的选项,它们是:

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);

我设置了 CURLOPT_HTTP_VERSION 因为没有设置它似乎默认为“让 CURL 决定使用哪个版本”——而我没有出于将来的兼容性原因想要或喜欢对设置进行硬编码,如果支持可用,是否可以信任 cURL 始终设置 HTTP 1.1

其次,我将CURLOPT_SSLVERSION设置为6,也就是CURL_SSLVERSION_TLSv1_2,因为我已经看过了..

Some environments may be capable of TLS 1.2 but it is not in their list of defaults, so need the SSL version option to be set.

现在,我注意到另一个问题是 PayPal link 它只提到了端点,但是当你向他们的其他 URL 发出 cURL 请求时呢?就像普通的:https://www.paypal.com/cgi-bin/webscr 用于诸如 IPN 侦听器之类的东西?这仍然需要 TLS 1.2 和 HTTP 1.1 吗?

www.paypal.com 正在使用 HTTP/2,如

中所示
curl --silent --head https://www.paypal.com | head -n 1
HTTP/2 302

根据official docs,你最好的选择是

CURL_HTTP_VERSION_2_0

Attempt HTTP 2 requests. libcurl will fall back to HTTP 1.1 if HTTP 2 can't be negotiated with the server.

cURL 将回退到所需的 HTTP/1.1 如果 HTTP/2 无法使用。

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

这个选项可能会更好

CURL_HTTP_VERSION_2TLS

Attempt HTTP 2 over TLS (HTTPS) only. libcurl will fall back to HTTP 1.1 if HTTP 2 can't be negotiated with the HTTPS server. For clear text HTTP servers, libcurl will use 1.1. (Added in 7.47.0)

对于php cURL extension docs

CURL_HTTP_VERSION_2 (integer) Available since PHP 7.0.7 and cURL 7.43.0 CURL_HTTP_VERSION_2TLS (integer) Available since PHP 7.0.7 and cURL 7.47.0

如果您的 PHP 版本没有定义这些常量,您可以尝试类似

defined('CURL_HTTP_VERSION_2_0') || define('CURL_HTTP_VERSION_2_0', 65536);

对于 CURL_HTTP_VERSION_2TLS,该值似乎是。

CURL_HTTP_VERSION_2TLS = 4

只要 libcurl 后备包版本支持,使用整数值而不是 PHP 常量就可以工作。

基于 rpm Linux 你可以检查

rpm -q libcurl4
libcurl4-7.60.0-lp150.2.6.1.x86_64

与PHP(命令行)比较

php -r 'phpinfo();' | grep -i 'curl info'
cURL Information => 7.60.0

还有

php -r 'print_r(curl_version());' | grep 'version'
[version_number] => 474112
[ssl_version_number] => 0
[version] => 7.60.0
[ssl_version] => OpenSSL/1.1.0h
[libz_version] => 1.2.11

可能最好和最简单的进一步兼容性的方法就是尝试使您的库保持最新,主要是 curlopenssl(检查 nghttp),这可能有助于防止添加一些常量,并且通过使用定义的 "defaults" 应该可以正常工作。

来自文档:https://ec.haxx.se/http-versions.html

Since perhaps mid 2016, curl will default to use HTTP/1.1 for HTTP servers. If you connect to HTTPS and you have a libcurl that has HTTP/2 abilities built-in, curl will attempt to use HTTP/2 automatically or fall down to 1.1 in case the negotiation failed. Non-HTTP/2 capable curls get 1.1 over HTTPS by default.