56

I am writing an application that uses SSL. Hence, I have a dummy keystore and a dummy truststore I want to supply to my customer. Is there any default folder to put them inside my distribution? e.g. docs, lib, bin...etc. Where is usually the keystore put on the server and where is usually truststore put on the client?

Thanks

dpr
  • 10,591
  • 3
  • 41
  • 71
yura
  • 563
  • 1
  • 4
  • 4

2 Answers2

47

In Java, according to the JSSE Reference Guide, there is no default for the keystore, the default for the truststore is "jssecacerts, if it exists. Otherwise, cacerts".

A few applications use ~/.keystore as a default keystore, but this is not without problems (mainly because you might not want all the application run by the user to use that trust store).

I'd suggest using application-specific values that you bundle with your application instead, it would tend to be more applicable in general.

mthomas
  • 624
  • 2
  • 9
  • 20
Bruno
  • 119,590
  • 31
  • 270
  • 376
  • 3
    Keystore and Truststore are general PKI terminology and not specific to Java. – user93353 Dec 01 '12 at 15:00
  • @user93353, it varies depending on the implementation. PKI talks about trust in various ways, but that can be "trust store", "trust anchors" or simply "trusted certificates". On Windows/schannel, you also get the "Trusted Root Certification Authorities store" and so on. AFAIK, there's no uniform terminology. – Bruno Dec 01 '12 at 15:10
  • 38
    More specifically, the default locations are /lib/security/jssecacerts and /lib/security/cacerts and you override it with the javax.net.ssl.trustStore system property. – Eric Mar 20 '13 at 21:40
  • One example, if one uses command "keytool" without provide -keystore , keytool will writes to ~/.keystore as default – dreadlock Feb 27 '21 at 12:35
15

Like bruno said, you're better configuring it yourself. Here's how I do it. Start by creating a properties file (/etc/myapp/config.properties).

javax.net.ssl.keyStore = /etc/myapp/keyStore
javax.net.ssl.keyStorePassword = 123456

Then load the properties to your environment from your code. This makes your application configurable.

FileInputStream propFile = new FileInputStream("/etc/myapp/config.properties");
Properties p = new Properties(System.getProperties());
p.load(propFile);
System.setProperties(p);
Kristian Benoit
  • 612
  • 5
  • 16
  • 2
    HI Kristian Benoit - Your answer seem to be logical - can you please elaborate your answer details - or refer a blog link ... for complete tutorial. Sry I am a bit new to keystore, would appreciate your efforts – Abdeali Chandanwala Apr 16 '17 at 13:12