当前位置: 代码迷 >> java >> SSL:使用openSSL创建并使用keytool安装的CSR文件
  详细解决方案

SSL:使用openSSL创建并使用keytool安装的CSR文件

热度:32   发布时间:2023-07-25 19:41:52.0

我已经使用命令openSSL创建了CSR,并购买了crt文件。

openssl genrsa -out private-key.pem 2048 
openssl req -new -key private-key.pem -out csr.pem

是否可以使用keystore命令安装此程序,因为我还没有使用keytool创建CSR文件(而是使用openSSL创建)?

另一个问题是我从受信任的证书生成公司获得了三个文件。 那么如何确定哪个是主,根,中间crt文件呢? 文件名本身未提及文件类型(root,intermediate)。 我必须根据crt文件类型运行以下命令。

keytool -import -alias root -keystore tomcat.keystore -trustcacerts -file [name of the root certificate]

keytool -import -alias intermed -keystore tomcat.keystore -trustcacerts -file [name of the intermediate certificate]

keytool -import -alias tomcat -keystore tomcat.keystore -trustcacerts -file [name of the certificate]

是否可以使用keystore命令安装此程序,因为我还没有使用keytool创建CSR文件(而是使用openSSL创建)?

您还必须将私钥导入密钥库。 否则,密钥库将无用。

有两种方法可以做到这一点:

  1. 首先使用OpenSSL创建PKCS#12文件,然后使用keytool将该文件转换为JKS(请参见 )。
  2. 使用 ,它具有用于OpenSSL格式的导入/导出功能。 说明可以在找到。

另一个问题是我从受信任的证书生成公司获得了三个文件。 那么如何确定哪个是主,根,中间crt文件呢?

您必须查看证书的内容,尤其是其专有名称(DN)。

  • 根CA证书始终具有相同的SubjectDN和IssuerDN。
  • 中间CA具有根CA的SubjectDN作为它的IssuerDN和一个不同的SubjectDN。
  • SSL证书将中间CA的SubjectDN作为其IssuerDN,将域名作为其SubjectDN的一部分。

用于输出SubjectDN和IssuerDN的OpenSSL命令取决于证书文件的格式(DER或PEM)。 DER是二进制格式,PEM是ASCII格式。 如果不确定,请同时尝试以下两种方法:

openssl x509 -noout -subject -issuer -nameopt RFC2253 -inform DER -in <cert-file>

要么

openssl x509 -noout  -subject -issuer -nameopt RFC2253 -inform PEM -in <cert-file>