7

由于 3 天我无法连接到贝宝沙盒。我发现他们可能禁用了对 SSLv3 的支持。所以我尝试通过设置更改我的 curl 请求中的 SSL 版本:

curl_setopt($curl, CURLOPT_SSLVERSION,1); # 1 = TLSv1

但它仍然给我同样的错误:

error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

知道为什么脚本仍在使用 SSLv3 吗?

我正在使用 php 5.5 和以下 curl 版本(目前要求我的主机 [managed hosting at 1&1] 升级到更新版本)

curl 7.21.0 (i486-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6 协议:dict 文件 ftp ftps http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 功能: GSS-协商 IDN IPv6 Largefile NTLM SSL libz

4

3 回答 3

6

问题是 PayPal 放弃了对 SSLv3、TLS 1.0 和 TLS 1.1 的支持,现在只支持 TLS 1.2,但使用 ( 0.9.8o) 构建的 OpenSSL 版本 cURL 不支持 TLS。

此时您所能做的就是希望主机能够将 OpenSSL、cURL 和 PHP 更新到更新的(1.0+)版本的 OpenSSL。

就目前而言,您的 cURL 客户端不支持 PayPal 所需的 TLS,除了更新 OpenSSL 之外,没有其他方法可以绕过它。

于 2016-02-01T17:25:22.677 回答
4

有同样的问题。

    <?php
error_reporting(E_ALL);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');

$response =    curl_exec($curl);
var_dump($response);
exit;

回复:

bool(false)

并且没有错误日志!

所以我做了小脚本:

<?php
error_reporting(E_ALL);
var_dump(file_get_contents('https://api-3t.sandbox.paypal.com/nvp'));

这是我在日志中得到的:

[12-Feb-2016 15:56:19] PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in /xxx/yyy.php on line 3
[12-Feb-2016 15:56:19] PHP Warning:  file_get_contents(): Failed to enable crypto in /xxx/yyy.php on line 3
[12-Feb-2016 15:56:19] PHP Warning:  file_get_contents(https://api-3t.sandbox.paypal.com/nvp): failed to open stream: operation failed in /xxx/yyy.php on line 3

我的解决方案是:

  1. 更新 (1.0+) 版本的 OpenSSL。
  2. 重新编译卷曲
  3. 用新的 CURL 重新编译 PHP
  4. 确保 Curl SSL 版本是 OpenSSL/(1.0+)

SSL 版本 OpenSSL/1.0.1e – 好

SSL 版本 NSS/3.13.6.0 – 坏

我在 CentOS 上运行。这是我所做的更新:

  1. 更新 OpenSSL:

    openssl 版本

如果低于 1.0 运行:yum update openssl 确保它实际上已更新

  1. 重新安装 PHP。所以保存 php.ini 文件
  2. 保留通过以下方式安装的所有 PHP 模块的列表:

    yum 列表安装 | grep php

保存输出!

  1. 百胜清除php
  2. yum 擦除 php-curl
  3. 百胜安装php
  4. 百胜安装 php-curl

  5. 重新启动 apache 或 fpm,如果你幸运的话,你会得到工作

  6. 恢复 php.ini 配置和 PHP 模块:yum install php-pgsql;百胜安装php-gd;ETC

但是,如果您的包存储库已过时,或者您安装了带有 NSS SSL 绑定的 curl 库,您可以手动下载和编译 curl 库。我使用了与 php-devel 包捆绑在一起的phpize工具。所以我遇到的问题是:

cURL Information    7.19.7 
SSL Version     NSS/3.13.6.0

这是我如何将其更改为:

cURL Information    7.22.0 
SSL Version     OpenSSL/1.0.1e 
  1. 更新 OpenSSL:

    openssl 版本

如果低于 1.0 运行:yum update openssl 确保它实际上已更新

  1. 重新安装 PHP。所以保存 php.ini 文件
  2. 保留通过以下方式安装的所有 PHP 模块的列表:

    yum 列表安装 | grep php

保存输出!

  1. 百胜清除php
  2. yum 擦除 php-curl
  3. 百胜安装 php-devel
  4. 使用rpm -qa --queryformat '%{version}' php打印 PHP 版本并找到可以下载完全相同的 PHP 源的位置
  5. 以下 bash 脚本将安装特定的 curl 库:

<pre>
#!/bin/bash

PHP_VERSION=$(rpm -qa --queryformat '%{version}' php)

CURL_VERSION=7.22.0

#echo $CURL_VERSION
#exit

#wget --no-check-certificate http://mirror.cogentco.com/pub/php/php-${PHP_VERSION}.tar.gz -O /tmp/php-${PHP_VERSION}.tar.gz
wget --no-check-certificate http://museum.php.net/php5/php-${PHP_VERSION}.tar.gz -O /tmp/php-${PHP_VERSION}.tar.gz
wget --no-check-certificate http://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz -O /tmp/curl-${CURL_VERSION}.tar.gz

cd /tmp; tar xzf php-${PHP_VERSION}.tar.gz
cd /tmp; tar xzf curl-${CURL_VERSION}.tar.gz

cd curl-${CURL_VERSION}
./configure
make
make install

cd /tmp; rm -rf curl-${CURL_VERSION}*

sleep 2

cd /tmp/php-${PHP_VERSION}/ext/curl/
phpize
./configure
make
make install

cd /tmp; rm -rf php-${PHP_VERSION}*

</pre>

  1. 重新启动 apache 或 fpm,如果你幸运的话,你会得到工作
  2. 恢复 php.ini 配置和 PHP 模块:yum install php-pgsql;百胜安装php-gd;ETC
于 2016-02-25T09:46:36.430 回答
1

完美,我希望 LibCurl 使用 OpenSSL 而不是 NSS,这有助于我修复它以调整 php libcurl 以使用 OpenSSL。

我的 Centos7 PHP 5.6 正在使用

php -r "print_r(curl_version());" | grep ssl_version
[ssl_version_number] => 0
[ssl_version] => NSS/3.19.1 Basic ECC

在上述修复之后,它显示,这就是我想要的。

php -r "print_r(curl_version());" | grep ssl_version
[ssl_version_number] => 0
[ssl_version] => OpenSSL/1.0.1f

这是我在 Centos7 上使用 PHP 5.6.17 的修改后的脚本

#!/bin/bash
PHP_VERSION=$(rpm -qa --queryformat '%{version}' php56)
CURL_VERSION=$(curl -V|head -1|awk '{print $2}')
wget --no-check-certificate http://mirror.cogentco.com/pub/php/php-5.6.17.tar.bz2 -O /tmp/php-${PHP_VERSION}.tar.bz2
wget --no-check-certificate http://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz -O /tmp/curl-${CURL_VERSION}.tar.gz

cd /tmp; tar xjf php-${PHP_VERSION}.tar.bz2
cd /tmp; tar xzf curl-${CURL_VERSION}.tar.gz

cd curl-${CURL_VERSION}
./configure
make
make install

cd /tmp; rm -rf curl-${CURL_VERSION}*

sleep 2

cd /tmp/php-${PHP_VERSION}/ext/curl/
phpize
./configure
make
make install

cd /tmp; rm -rf php-${PHP_VERSION}*
于 2016-05-20T11:29:37.843 回答