What can cause a NullPointerException inside Sun's JavaKeyStore.engineStore () method?

We have an application that creates KeyStore program code. We create a KeyStore as follows (sample code that suppresses exception handling for brevity),

 KeyStore ks = KeyStore.getInstance( "JKS" ); ks.load( null, null ); ... // Add crypto material here keystore.store( new FileOutputStream( "keystore.ks" ), "password" ); 

The store(OutputStream stream, char[] password) method throws the following exception,

 java.lang.NullPointerException at sun.security.provider.JavaKeyStore.engineStore(Unknown Source) at sun.security.provider.JavaKeyStore$JKS.engineStore(Unknown Source) at java.security.KeyStore.store(Unknown Source) 

The keystore.ks file is created on the file system. But when we try to test it with keytool , we get

 keytool -list -keystore nms.keystore keytool error: java.io.EOFException 

It's funny that the same code works fine on all the other machines that we tested. In the actual code, none of the arguments passed to the store method is null , we checked three times.

Some details about a bad car,

  • CentOS 5.8 32 bit
  • Sun JRE 1.6.0_43
+4
source share
1 answer

The best explanation so far for what was happening is that something in the certificates that were stored in Keystore caused NPE inside the method

sun.security.provider.JavaKeyStore.engineStore() .

Generated certificates are stored in the keystore with their complete trust chain. For example, an entry for certificate A will look like

Cert A alias : Cert A -> Intermediate CA Trust -> Root CA Trust

The error disappeared after restoring the entire trust chain. This is consistent with our previous observations, because the chain of trust was the only difference between the systems that worked and the systems that were not.

I looked at the source of the sun.security.provider.JavaKeyStore class on Grep Code and Java Source Code , but I can’t say what can cause NPE in this code.

In the end, we have a solution, but we do not know the root cause.

0
source

Source: https://habr.com/ru/post/1469100/


All Articles