openssl - openSSL SSL_CTX_load_verify_locations 失败
问题描述
在 Linux Debian 上,考虑以下 C/C++ 片段:
TRACE << "TLSv1_2_client_method() started";
// Set up a SSL_CTX object, which will tell our BIO object how to do its work
const SSL_METHOD* method = TLSv1_2_client_method();
TRACE << "TLSv1_2_client_method() ended";
if (method == NULL) {
ERROR << "SSL_METHOD is null";
return false;
}
TRACE << "SSL_CTX_new() started";
SSL_CTX* ctx = SSL_CTX_new(method);
TRACE << "SSL_CTX_new() ended";
if (ctx == NULL) {
ERROR << "SSL CTX is null";
return false;
}
TRACE << "SSL_CTX_set_verify() started";
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
TRACE << "SSL_CTX_set_verify() ended";
TRACE << "SSL_CTX_set_verify_depth() started";
SSL_CTX_set_verify_depth(ctx, 4);
TRACE << "SSL_CTX_set_verify_depth() ended";
TRACE << "SSL_CTX_load_verify_locations() started";
if (!SSL_CTX_load_verify_locations(ctx, CA_CERTIFICATE_FILE, NULL)) {
ERROR << "SSL_CTX_load_verify_locations failed";
SSL_CTX_free(ctx);
return false;
}
TRACE << "SSL_CTX_load_verify_locations() ended";
这个函数已经运行了很长时间,但是前一天SSL_CTX_load_verify_locations返回了 0,因此函数返回了。
现在来自 openSSL 的文档:它只能在“操作失败,因为 CAfile 和 CApath 为 NULL 或指定位置之一的处理失败。检查错误堆栈以找出原因”时返回 0。
让我们把这句话分成几部分:
- (CAfile 和 CApath 为空)?没有。它们是代码中的硬编码定义。
- 或指定位置之一的处理失败?也许。
我感兴趣的是上面的可能。
此功能每分钟定期运行。日志文件中充满了此错误消息“SSL_CTX_load_verify_locations failed”。因此,确实可能会发生“指定位置之一的处理失败”。
但!杀死应用程序,然后重新启动它后,该功能再次按预期工作,没有任何错误。
在这种情况下,什么会导致 SSL_CTX_load_verify_locations 失败?显然与验证本身无关。(因为它在我重新启动应用程序后立即自行修复)
解决方案
推荐阅读
- stripe-payments - 错误:根据印度法规,出口交易需要客户姓名和地址
- python-3.x - 哪些类型的操作将/不会插入 Tensorflow 2 中的计算图?
- ios - 从播放 MIDI 音符时自动运行的函数更新 UIViewControler 内标签的文本
- ios - 未找到模块“混合面板”。混合面板-iphone
- c++ - 如果 constexpr 条件为假,如何避免编译此语句?
- git - Concourse 管道构建失败并出现错误提示:更新被拒绝,因为标签已存在于远程
- reactjs - React Native 项目通过 react native CLI 创建和运行错误
- android - 如何解决后续 .apk 上传证书与原始证书不同的问题
- c# - WPF MarkupExtension 绑定到字典
- reactjs - 检查 `App` 的渲染方法。将功能APP组件更改为类组件后