I have this in activemq config
<sslContext>
<sslContext keyStore="file:/home/alex/work/amq/broker.ks"
keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts"
trustStorePassword="password"/>
</sslContext>
I have a pair of x509 cert and a key file
How do I import those two to be used in ssl and ssl+stomp connectors? All examples i could google always generate the key themselves, but I already have a key.
I have tried
keytool -import -keystore ./broker.ks -file mycert.crt
but this only imports the certificate and not the key file and results in
2009-05-25 13:16:24,270 [localhost:61612] ERROR TransportConnector - Could not accept connection : No available certificate or key corresponds to the SSL cipher suites which are enabled.
I have tried concatenating the cert and the key but got the same result
How do I import the key?
I used the following two steps which I found in the comments/posts linked in the other answers:
Step one: Convert x509 Cert and Key to a pkcs12 file
Note: Make sure you put a password on the p12 file - otherwise you'll get a null reference exception when you try to import it. (In case anyone else had this headache). (Thanks jocull!)
Note 2: You might want to add the
-chain
option to preserve the full certificate chain. (Thanks Mafuba)Step two: Convert the pkcs12 file to a java keystore
Finished
OPTIONAL Step Zero, create self-signed certificate
Cheers!
First convert to p12:
Create new JKS from p12:
Keytool in Java 6 does have this capability: Importing private keys into a Java keystore using keytool
Here are the basic details from that post.
Convert the existing cert to a PKCS12 using OpenSSL. A password is required when asked or the 2nd step will complain.
Convert the PKCS12 to a Java Keystore File.
And one more:
Yes, it's indeed a sad fact that keytool has no functionality to import a private key.
For the record, at the end I went with the solution described here
Previous answers point out correctly that you can only do this with the standard JDK tools by converting the JKS file into PKCS #12 format first. If you're interested, I put together a compact utility to import OpenSSL-derived keys into a JKS-formatted keystore without having to convert the keystore to PKCS #12 first: http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art049
You would use the linked utility like this:
(sign the CSR, get back localhost.cer)