Raj5198
Raj5198

Reputation: 25

How to read browsers certificates uisng java on linux? by using keyStore.getInstance("xyz")

Am trying to read the installed certificates by using code

KeyStore ks = KeyStore.getInstance("Windows-MY")  
ks.load(null, null)    
Enumeration<String> enumeration = ks.aliases()  
while (enumeration.hasMoreElements()) {    
String string = (String) enumeration.nextElement()    
System.out.println(string)   
}  

this code list out the installed certificates on windows but on linux doesn't? tried by changing the keystore providers also.

Upvotes: 2

Views: 1302

Answers (3)

Shiva kumar
Shiva kumar

Reputation: 732

You can get the Default Type. Try the below code

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

Upvotes: 0

WesternGun
WesternGun

Reputation: 12748

Try with libsoftokn3.so of NSS.

See my answer here, "Approach 1".

The key is to find where libsoftokn3.so is, and use it as the libfile to construct a config file, and then a KeyStore.

Upvotes: 0

Bert Jan Schrijver
Bert Jan Schrijver

Reputation: 1531

I'm not sure what you mean with "read browsers certificates". Are you trying to read certificates from the default Java keystore? What's your goal?

KeyStore.getInstance(..) instantiates a keystore with a specific type (JKS, for example). When you want to read from a specific keystore, you need to specify the path to the keystore and make the KeyStore instance load that file.

See http://www.java2s.com/Code/Java/Security/RetrievingaKeyPairfromaKeyStore.htm for an example and https://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html for more details.

Edited: updated answer after clarified question.

You can find more info on reading browser keystores in Linux on:

  1. http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/keystores.html
  2. https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/JSS
  3. applet with SunMSCapi not working in linux
  4. http://forums.mozillazine.org/viewtopic.php?p=12037571

Upvotes: 1

Related Questions