SSL handshake failure when importing certificates from file

淺唱寂寞╮ 提交于 2019-12-04 21:52:43

A third party certificate shouldn't be imported as 'mycert'. It isn't your certficate, it's someone else's. In addition, you have just clobbered your own key pair and certificate. Start again, using a different alias for the 3rd-party cert.

The thing is that the keystore has to contain a public certificate and a private key.
In the first example, keytool is creating both of them and putting them into the keystore.
In the second example, you are missing the private key.

You should do:

  1. Import the public certificate and the private key into a pkcs12 (*.p12) keystore
    openssl pkcs12 -export -in mycert.crt -inkey mykey.key \ -out lig.p12 -name some-alias \ -CAfile ca.crt -caname root

  2. Convert the pkcs12 to JSK
    keytool -importkeystore \ -deststorepass changeit -destkeypass changeit -destkeystore lig.keystore \ -srckeystore lig.p12 -srcstoretype PKCS12 -srcstorepass some-password \ -alias some-alias

  3. Refer to this new JKS keystore from your code


Arguments explanation

mycert.crt --> your public certificate
mykey.key --> your private key
ca.crt --> the public certificate of the Certification Authority who signed your public certificate and private key

You could not use that ca.crt for creating the p12 keystore, but you should. The p12 is supossed to hold that too, and you may have problems with some libraries if it isn't there. Anyway, you can try with and without it; in case of fail, the library will most probably tell you about the problem quite clearly.
If you are using self-signed certificates, you absolutely can forget that ca.crt argument, and no program should give you any problem. But if I understood well, you are using third-party certificates, so my guess is that they already gave you their ca.cert or maybe a .p12 with everything (or a .pfx, which is the same).

If it's still unclear, you could list the files they provided you, and I could tell you which one is which. I guess the system administrator names the files coherently (they usually do), so it should be quite straightfoward.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!