wajdiBen / jsslutils

Automatically exported from code.google.com/p/jsslutils
0 stars 0 forks source link

KeyStoreLoader doesn't honor keyStoreInputStream when keyStorePath="NONE" #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Construct a KeyStoreLoader by doing: 
KeyStoreLoader ksl = new KeyStoreLoader()
2. call ksl.setKeyStorePath("NONE");
3. call ksl.setKeyStorePassword("the correct password");
3. call ksl.setKeyStoreInputStream(jksInputStream); where jksInputStream is a 
non-null inputstream to a jks file.
4. call ksl.loadKeyStore()

What is the expected output? 
Expect at this point that my keystore is loaded and returned by the 
loadKeyStore() method.

What do you see instead?
Instead, the KeyStore is not loaded because the keyStoreInputStream is null.

What version of the product are you using? 
1.0.5

On what operating system?
Running on my local Windows 7 Enterprise machine.

Please provide any additional information below.
By debugging the source of KeyStoreLoader, I see this:
391:  InputStream keyStoreInputStream = this.keyStoreInputStream;
392:  try {
393:      keyStoreInputStream = (!"NONE".equals(this.keyStorePath)) ? new 
FileInputStream(
394:               this.keyStorePath)
395:               : null;

Since I do not want the KeyStoreLoader to load the jks from a file but rather 
my inputStream, I have set keyStorePath = "NONE", so the code above sets the 
local variable keyStoreInputStream = null (which I believe is the bug), rather 
than to the properly-set member variable this.keyStoreInputStream.

I am thinking the fix should be:
393:   if (!"NONE".equals(this.keyStorePath)) {
394:       keyStoreInputStream = new FileInputStream(this.keyStorePath);
395:   }

Or, as per the javadoc comment in the setKeyStoreInputStream method "If null, 
falls back to KeyStore path.", the better fix might be:
393:   if (null != this.keyStoreInputStream) {
394:       keyStoreInputStream = new FileInputStream(this.keyStorePath);
395:   }

As a side note, I want to say THANK YOU for taking the time to write this 
awesome little api! 
You saved me hours and hours of implementing this myself!
-Tim

Original issue reported on code.google.com by tvatt...@gmail.com on 13 Oct 2014 at 6:56