Some years ago, I was scared of the certificates and was quite confused about how to set it up. I remember just following my colleagues commands. Later on, I have received a task to set up servers and renew a lot of certificates. After all, It was not that complicated to do the basic set up/renewals.
There are keystore and truststore terms. The keystore contains certificate (e.g. SSL with chain) to be a server certificate. On the other side, truststore contains certificates your computer or Java application should trust (e.g. root CA certificate, usually same as root of SSL in keystore, if internal application)
With tomcat and java you can set up keystore and truststore in server.xml. https://tomcat.apache.org/tomcat-9.0-doc/config/http.html
Keystore usually with SSL certificate and chain (root and parent):
keystoreFile="keystoreName.any" keystorePass="keystorePassword"
Truststore in server.xml :
truststoreFile="truststoreName.jks" truststorePass="truststorePassword"
Note: Java cacerts is also a truststore.
It is also possible to load it via Java options in tomcat
-Djavax.net.ssl.keyStore=keystoreName.any
-Djavax.net.ssl.keyStorePassword=keystorePassword
-Djavax.net.ssl.trustStore=truststoreName.jks
-Djavax.net.ssl.trustStorePassword=truststorePassword
I like to set up a custom truststore with my own certificates and then also trust Java cacerts optionally. That way, when Java is updated/re-installed, I don’t have to re-import the certificates to cacerts.
Creating keystore/truststore:
Use Java keytool command to generate the keystore and add/remove certificates. https://docs.oracle.com/en/java/javase/17/docs/specs/man/keytool.html
Examples:
keytool -import -file root.cer -alias ca_root -keystore keystoreName.any
keytool -list -keystore keystoreName.any -storepass keystorePassword
Note: you can also use openssl command, to check and review certificates if needed.
Now, what a strange issue i faced last week
My colleagues were renewing certificates in the keystore (SSL/server certificate) and followed the standard steps. All went fine till the final step – it threw an error:
- Generate CSR
- Get response from CA team (generate yourself)
- Import Root and issuing certificates
- Import the certificate itself (error)
keytool error: java.lang.Exception: Failed to establish chain from reply
Strange, steps are good, certificates seems good too. When improted to windows certificate store. It actually showed that there is something wrong on the certificate itself, i thought.
This certificate has an invalid digital signature.
Assuming, still, this is something wrong with certificate. Contacted the CA team that there is an issue. Team comes back, that everything is good. I used openssl tool to verify the certificate and spot some difference in text output.
There was nothing unusual. Therefore i created a new keystore and new CSR and sent it to CA team.
After some time i got answer with the new certificate with new chain (same names), but the Issuing was different. After questioning CA team, they confirmed they sent corrupted/wrong issues certificate and now is all good. It was all good now for new keystore and also previous one.
Whats the lesson here?
Read the error message more broadly after all checks fail. And again don’t trust it when someone says its all good and push back a bit. Luckily I didn’t have to deal with some ego colleagues as before.
Would that error hint you the relation to issuing cert? And also that it happened during the server cert import? Well, it didn’t for me, but now i know and will remember this.