【问题标题】:HTTPS using cURL, using openssl with the capi engineHTTPS 使用 cURL,使用 openssl 和 capi 引擎
【发布时间】:2011-05-19 03:28:30
【问题描述】:

我正在尝试使用带有 OpenSSL 1.0.0d 的 cURL 7.21.1 使用 https,使用 OpenSSL 的内置 capi 引擎进行证书颁发机构检查,但它在 curl_easy_perform() 上返回 CURLE_SSL_CACERT (60)。

#include <openssl/conf.h>
#include <openssl/engine.h>
#include <openssl/ssl.h>
#define CURL_NO_OLDIES
#define CURL_STATICLIB
#include <curl.h>

// Don't forget libeay32.lib, ssleay32.lib, curl.lib
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "wldap32.lib")
#pragma comment(lib, "crypt32.lib")

int main(int argc, char* argv[])
{
    OPENSSL_no_config();
    ENGINE_load_capi();
    // Same effect, despite ok = 1 both times:
    // ENGINE* capi = ENGINE_by_id("capi");
    // int ok = ENGINE_init(capi);
    // ok = ENGINE_register_complete(capi);

    CURLcode e = curl_global_init(CURL_GLOBAL_DEFAULT);
    CURL* curl = curl_easy_init();

    e = curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com/");
    e = curl_easy_perform(curl); // returns CURLE_SSL_CACERT
    return 0;
}

如果我使用以下配置测试“openssl s_client -connect www.google.com:443”:

openssl_conf = openssl_init

[openssl_init]
engines = engine_section

[engine_section]
capi = capi_config

[capi_config]
engine_id = capi
init=1

基于http://www.mail-archive.com/openssl-users@openssl.org/msg62249.html,我收到:

verify error:num=20:unable to get local issuer certificate

让我感到困惑的是,当我第一次编写失败的实际程序时,在我添加 ENGINE_load_capi() 之前,它有同样的失败。 我想避免使用 CA 捆绑包,因为实际程序可能在随机的公司网络中运行,而且它们可能使用私有 CA。

【问题讨论】:

  • 是在windows平台上做这个吗?
  • @this.josh:是的,我知道我不能在其他平台上使用 CryptAPI,但是基于 *nix 的平台可以使用平台 ca-bundle.crt,对吗?如果没有别的,我可能最终还是会为了可靠性而捆绑它。

标签: c curl openssl


【解决方案1】:

听起来 OpenSSL 在查找默认证书存储时遇到问题?以下 SO 问题通过明确指定 CA 文件解决了类似的错误,但听起来您想避免该配置。

OpenSSL unable to get local issuer certificate unless CAfile is explicitly specified

【讨论】:

  • 我相信我们确实做到了这一点,但它仍然很糟糕。我会看看它,看看我们做了什么,但我们不太可能很快触及它
【解决方案2】:

也许您可以尝试在您有权访问该域的文件中添加以下行。 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-20
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多