Libcurl with a client certificate, I get the error "Could not load client key -8178. * NSS -8178 error"

when i run this code i got error info:

  • About connecting () to the port 10.12.190.155 443 (# 0)
  • Attempt 10.12.190.155 ... * connected
  • Connected to 10.12.190.155 (12.12.190.155) port 443 (# 0)
  • Initializing NSS with certpath: sql: / etc / pki / nssdb
  • CA File: /home/wh/work/sslkey/ca.crt CApath: none
  • Unable to load client key -8178.
  • Error NSS -8178
  • Closing Connection # 0
  • Problem with local SSL certificate

CURL * rot; CURLcode res;

//static const char *pClientCert = "/home/wh/work/sslkey/user1.pem"; curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_HEADER, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_URL, "https://10.12.190.155/"); curl_easy_setopt(curl, CURLOPT_CAINFO, "/home/wh/work/sslkey/ca.crt"); curl_easy_setopt(curl,CURLOPT_SSLCERT,"/home/wh/work/sslkey/user1.pem"); res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_easy_cleanup(curl); } curl_global_cleanup(); 
+4
source share
1 answer

There is no curl_easy_setopt(curl, CURLOPT_SSLKEY, "key_file_path"); in your code curl_easy_setopt(curl, CURLOPT_SSLKEY, "key_file_path"); to get your key. It is also not clear that your user1.pem contains both a key and a certificate or not?

If the answer is no, you need to provide the key.pem file using the command above. If you are converting your key from a .p12 file, then check this question.

Read this to write the code correctly.

0
source

Source: https://habr.com/ru/post/1468865/


All Articles