We are going to have a Java Key Store which will store certificates & public/private keys. This keystore will be protected with the password. However, access to the keystore is only from the program. There is no way of providing input as it is only based on api access.

What is best place to store the Java keystore password & in what format it should be stored?


If you hope to keep the private keys out of the hands of whoever runs your program, then it will not work. Secrets embedded in code do not resist reverse engineering (especially when using Java, which is quite easy to reverse-engineer).

Though you do not give any detail about your situation (you just say "Java" and "the program"), I can give the following generic advice: arrange for your private key to be user-specific, and such that it is the user's best interest that the private key remains private. In that case, the user will collaborate to the key security. You may then store the private key (or a password which unlocks the private key) in the Java preferences.

  • actually there is no user specific keys, its data specific. In my situation, the keystore is storing the keys which can encrypt/decrypt the data & user accessibility to the method that read from this keystore & the data is only after proper authentication. That is why I said the access is with program. – Deepesh M Feb 18 '13 at 3:41

This is a really good question and I would like to see more good answers. Here are the ones that I am aware of:

  1. Hardcode the password(s) in the application.
  2. Keep the password(s) in a file.
  3. Store the password in an external system and retrieve it at startup.

Of these the first is the most common and often the password is 'password' or 'changeit' etc. The second option might seem better at first glance but it's hard to explain how exactly. The last option is probably the only one that has a hope of doing anything meaningful. I know of vendor solutions that do this kind of thing and claim to improve security.

The fundamental issue here is that if an attacker is on the host with enough access to see the application space, there's really nothing you can do to keep them from getting this password. At some point it must be in memory in the clear.

As I see it, the password on the keystore protects it mainly in situation that the keystore itself has been retrieved from the machine without actually having access to that machine directly. With that file, an attacker can hammer it at will to get the secrets out of it. If you don't have a strong password on it, game over. If the attacker can pull that file, then they likely can pull other files that the password could be stored in. This puts options 1 and 2 in doubt.

As far as the 3rd option goes, the problem now moves to how you authenticate the clients in order to retrieve the password. I know there are a number of schemes for doing this such as depending on the host/network and using signatures on the binaries. You could have an entire discussion just on how to do this and what level of protection it brings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.