首页 > 解决方案 > 我应该如何在 BoringSSL 中使用 TLS_with_buffers_method() 与带有自签名证书的 OpenSSL 服务器通信?

问题描述

我正在尝试在与使用 OpenSSL 的服务器通信的客户端中使用 BoringSSL。客户端和服务器都位于内部网络中,并使用私有 IP 地址(192.168.xx)进行通信。BoringSSL 库公开的用于创建 SSL 连接的两个函数之一SSL_CTX_new()TLS_with_buffers_method(). 我已经尝试过这个功能,但它无法与我的 OpenSSL 服务器建立,因为来自服务器的证书是自签名的。

根据下面 BoringSSL 的移植指南,它避免了创建 X509 对象。

"The function TLS_with_buffers_method returns an SSL_METHOD that avoids creating X509 objects for certificates. Additionally, SSL_CTX_set0_buffer_pool can be used to install a pool on an SSL_CTX so that certificates can be deduplicated across connections and across SSL_CTXs."

但是,我的服务器使用 OpenSSL 使用的是使用 x509 创建的证书并且是自签名的。我不熟悉 SSL 证书的详细信息。从这篇文章看来,自签名需要 x509。

这是否意味着如果我必须使用自签名证书 BoringSSL 在这里可能不是一个选项?

标签: sslopensslx509certificateboringssl

解决方案


1) 正如PORTING.md后面几行所说

为了使用缓冲区,应用程序代码还需要使用 SSL_[CTX_]set_custom_verify 实现自己的证书验证。否则,所有连接都将失败并出现验证错误。使用缓冲区时也会禁用自动链接。

所以看起来你需要这样做。请注意,它说的是all,而不仅仅是自签名。真可惜。

2) 使用 OpenSSL 创建自签名证书不需要x509 subcommand。正如您链接上的答案正确地说,您可以执行两个步骤,例如

openssl req -newkey parms -keyout keyfile -out reqfile # create key and CSR 
# if you want RSA with size per the config file, you can use -new (without value) instead
openssl x509 -req reqfile -signkey keyfile -out certfile # create cert from CSR

或者像这样的一个步骤

openssl req -newkey parms -x509 -keyout keyfile -out certfile # create key and directly create cert 
# ditto
# that's the DASH-x509 OPTION on the req COMMAND, not the x509 COMMAND

另外,您还可以使用不同的第二步,例如

openssl req -newkey parms -keyout keyfile -out reqfile # create key and CSR 
# ditto
openssl ca -in reqfile -selfsign -keyfile keyfile # create selfsigned cert from CSR
# but this also requires some other files to be set up and/or options added

结果是一样的。如果你想添加扩展,现在你经常特别为 SSL/TLS 做,这三种方法都可以这样做,但细节略有不同,所以要正确,你必须查看手册页部分实际上是为了你在做什么

还有更多选择;您可以单独创建密钥(并且有多个选项) 然后使用其中一个req -new -key f(但不是-newkey),后跟一个x509 -reqca -selfsign -in,或者只是req -new -x509 -key f(同上)。

但是所有这些最终都得到了相同的证书,证书不是你的问题,BoringSSL API 是。


推荐阅读