I'm going to show you all how I had to fiddle with the Java KEYTOOL application and the keystore it creates to get a certificate I already had working in Apache Tomcat.
I needed to do this to get two web apps, on one server, with one FQDN, working with the same certificate.
One of these apps was a straight Apache application and one was written using the Tomcat framework.
You are going to need...
- Your server certificate from GoDaddy, Verisign, etc.
- Your certificate private key file (created when you generated your cert).
- OpenSSL binaries for Windows (if you are using Windows).
- Java Keytool binaries for Windows (if you are using Windows).
Here is what I did and I hope this works for you.
- Get your CRT file working in Apache. This is easy and you should be able to Google/Bing/Yahoo the heck out of how to do this. But, verify it is working and you get no errors when you browse to your location.
- Download and unzip the OpenSSL binaries.
- Copy your CRT file and your KEY file to the OpenSSL file location.
- Convert your CRT and KEY to a P12 file. Use this command:
openssl pkcs12 -export -in [your crt file name here] -inkey [your key file name here] -out [your end result file here].p12
- Once complete you will have a P12 file of your own naming in your directory.
- Download or locate your KEYTOOL binary on your system.
- Setup a directory for your new KEYSTORE, I called my NEWSTORE
- Copy your P12 file to the NEWSTORE folder.
- We are going to create a "crap" keystore using the command:
keytool -genkey -alias crappyserver -keyalg RSA -keystore [your keystore filename] -keysize 2048
- Once complete we will have a file that is our new keystore with one, sorta, bogus entry in it. Remember the alias we used... crappyserver. We'll need that later.
- I used a certificate from GoDaddy. So, I need to import the GoDaddy trusted CA cert into my KEYSTORE. Use this command for that:
keytool -import -alias root -keystore [your keystore filename] -trustcacerts -file [path and filename of the trusted CA cert]
- Once complete our KEYSTORE has our bogus record and our CA record it it. We can check that by listing the contents of the KEYSTORE file. Use the command:
keytool -list -v -keystore [your keystore filename]
- Now we need to import out P12 file. Use the command:
keytool -importkeystore -srckeystore [your P12 file filename] -srcstoretype PKCS12 -destkeystore [your keystore filename] -deststoretype JKS
- Once complete, we have our bogus record, our CA cert and our server certs P12 file all in our KEYSTORE.
- Now, let's clean up our KEYSTORE and remove the bogus record. Use the command:
keytool -delete -alias crappyserver -keystore [your keystore filename]
Just to note:
You WILL need to know your key passwords to do this.
You WILL need to set and type, alot, your KEYSTORE password.
When done, you can copy your KEYSTORE file to the location you need and adjust the filename and password in the SERVER.XML in your Tomcat application.
Hope this helps someone.