2013-03-18 62 views
0

我有一個自簽名證書和基於apache 2.x的網站,帶有這個證書。 只想通過SSL使用我的軟件訪問本網站。通過curl和Visual C++ 2010的HTTP + SSL

做以下幾點:

int _tmain(int argc, _TCHAR* argv[]) 
{ 

CURL *curl; 
    CURLcode res; 

    curl_global_init(CURL_GLOBAL_DEFAULT); 

    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "https://mysite.com"); 
    curl_easy_setopt(curl, CURLOPT_CAINFO, "n.crt"); 
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); 
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); 
curl_easy_setopt(curl, CURLOPT_CAPATH, "D:\\"); 
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L) ; 
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT); 

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl); 
    /* Check for errors */ 
    if(res != CURLE_OK) 
     fprintf(stderr, "curl_easy_perform() failed: %s\n", 
       curl_easy_strerror(res)); 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 

    curl_global_cleanup(); 

    return 0; 
} 

但每次我得到:

* About to connect() to mysite.com port 443 (#0) 
* Trying 1.1.1.1... * connected 
* Connected to mysite.com (1.1.1.1) port 443 (#0) 
* error setting certificate verify locations: 
    CAfile: n.crt 
    CApath: D:\ 

* Closing connection #0 
* Problem with the SSL CA cert (path? access rights?) 
curl_easy_perform() failed: Problem with the SSL CA cert (path? access rights?) 
Press any key to continue . . . 

請你的意見時,我做錯了嗎?

PS:

  • Win7的X64
  • MSVC++ 2010
  • 捲曲7.19.3(I386-PC-win32)中的libcurl/7.19.3的OpenSSL/0.9.8j協議:FTP TFTP的telnet字典LDAP http文件https ftps

回答

0

查找n.crt的位置。當可執行程序運行時,所有文件檢查都與其路徑有關。因此,將n.crt放入可執行文件夾中,或者在設置CURLOPT_CAINFO時放置文件的絕對路徑。否則使用證書信息文件的相對路徑。