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

How should I use TLS_with_buffers_method() in BoringSSL to talk to OpenSSL server with a self-signed certificate?

我正在尝试在与使用 OpenSSL 的服务器通信的客户端中使用 BoringSSL。客户端和服务器都位于内部网络中,并使用私有 IP 地址(192.168.x.x)进行通信。 BoringSSL 库公开的用于创建与 SSL_CTX_new() 的 SSL 连接的两个函数之一是 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 证书的详细信息。从 this post 看来,自签名需要 x509。

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

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

In order to use buffers, the application code also needs to implement its own certificate verification using SSL_[CTX_]set_custom_verify. Otherwise all connections will fail with a verification error. Auto-chaining is also disabled when using buffers.

看来您需要这样做。请注意,它说的是 all,而不仅仅是自签名的。无赖。

2) 使用 OpenSSL 创建自签名证书不需要 x509 子命令 。正如您 link 的答案正确所说,您可以执行两个步骤,例如

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,这三种方法都可以,但细节略有不同,所以要正确,你必须查看手册页部分这实际上是 你正在做的事情

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

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