将CA签名证书导入JKS

时间:2015-08-11 17:54:46

标签: ssl certificate wso2 wso2is ca

我从CA获得了4个.crt文件,如下所示,

AddTrustExternalCARoot.crt
COMODORSADomainValidationSecureServerCA.crt
COMODORSAAddTrustCA.crt
demo_site_domain.crt

第二和第三是中间证书。我想将.crt文件导入wso2carbon.jks存储,并将其替换为wso2服务器的现有jks,如文档here所示。 我的问题是,文档想要wso2carbon作为别名,但我只能使用该别名导入一个证书,因此我应该导入哪个.crt文件?或者我应该导入一个从上面的四个crt文件创建的复合.crt文件(可能吗?) 我尝试使用AddTrustExternalCARoot.crtdemo_site_domain.crt,但在我在wso2服务器中设置.jks文件后,服​​务器网址出现以下错误,

  

安全连接失败

     

当页面被中断时,与ip:port的连接被中断   负荷。

The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
Please contact the website owners to inform them of this problem.

我在这里做错了什么?

我使用的wso2服务器是WSO2 UES,我必须将密码放在以下四个文件中以克服Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect错误。

repository/conf/security/cipher-text.properties
repository/conf/identity.xml
repository/conf/carbon.xml
repository/conf/tomcat/catalina-server.xml

更新

我按照给出的答案,但最后一个命令没有给installed in keystore而不是Certificate was added to keystore 以下是我的命令和反应,

keytool -importcert -keystore wso2carbon.jks -file AddTrustExternalCARoot.crt -alias commoroot -trustcacerts

输入密钥库密码:
重新输入新的密码: 证书已存在于别名下的系统范围的CA密钥库中 您是否仍想将其添加到自己的密钥库中? [不]:是的 证书已添加到密钥库

keytool -importcert -keystore wso2carbon.jks -file COMODORSAAddTrustCA.crt -alias commointermediate1

输入密钥库密码:
证书已添加到密钥库

keytool -importcert -keystore wso2carbon.jks -file COMODORSADomainValidationSecureServerCA.crt -alias commointermediate2

输入密钥库密码:
证书已添加到密钥库

keytool -importcert -keystore wso2carbon.jks -file demo_site_domain.crt -alias wso2carbon

输入密钥库密码:
证书已添加到密钥库

1 个答案:

答案 0 :(得分:3)

(Meta:我很确定这是重复的,但我找不到一个好的。无论如何都要回答。)

That page似乎缺少keytool命令行选项和PEM文件格式所需的所有破折号;假设你已经纠正了这个问题:

在第3项中,它表示“您可能必须导入任何中间证书......才能导入[CA-]签名证书”。事实上,你这样做。有两种方法可以做到这一点:

1:将您的服务器(或其他最终实体)证书以外的每个证书从上到下导入到密钥库中的单独条目;对于你的情况: keytool -importcert -keystore wso2carbon.jks -file AddTrustExternalCARoot -alias somealias1 -trustcacerts keytool -importcert -keystore wso2carbon.jks -file COMODORSAAddTrustCA.crt -alias somealias2 keytool -importcert -keystore wso2carbon.jks -file COMODORSADomainValidationSecureServerCA.crt -alias somealias3 其中somealias{1,2,3}别名彼此不同,并且与密钥库中已有的别名不同,尤其是wso2carbon。 Meta:那些code行不应该像那样包裹,但我不能让它们停止。

然后将您的服务器证书导入(编辑)相同密钥库文件中的相同别名,其中-genkeypair-certreq 之前已完成(或者是-genkeypair和{{strong>之前创建的PrivateKey条目的此密钥库中的副本的别名{1}}): -certreq 这(最后)步骤应该说 keytool -importcert -keystore wso2carbon.jks -file demo_site_domain.crt -alias wso2carbon NOT Certificate reply was installed in keystore。否则它实际上失败了,即使它没有给出错误信息。

2:首先将所有证书连接到一个文件中,首先使用服务器(EE)证书,然后将组合文件导入(编辑)使用的同一个密钥库文件中的相同别名早先(或该私钥表项的副本):

Certificate was added to keystore

除了第一个之外的证书的顺序实际上并不重要 here ,但它们将存储在密钥库中并以“向上”顺序在SSL / TLS协议中使用,因此我使用# assuming any kind of Unix cat demo_site_domain.crt COMODORSADomainValidationSecureServerCA.crt \ COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt >combinedfile # if Windows use copy a+b+etc or (for PEM) cut&paste in a plaintext editor like Notepad keytool -importcert -keystore wso2carbon.jks -file combinedfile -alias wso2carbon -trustcacerts 中的顺序是为了保持一致性和清晰度。

(编辑)如果在任何时候对您在给定密钥库文件中有或没有的条目有任何疑问,可以使用cat列出它们。您使用keytool -list -v -keystore filename生成的任何条目都是-genkeypair条目,并且 是由PrivateKey 或您从CA获得的带有链的证书。显示格式相当混乱,可能令人困惑,但查找keytool Certificate[1]:等行,紧接着是Certificate[2]:的行(标准术语中的主题)和{{ 1}}。 另一方面,您单独导入的每个CA根证书或中间证书都将是仅包含该证书的Owner:条目。

该页面还说明您需要将“签名证书”导入Issuer:。我认为这是错的。您通常需要在任何客户端信任库中放置自签名证书,但您不需要为知名CA签署的证书执行此操作,Comodo / Addtrust是。但是,不会损害向信任库添加不必要但有效的证书。