【问题标题】:PayPal IPN Listener - SSL Certificate Handshake FailurePayPal IPN 侦听器 - SSL 证书握手失败
【发布时间】:2016-05-04 08:26:35
【问题描述】:

使用 IIS 在 Windows Server 2008 R2 上运行 PHP 5.3.28 和 curl 7.30.0(OpenSSL/0.9.8y 和 libssh2/1.4.2)。

我正在使用他们的沙盒环境为 PayPal 即时付款通知创建一个 IPN 侦听器,但无论我做什么,我都会收到 SSL 证书错误,例如:

错误:14077410:SSL 例程:SSL23_GET_SERVER_HELLO:sslv3 警报握手失败

这是我的代码($fieldsPOST 返回的正确字段):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
if ($result = curl_exec($ch)) {
    echo 'result = '.$result.'<br>';
} else {
    echo 'result = '.$result.'<br>';
    echo 'errno = '.curl_errno($ch).'<br>';
    echo 'error = '.curl_error($ch).'<br>';
}
curl_close($ch);

所以,我了解 PayPal 服务器 requires TLS 1.2 and does not support SSL 2/3,但我的 POST 请求似乎无法正常工作。我试过了:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

...我得到同样的错误。我也试过:

curl_setopt($ch, CURLOPT_SSLVERSION, n);

...得到这些结果:

  • [默认] = 35 error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  • 0 CURL_SSLVERSION_DEFAULT = 35 error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  • 1 CURL_SSLVERSION_TLSv1 = 35 error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
  • 2 CURL_SSLVERSION_SSLv2 = 4 OpenSSL was built without SSLv2 support
  • 3 CURL_SSLVERSION_SSLv3 = 35 error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
  • 4 CURL_SSLVERSION_TLSv1_0 = 35 error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  • 5 CURL_SSLVERSION_TLSv1_1 = 35 error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  • 6 CURL_SSLVERSION_TLSv1_2 = 35 error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

我也在某处阅读过这个尝试:

curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '\cacert.pem');

cacert.pem 是从http://curl.haxx.se/docs/caextract.html 下载的,并放在与我的脚本相同的目录中。这没有任何区别。

我的代码是否正确..?

我该如何进行这项工作..?

【问题讨论】:

    标签: php ssl curl paypal https


    【解决方案1】:

    我现在有这个工作,方法如下:

    1. 验证证书
    2. 至少升级到 PHP 5.6.0 / OpenSSL 1.0.1
    3. 保存并引用cacert.pem

    1。验证证书

    使用curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 验证证书。

    2。至少升级到 PHP 5.6.0 / OpenSSL 1.0.1

    升级到至少 PHP 5.6.0,这似乎带来了 OpenSSL/1.0.1i。我认为至少需要 OpenSSL 版本 1.0.1 才能支持 TLS 1.2,这是 PayPal 所要求的。

    3。保存并引用cacert.pem

    http://curl.haxx.se/docs/caextract.html 中的cacert.pem 保存到本地(在我的情况下为c:\cert),然后更新您用来引用cacert.pem as shown here 的PHP ini。使用 ini 文件让您不必在每次调用中都使用curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '\cacert.pem');

    【讨论】:

      猜你喜欢
      • 2016-06-30
      • 2016-04-29
      • 2015-06-08
      • 2016-05-15
      • 2015-05-27
      • 2014-12-10
      • 2019-12-06
      • 2015-12-02
      • 2016-05-04
      相关资源
      最近更新 更多