Meta: this feels like a duplicate but I couldn't easily find a match so ...
SSL/TLS server must have a certificate WITH MATCHING PRIVATE KEY and chain certs if applicable. A single certificate by itself, or even several certificates, is not sufficient. First do
keytool -list -v -keystore $d.jks
and look for a PrivateKey entry (NOT a trustedCert entry). If that is present, look at the cert(s) to determine whether they are the certs you want. If they aren't the desired cert(s), but you do have the desired cert(s) in your .crt and bundle files, then describe the contents of your .crt and especially bundle files and we can work out how to use them to fix the .jks. In particular, there are two formats commonly used for single certs and several for CA "bundles"; if you open the files in an editor like notepad or vi and the first line is -----BEGIN something-----
followed by a block of almost all letters and digits then ----END same----
and maybe more of the same, post the somethings; if they appear to be all random characters and you have a hex dump tool available post the first 64 bytes at least, or if you have OpenSSL or any other ASN.1 (binary) parser available post the results of that. If there is no privatekey at all, this .jks is useless; discard it and continue.
Your .key
file sounds likely to contain a private key, but there are dozens of different formats people label .key
and it's very unlikely this file is in a usable format. If the key is not more conveniently in the p12, we can come back to this.
Your .p12
file almost certainly contains the private key and some cert(s), but not necessarily the desired cert(s). (Technically the PKCS#12 standard allows a file with no private key, but all common tools that create PKCS#12 don't ever do that.) To see what you have now, do
keytool -list -v -keystore $d.jks -storetype pkcs12
If it is what you want, Tomcat (and Java/JSSE) can actually use a pkcs12 directly as a keystore in place of a JKS: just set keystoreFile
and keystorePass
for it and add keystoreType="pkcs12"
. Alternatively you can convert the pkcs12 to JKS with
keytool -importkeystore -srckeystore $d.p12 -srcstoretype pkcs12 -destkeystore $d.jks
If .p12 contains the privatekey but the wrong cert(s), there are two approaches:
first convert the pkcs12 to JKS as just above, then fix the certs in the JKS; this is now the same case as my first paragraph: JKS contains privatekey but wrong cert(s)
if you have or get OpenSSL, use it to "unpack" the pkcs12 into separate privatekey and cert files, replace the wrong cert files with the right ones, and reconstruct a new pkcs12. This puts you back in my fourth paragraph: pkcs12 with correct cert(s) which you can either use or convert to JKS and use that.