C ++和cUrl:如何获取SSL错误代码 [英] C++ and cUrl : how to get SSL error codes

查看:324
本文介绍了C ++和cUrl:如何获取SSL错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过SSL建立与安全服务器的连接。
一切正常,我的CAcertificate通过

I am establishing a connection to a secured server over SSL. Everything works fine, my CAcertificate is well used through

retCode=curl_easy_setopt(handleCurl, CURLOPT_CAINFO, sSSLCertificate);
retCode=curl_easy_setopt(handleCurl, CURLOPT_SSL_VERIFYPEER, 1);



当我尝试管理curl错误时,我被卡住了。基本上我想能够在SSL发生问题时通知(错误的cacert.pem,服务器身份未验证等)。

I'm stuck when i try to manage curl errors. Basically i want to be able to be notified when a problem happens with the SSL (wrong cacert.pem, server identity not verified etc).

当给出CURLOPT_CAINFO时,什么都不会发生一个空的CAcert,retCode是OK的。

Nothing happens when CURLOPT_CAINFO is given an empty CAcert, retCode is OK.

我试图在请求后获得信息:

I tried to get info after the request with that :

res = curl_easy_getinfo(m_pHandleCurl, CURLINFO_SSL_VERIFYRESULT, &lSSLVerifyResult);

但它总是告诉我,everithing很好。

But it always tells me that everithing is fine.

我遗漏了什么?

推荐答案

添加到您的连接设置代码:

Add to your connection setup code:

// Make sure this is NOT a stack variable! The buffer
// must be available through whole live of the connection
char buffer[CURL_ERROR_SIZE+1] = {};

retCode=curl_easy_setopt(handleCurl, CURLOPT_ERRORBUFFER, buffer);

那么当你的连接结束时,检查缓冲区中的内容 - 你应该能够看到一些提示关于SSL状态。

then when your connection has ended, check what's in the buffer - you should be able to see some hints regarding SSL state, too. It will be empty if no error occurred.

如果你想要实际的代码,数字 CURLcode 总是返回<

If you want actual code, numeric CURLcode is always returned by curl_easy_perform for easy handles.

如果您使用多个句柄,请使用 curl_multi_info_read curl_easy_perform

If you use multi handles, use curl_multi_info_read instead. Here is example:

int u = 0;
if (CURLM_OK == curl_multi_perform(multi_, &u))
{
  int q = 0;
  CURLMsg *msg = NULL;
  while ((msg = curl_multi_info_read(multi_, &q)) != NULL)
  {
    if (msg->msg == CURLMSG_DONE)
    {
      CURL* easy = msg->easy_handle;
      CURLcode code = msg->data.result;
      // . . .
    }
  }
}

这篇关于C ++和cUrl:如何获取SSL错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆