简体   繁体   English

TLS握手中的curl NSS -12286错误

[英]curl NSS -12286 error in TLS handshake

I am getting NSS -12286 error while trying to load the https page using the ca certificate using cacertinpem.c curl c code. 尝试使用cacertinpem.c curl c代码使用ca证书加载https页面时,出现NSS -12286错误。 i am using cacert.pem file in the code alog with path. 我在带有路径的代码alog中使用cacert.pem文件。 but same thing is working when i try using curl -v " https://sampleserve.com:443 ",in this case ssl is taking default ca path as "/etc/tls/certs/ca.budle.crt" 但是当我尝试使用curl -v“ https://sampleserve.com:443 ”时,同样的东西正在工作,在这种情况下,ssl将默认的ca路径设置为“ /etc/tls/certs/ca.budle.crt”

But this c code is not working for both default ca location and external path selection of ca aswell. 但是,此C代码不适用于默认的ca位置和ca的外部路径选择。

What is the reason for this error(NSS -12286). 此错误的原因是什么(NSS -12286)。

Error:
* About to connect() to fiservices.sterlingbankng.com port 443 (#0)
*   Trying 1.1.1.1... * Connection timed out
*   Trying 1.1.1.2... * connected
* Connected to fiservices.sterlingbankng.com (1.1.1.2) port 443 (#0)
* Initializing NSS with certpath: /etc/pki/nssdb
*   CAfile: ./cacert.pem   CApath: ./cacert.pem
* NSS error -12286
* Error in TLS handshake, trying SSLv3...

GET /CanFI/ HTTP/1.1
Host: sampleserver.com
Accept: */*

* Connection died, retrying a fresh connect
* Closing connection #0
* Issue another request to this URL: 'https://sampleserver.com'
* About to connect() to sampleserver.com port 443 (#0)
*   Trying 1.1.1.1... * Connection timed out
*   Trying 1.1.1.2... * connected
* Connected to sampleserver.com (1.1.1.2) port 443 (#0)
* TLS disabled due to previous handshake failure
*   CAfile: ./cacert.pem
  CApath: ./cacert.pem
* NSS error -12286
* Closing connection #0
* SSL connect error

Sample code: 样例代码:

size_t writefunction( void *ptr, size_t size, size_t nmemb, void *stream)
{
  fwrite(ptr,size,nmemb,stream);              

  return(nmemb*size);                   
}

static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm)
{

  X509_STORE * store;

  X509 * cert=NULL;   

  BIO * bio;                             

  char * mypem = "-----BEGIN CERTIFICATE-----\n"\     "-----END CERTIFICATE-----\n";  //public certificate    

}     

int main(void)    
{

  CURL * ch;

  CURLcode rv;

  rv=curl_global_init(CURL_GLOBAL_ALL);

  ch=curl_easy_init();

  rv=curl_easy_setopt(ch,CURLOPT_VERBOSE, 1L);

  rv=curl_easy_setopt(ch,CURLOPT_HEADER, 0L);

  rv=curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1L);

  rv=curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1L);

  rv=curl_easy_setopt(ch,CURLOPT_WRITEFUNCTION, *writefunction);

  rv=curl_easy_setopt(ch,CURLOPT_WRITEDATA, stdout);

  rv=curl_easy_setopt(ch,CURLOPT_HEADERFUNCTION, *writefunction);

  rv=curl_easy_setopt(ch,CURLOPT_WRITEHEADER, stderr);

  rv=curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM");  

  rv=curl_easy_setopt (ch, CURLOPT_CAPATH, "./cacert.pem" );  

  rv=curl_easy_setopt (ch, CURLOPT_CAINFO, "./cacert.pem" ); 

  rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1L); 

  rv=curl_easy_setopt(ch, CURLOPT_URL, "https://");   

  rv=curl_easy_perform(ch);           

  if (rv==CURLE_OK)             

    printf("*** transfer succeeded ***\n"); 

  else                   

    printf("*** transfer failed ***\n"); 

  rv=curl_easy_setopt(ch,CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); 

  rv=curl_easy_perform(ch);              

  if (rv==CURLE_OK)             

    printf("*** transfer succeeded ***\n");               
  else             

    printf("*** transfer failed ***\n");               

  curl_easy_cleanup(ch);  

  curl_global_cleanup();  

  return rv;               
}

Thanks 谢谢

Ran into this in PHP. 在PHP中使用它。 I ran curl on the command line with -v and found the NSS -12286 error. 我在命令行上使用-v运行curl,发现NSS -12286错误。

Turns out that the remote server and curl did not have a common cypher ( nss error codes ). 事实证明,远程服务器和curl没有通用密码( nss错误代码 )。 We added a cypher to the curl object like so: 我们向curl对象添加了一个密码,如下所示:

curl_setopt($oCurl, CURLOPT_SSL_CIPHER_LIST, 'rsa_rc4_128_sha');

The very first thing I notice, you're doing: 我注意到的第一件事就是:

rv=curl_easy_setopt (ch, CURLOPT_CAPATH, "./cacert.pem" );

needs to specify a "string naming a directory holding multiple CA certificates to verify the peer with". 需要指定“命名包含多个CA证书的目录以验证对等方的字符串”。 From the man page. 从手册页。 You'll probably want "/etc/tls/certs/" 您可能需要"/etc/tls/certs/"

In addition, it would appear the line: 此外,它将显示以下行:

rv=curl_easy_setopt(ch,CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); 

is doing nothing. 什么也没做。 I say this because, again, from the man page, "This option does only function for libcurl powered by OpenSSL". 我之所以这样说是因为,再次在手册页中,“此选项仅对由OpenSSL驱动的libcurl起作用”。 I say this because, your error log has "NSS error" 我说这是因为,您的错误日志中包含“ NSS错误”

My experience with working with ssl is only with openssl. 我使用ssl的经验仅限于openssl。 I found the command line function openssl s_client to be helpful. 我发现命令行功能openssl s_client会有所帮助。 That being said, it is very easy to miss configure your setup. 话虽这么说,很容易错过配置您的设置。 Many functions and command line options will try to work with even the craziest input, leading to red herring errors. 许多功能和命令行选项甚至会尝试使用最疯狂的输入,从而导致红色鲱鱼错误。

Edit: My attempt at your program completes with success. 编辑:我对您程序的尝试已成功完成。

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL * ch;
    CURLcode rv;
    rv=curl_global_init(CURL_GLOBAL_ALL);
    ch=curl_easy_init();
    rv=curl_easy_setopt(ch, CURLOPT_VERBOSE, 1L);
    rv=curl_easy_setopt(ch, CURLOPT_CAPATH, "/etc/ssl/certs");
    rv=curl_easy_setopt(ch, CURLOPT_URL, "https://");
    rv=curl_easy_perform(ch);
    if (rv==CURLE_OK) {
        printf("*** transfer succeeded ***\n");
    }
    else {
        printf("*** transfer failed ***\n");
    }
    curl_easy_cleanup(ch);
    curl_global_cleanup();
    return rv;
}

We had this issue connecting between a Plesk Centos server that had been configured to only accept PCI DSS compliant ciphers and a Binami/DigitalOcean Debian stack which, out of the box, had no overlapping ciphers (as the 12286 indicates). 在配置为仅接受PCI DSS兼容密码的Plesk Centos服务器与开箱即用的,没有重叠密码的Binami / DigitalOcean Debian堆栈之间存在连接的问题(如12286所示)。 The answer was to update the DigitalOcean Debian to use the same cipher suite as the other server and restart apache. 答案是将DigitalOcean Debian更新为使用与其他服务器相同的密码套件,然后重新启动apache。

You can obviously change the cipher suite on either box, or both - but we chose to keep the PCI DSS cipher suite across the board. 您显然可以在其中一个或两个框中都更改密码套件-但我们选择全面保留PCI DSS密码套件。

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

相关问题 卷曲SMTP TLS错误 - Curl SMTP TLS ERROR 在 Docker Alpine 中编译 NSS 模块 - 致命错误:nss.h:没有这样的文件或目录 - Compiling NSS module in Docker Alpine - fatal error: nss.h: No such file or directory curl/curl.h、libcurl、libcurl4-openssl-dev、libcurl4-nss-dev 库之间的区别? - Difference between curl/curl.h, libcurl, libcurl4-openssl-dev, libcurl4-nss-dev libraries? libcurl-NSS使用tls构建了Imap:SSL CA证书(路径?访问权限?)窗口 - libcurl-NSS built Imap with tls :SSL CA cert (path? access rights?) windows C程序卷曲:(35)错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败 - C Program curl: (35) error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure 如何在一个进程中进行TLS握手并在另一个进程中处理其余的连接? - How to do TLS handshake in one process and handle the rest of connection in another process? TLS服务器未从客户端接收证书,无法终止握手 - TLS server doesn't receive certificate from client, fails to terminate handshake libcurl gnutls_handshake()失败:收到了TLS警告警报 - libcurl gnutls_handshake() failed: A TLS warning alert has been received FTPS 连接错误:gnutls_handshake 失败 - FTPS connection error: gnutls_handshake failed C curl / curl.h错误 - C curl/curl.h Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM