5

I have imported internal Certificate Authorities into Java's CA keystore. (Using keytool to import into the "cacerts" store) This works fine and dandy, until I update the Java RPM. At which point all of those imported certs are not carried over to the new install. So applications bomb when attempting to make SSL connections.

Is there any way to make these certificates persist through Java upgrades? Or an easy way to rerun the import commands on an upgrade trigger? I can obviously script these commands into my upgrade process, but I'm hoping there's a more elegant solution.

For reference, this is a RHEL 5.10 equivalent (technically Oracle Linux). I'm using java-1.7.0-openjdk through the official repositories, and just upgraded to U65.

Christopher Karel
  • 6,582
  • 1
  • 28
  • 34

2 Answers2

5

It may be helpful to keep your site-specific or host-specific key-store / trust-store outside the java installation-directory, and instead point to it when you need to consume trust. Presuming your trust-store is at /opt/site/cacerts.JKS, you would do that one of two ways:

In your Java code, add a line like: System.setProperty("javax.net.ssl.trustStore","/opt/site/cacerts.JKS");

At run-time, add a definition to your startup script: java -D'javax.net.ssl.trustStore'="/opt/site/cacerts.JKS" /opt/site/myClass.class

DTK
  • 1,718
  • 10
  • 15
  • 2
    Interesting work around. The downside is that you will never get certificate store updates (eg: new CAs) as part of a java upgrade. But it does definitely fix my issue. – Christopher Karel Oct 23 '14 at 13:47
  • This is true. I had assumed you had a predefined trust-store that is managed by security, and which could be pushed-out when new versions are built by your security team. – DTK Oct 24 '14 at 22:36
2

The way I do (maybe not the best?): save cacerts before upgrade and restore after, I scripted it in my update script like this:

1) save:

javaexe=`readlink -f  /usr/bin/java`
jredir=`dirname $javaexe`
cacertsfile=${jredir}/../lib/security/cacerts
[ -f $cacertsfile ] && cp -p $cacertsfile /tmp/cacerts

2) install updates (yum update or other way).

3) restore:

[ -f /tmp/cacerts ] && cp -p /tmp/cacerts $cacertsfile
tonioc
  • 1,047
  • 8
  • 11