没有证书颁发机构的 mTLS

mTLS without Certificate Authority

我正在尝试实施要求客户端识别自身(双向 TLS) 的场景,这在 https://github.com/Hakky54/mutual-tls-ssl#require-the-client-to-identify-itself-two-way-tls.

中有描述

API 服务器是使用 https://quarkus.io/ 以及密钥库和信任库创建的。密钥库包含证书和私钥,信任库包含用于客户端标识的客户端证书。

现在,我想通过 curl 而不是 java 其余客户端向 API 服务器发出请求。

我发现,也许 上的解决方案是使用以下命令:

curl --key client.key --cert client.crt --cacert bundle.pem -X GET -v https://x.x.x.x:xxxx/folder/endpoint

需要传递选项--cacert。但是,我想要求客户端识别自己(双向 TLS) 而不是基于信任证书颁发机构的双向 TLS。 问题是,我是否可以在选项 --cert 上传递服务器证书而不是 CA 证书,或者还有其他选项。

我不想使用自签名证书。

可以,您可以通过--cert选项,但是您需要提供Base64编码的私钥对文件。在该教程中,密钥库文件用作 jks,您首先需要将其转换为 curl 可以理解的内容,在本例中为 pem 文件。您需要做的是:

  1. 将密钥库转换为 p12 文件
  2. 将 p12 文件转换为 pem 文件
  3. 运行 使用 pem 文件的 curl 命令

将密钥库转换为 p12 文件

keytool -importkeystore -srckeystore truststore.jks -destkeystore truststore.p12 -srcstoretype JKS -deststoretype PKCS12
keytool -importkeystore -srckeystore identity.jks -destkeystore identity.p12 -srcstoretype JKS -deststoretype PKCS12

将 p12 文件转换为 pem 文件

openssl pkcs12 -in truststore.p12 -out trusted-certificates.pem
openssl pkcs12 -in identity.p12 -out identity.pem

运行 带有 pem 文件的 curl 命令

curl --cert identity.pem --cacert trusted-certificates.pem https://localhost:8443/api/hello

这些步骤也可以在这里找到:GitHub Gist - Curl with Java KeyStore