Navigate / search

Java Runtime Environment (JRE) – How to Import Certificates

A lot of company applications are actually using the Java Runtime Environment (JRE) and a lot of them are integrated in the Internet Explorer using local adresses. When you open these kind of applications you will receive an error message that the application can not be trusted eventhough you provided your own root certificates by group policies. One big problem of the JRE is that it completelly ignores the Windows certificate stores. Instead of using the windows certificate store it uses its own implementation. Java certificates are stored in a file called  cacerts located at  C:\Program Files (x86)\Java\jre1.x.x_xxx\lib\security\ You can open javacpl.exe to get a graphical overview about the content:
Java Control Panel – javacpl.exe
Java Control Panel – Manage Certificates
You can import certificates as user certificates by the graphical user interface but you are not allowed to add any system certificates. This is only possible by using  keytool.exe  that is located in every standard JRE installation  C:\Program Files (x86)\Java\jre1.8.0_144\bin\keytool.exe The following command will import the certificate “C:\certificate.cer” to the keystore “cacerts” that is protected by the password “changeit”. If you have installed the JRE with default settings the standard keystore is always called “cacerts” and always protected by the password “changeit”. To get this command running without any user interaction I suggest to run it as a PowerShell script in system context during client login. This is the only way to ensure that private root certitificates are always up to date.
For updating public root certificates don’t use the keytool.exe. Just update to the newest java version. When using the following script your certificates will automatically be deployed after restart when using group policies. Official keytool documentation:


If we are talking about enterprise a solution is to call a script checking a certificate folder on a network share everytime a computer gets restarted. I’ve used the following script a lot of times with the help of group policies. Feel free to use it in your own environment. This script needs the following variables to be declared:
  • $JavaCertificateFolder – Defines a share that is hosting all root certificates ending by .cer . The script will automatically import all certificates stored in the share.
  • $JRE_HOME – Defines the Java home path. With that information the script can locate the keytool.exe and your cacerts  store.
  • $log – Defines a logging path. The script will always write a log to the path and name you’ve entered.

How does the script work?

  1. First the script validates if your declared variables $JavaCertificateFolder , $JRE_HOME and $log are valid.
  2. In the next step the script will check if $JavaCertificateFolder does contain any certificate files ending with .cer .
  3. The script will automatically set path to the  keytool.exe  and to the  cacerts  store.
  4. In the last step the script will execute the  keytool.exe  with the above eplained command for certificate import.
  5. All actions done by the script will be logged to the location you specified in $log. By default the path is  C:\Users\username\AppData\Local\Temp\W10_JavaKeystoreImport.log

How can I validate that everything worked as expected?

  • Check the log file you’ve defined in $log. If you can’t find any messages containing  [X] ERROR everything regarding your variables is fine.
  • Check  javacpl.exe to ensure that your certificates got imported.
  • Take a deep look in your log file starting at  Certificate Import. The automatic import will start at this point!

Leave a comment


email* (not published)


This site uses Akismet to reduce spam. Learn how your comment data is processed.