TLS 1.2 在 cURL 中不起作用

2022-08-30 16:15:27

我在卷曲使用TLS1.2的HTTPS网址时遇到问题,在我的卷曲操作中,我将登录数据发布到网站并将其保存在cookie文件中。我收到的错误消息是这样的

 error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

我已经尝试设置和0,但这似乎不起作用,有什么建议吗?VERIFYPEERVERIFYHOST

以下是我正在使用的版本:

  • OpenSSL 版本是 0.9.8b
  • CURL 版本是 7.24.0
  • PHP 是 5.3

代码如下:

$setuplogin = curl_init(); 
curl_setopt ($setuploginurl, CURLOPT_URL, $url); 
curl_setopt ($setuploginurl, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt ($setuploginurl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt ($setuploginurl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($setuploginurl, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1_2');
curl_setopt ($setuploginurl, CURLOPT_POSTFIELDS, 'username=uname&password=pword&act=login&submit=Login');
curl_setopt ($setuploginurl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36"); 
curl_setopt (setuploginurl, CURLOPT_TIMEOUT, 60); 
curl_setopt ($setuploginurl, CURLOPT_COOKIESESSION, TRUE); 
curl_setopt ($setuploginurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($setuploginurl,  CURLOPT_HEADER, 1);
curl_setopt ($setuploginurl,CURLOPT_ENCODING,"gzip");
curl_setopt ($setuploginurl, CURLOPT_POST, true);
curl_setopt ($setuploginurl, CURLOPT_COOKIEJAR, 'cookies.txt'); 
curl_setopt ($setuploginurl, CURLOPT_FRESH_CONNECT , 1);

$loginp= curl_exec($setuploginurl); 
if ($loginp === FALSE) {
    die(curl_error($setuploginurl));
}

curl_close ($setuploginurl); 
var_dump ($loginp);

答案 1

必须对值使用整数值,而不是上面列出的字符串CURLOPT_SSLVERSION

试试这个:

curl_setopt ($setuploginurl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); // constant NOT string value

http://php.net/manual/en/function.curl-setopt.php

值应为选项参数的以下值的整数:CURLOPT_SSLVERSION

其中之一:

CURL_SSLVERSION_DEFAULT (0)
CURL_SSLVERSION_TLSv1 (1)
CURL_SSLVERSION_SSLv2 (2)
CURL_SSLVERSION_SSLv3 (3)
CURL_SSLVERSION_TLSv1_0 (4)
CURL_SSLVERSION_TLSv1_1 (5)
CURL_SSLVERSION_TLSv1_2 (6)

答案 2

OpenSSL 1.0.1 起支持 TLS 1.1 和 TLS 1.2

强制 TLS 1.1 和 1.2 仅从 curl 7.34.0 开始受支持

您应该考虑升级。


推荐