简体   繁体   English

CURL和PHP SSLv3错误,并且无法使用TLS

[英]CURL & PHP SSLv3 Error and Can't Get TLS to Work

I am trying to connect to PayPal sandbox using CURL. 我正在尝试使用CURL连接到PayPal沙箱。 I've searched both this website and many others trying to find the right answer however, none, and I mean none, have worked for me and I still get the error: 我已经搜索了该网站以及许多其他网站,试图找到正确的答案,但是,没有一个,我的意思是没有一个对我有用,但仍然出现错误:

SetExpressCheckout failed: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure ( 35 ) SetExpressCheckout失败:错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败(35)

I have the following CURL and PHP installed (It is bought and shared hosting so I cannot upgrade anything). 我安装了以下CURL和PHP(已购买并共享了主机,因此我无法升级任何东西)。

  • Curl Verison: 7.36.0 卷毛Verison: 7.36.0
  • SSL Version: OpenSSL/0.9.8b SSL版本: OpenSSL / 0.9.8b
  • PHP Version: 5.4.45 PHP版本: 5.4.45

The code I am currently using: 我当前使用的代码:

class MyPayPal {
    function PPHttpPost($methodName_, $nvpStr_, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode) {
        // Set up your API credentials, PayPal end point, and API version.
        $API_UserName = urlencode($PayPalApiUsername);
        $API_Password = urlencode($PayPalApiPassword);
        $API_Signature = urlencode($PayPalApiSignature);

        $paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';

        $API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
        $version = urlencode('109.0');

        // Set the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSLVERSION, 4);
        curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');

        curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);

        // Turn off the server and peer verification (TrustManager Concept).
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);

        // Set the API operation, version, and API signature in the request.
        $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

        // Set the request as a POST FIELD for curl.
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

        // Get response from the server.
        $httpResponse = curl_exec($ch);

        if(!$httpResponse) {
            exit("<span style='font-family: Verdana'><strong>$methodName_ failed: </strong>".curl_error($ch).'<strong> (</strong> '.curl_errno($ch).' <strong>)</strong></span>');
        }

        // Extract the response details.
        $httpResponseAr = explode("&", $httpResponse);

        $httpParsedResponseAr = array();
        foreach ($httpResponseAr as $i => $value) {
            $tmpAr = explode("=", $value);
            if(sizeof($tmpAr) > 1) {
                $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
            }
        }

        if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
            exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
        }

    return $httpParsedResponseAr;
}

}

It doesn't matter what I do, I cannot seem to conquer this error. 不管做什么,我似乎都无法克服这个错误。 :( Any guidance will be helpful. :(任何指导都会有所帮助。

Paypal now supports only TLS 1.2 on the sandbox (and in June the same will apply to production systems). Paypal现在在沙盒上仅支持TLS 1.2(6月份将同样适用于生产系统)。 If you want to use TLS 1.2 you'll need to upgrade to OpenSSL 1.0.1+ as a minimum, and then you'll be able to set CURLOPT_SSLVERSION to 6 (TLS 1.2). 如果要使用TLS 1.2,则需要至少升级到OpenSSL 1.0.1+,然后才能将CURLOPT_SSLVERSION设置为6 (TLS 1.2)。 If you want TLS 1.2 to be used automatically during SSL requests, you'll also need to upgrade to PHP 5.5.19+ (this is the ideal solution but many projects are still on older PHP versions). 如果希望在SSL请求期间自动使用TLS 1.2,则还需要升级到PHP 5.5.19+(这是理想的解决方案,但许多项目仍在较旧的PHP版本上)。

However, you've said you're on shared hosting and can't upgrade the software yourself...so you're out of luck. 但是,您说过您正在共享主机上,无法自己升级软件...因此您很不走运。 My advice would be to get away from whatever hosting provider is still stuck on OpenSSL 0.9.8. 我的建议是摆脱仍然停留在OpenSSL 0.9.8上的任何托管提供商。

Reference: https://devblog.paypal.com/upcoming-security-changes-notice/ 参考: https : //devblog.paypal.com/upcoming-security-changes-notice/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM