Ssl – Export specific certificate from JKS using keytool

apache-2.2httpdsslssl-certificate

We're trying to configure Apache HTTPd to use an SSL cert from a JKS keystore file we have. Since we want only one of the certs out of the JKS (www.MySite.com) and not the others (such as test.MySite.com), how do we specify the correct certificate pair to export?

This is the command we're using.

keytool -importkeystore -srckeystore MyKeystore.jks -srcstoretype JKS
\ -destkeystore keystore.p12 -deststoretype PKCS12

This appears to pick one (at random?) from the JKS file to export. And not the one we want….

Forgive me if I have all this wrong, SSL is way out of my wheelhouse. Thanks for any help.

Best Answer

List the certificates inside a keystore to get the alias

keytool -list -v -keystore KEYSTORE.jks

Convert a JKS file to PKCS12 format (Java 1.6.x and above)

keytool -importkeystore -srckeystore KEYSTORE.jks -destkeystore KEYSTORE.p12 \
-srcstoretype JKS -deststoretype PKCS12 -srcstorepass mysecret  \
-srcalias myalias -destalias myalias

See also: http://shib.kuleuven.be/docs/ssl_commands.shtml