2

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.

Raj5198
  • 25
  • 1
  • 9

3 Answers3

1

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
Community
  • 1
  • 1
Bert Jan Schrijver
  • 1,521
  • 10
  • 16
  • 1
    here my problem is, i want list out the certificates which are installed by user on linux system. not specific certificate details. i have edited my post pleae check it once. thanks @bert jan – Raj5198 Feb 27 '16 at 12:20
0

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.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
0

You can get the Default Type. Try the below code

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
Shiva kumar
  • 673
  • 8
  • 23