OpenSSL Ignore Self-signed certificate error(OpenSSL 忽略自签名证书错误)
问题描述
我正在使用 OpenSSL 库编写一个小程序,该库假设与 SSLv3 服务器建立连接.此服务器分发自签名证书,导致握手失败并显示以下消息:sslv3 alert handshake failure, self-signed certificate in certificate chain."
I'm writing a small program with the OpenSSL library that is suppose to establish a connection with an SSLv3 server. This server dispenses a self-signed certificate, which causes the handshake to fail with this message: "sslv3 alert handshake failure, self signed certificate in certificate chain."
有没有办法强制连接继续?我试过这样调用 SSL_CTX_set_verify:
Is there a way I can force the connection to proceed? I've tried calling SSL_CTX_set_verify like so:
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
但它似乎并没有改变任何东西.
But it does not seem to change anything.
有什么建议吗?
推荐答案
默认情况下,OpenSSL 会遍历证书链并尝试在每一步进行验证,SSL_set_verify() 不会改变这一点,请参阅页.引用它:
By default OpenSSL walks the certificate chain and tries to verify on each step, SSL_set_verify() does not change that, see tha man page. Quoting it:
实际的验证过程是使用内置验证程序或使用提供的其他应用程序使用 SSL_CTX_set_cert_verify_callback(3) 设置的验证函数.
The actual verification procedure is performed either using the built-in verification procedure or using another application provided verification function set with SSL_CTX_set_cert_verify_callback(3).
因此解决方案是创建一个简单的回调并设置它,以便您覆盖所有证书链遍历:
So the solution is to create a simple callback and set that one, so that you override all certificate-chain walking:
static int always_true_callback(X509_STORE_CTX *ctx, void *arg)
{
return 1;
}
SSL_CTX_set_cert_verify_callback(CTX, always_true_callback);
这篇关于OpenSSL 忽略自签名证书错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OpenSSL 忽略自签名证书错误
基础教程推荐
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
