OpenSSL 忽略自签名证书错误
我正在使用 OpenSSL 库编写一个小程序,该程序应该与 SSLv3 服务器建立连接。此服务器分发自签名证书,这会导致握手失败并显示以下消息:“sslv3 警报握手失败,证书链中的自签名证书。”
有什么办法可以强制连接继续进行吗?我尝试像这样调用 SSL_CTX_set_verify :
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
但它似乎没有改变任何东西。
有什么建议吗?
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."
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.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
默认情况下,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:So the solution is to create a simple callback and set that one, so that you override all certificate-chain walking:
您是否尝试过向您的应用提供服务器的 CA 证书,以便您的应用可以验证证书链?
Have you tried giving your app the server's CA certificate so that your app can verify the certificate chain?
检查这些 OpenSSL 示例:http://www.rtfm.com/openssl-examples/
wclient.c 连接到任何 https 页面,例如:
如果您使用默认安装运行该页面,您将收到证书错误(您可以使用 -i 标志来绕过证书检查) )。
要验证证书,您需要下载 CA 证书(Verisign、Thawte、Equifax 等),因此请在 google 上搜索此文件 cacert.pem,下载并将其重命名为 root.pem ,您将能够连接到网络服务器并验证其证书。
Check these OpenSSL Examples: http://www.rtfm.com/openssl-examples/
The wclient.c connects to any https page, for example:
If you run that with the default installation, you'll get a certificate error (you can use the -i flag to bypass the certificate check though).
To verify the certificate, you'll need to download the CA certificates (Verisign, Thawte, Equifax, etc), so google this file cacert.pem, download and rename it to root.pem and you'll be able to connect to a web server and validate its certificate.
您是否尝试过设置 SSL_set_verify ?
Have you tried setting SSL_set_verify?
您可以尝试将自己的回调传递给
SSL_set_verify()
,然后进行自己的验证。这不太理想,因为我认为您需要执行所有验证,然后允许忽略自签名错误,但您应该能够从 OpenSSL 源中找出标准验证代码的作用,然后简单地提取它进入您自己的验证回调并允许特定的错误代码...You could try passing your own callback to
SSL_set_verify()
and then doing your own verification. It's less than ideal as I think you then need to do all of the verification and then allow the self signed error to be ignored, but you should be able to work out what the standard verify code does from the OpenSSL source and then simply pull it into your own verification callback and allow the specific error code...我的示例客户端代码(链接)可以很好地使用自签名服务器证书。我在 SSL_connect 之后有以下代码,并且可以完全控制客户端中自签名证书的可接受性
My sample client code (link) works fine with self signed server cert. I have the below code after SSL_connect and have full control over self signed certificates acceptability in my client