在Java cacerts中导入根证书和中间证书的正确方法

时间:2017-02-03 15:42:41

标签: java ssl certificate ssl-certificate x509certificate

我公司有自己的ROOT证书。使用此证书,他们签署了intermediate证书。

然后我们为server证书颁发了CSR,并使用intermediate证书进行了签名。

在Java cacerts文件中导入ROOT证书和intermediate的正确方法是什么,以便能够与具有server证书签名的服务器建立SSL连接intermediate

我使用OpenSSL测试服务器上的证书链:

openssl s_client -showcerts -connect host:443

CONNECTED(00000003)
depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
verify error:num=27:certificate not trusted
verify return:1
depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
 0 s:/C=COUNTRYCODE/ST=myCountry/O=myOrganization/CN=myServer/emailAddress=myMail
   i:/CN=INTERMEDIATECERT
-----BEGIN CERTIFICATE-----
MIIFr...
-----END CERTIFICATE-----
---
Server certificate
subject=/C=COUNTRYCODE/ST=myCountry/O=myOrganization/CN=myServer/emailAddress=myMail
issuer=/CN=INTERMEDIATECERT
---
No client certificate CA names sent
---
SSL handshake has read 1601 bytes and written 589 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA

1 个答案:

答案 0 :(得分:2)

您只需要在信任库中导入根证书。

 keytool -import -trustcacerts -keystore path/to/cacerts -storepass changeit  -alias aliasName -file path/to/certificate.cer

握手期间的SSL服务器应提供证书和中间人。您的客户的TrustManager将验证证书链,直到找到root

注意:建议使用您自己的信任库而不是修改cacerts