I understand that the keystore would usually hold private/public keys and the trust store only public keys (and represents the list of trusted parties you intend to communic
To explain in common usecase/purpose or layman way:
TrustStore : As the name indicates, its normally used to store the certificates of trusted entities. A process can maintain a store of certificates of all its trusted parties which it trusts.
keyStore : Used to store the server keys (both public and private) along with signed cert.
During the SSL handshake,
A client tries to access https://
And thus, Server responds by providing a SSL certificate (which is stored in its keyStore)
Now, the client receives the SSL certificate and verifies it via trustStore (i.e the client's trustStore already has pre-defined set of certificates which it trusts.). Its like : Can I trust this server ? Is this the same server whom I am trying to talk to ? No middle man attacks ?
Once, the client verifies that it is talking to server which it trusts, then SSL communication can happen over a shared secret key.
Note : I am not talking here anything about client authentication on server side. If a server wants to do a client authentication too, then the server also maintains a trustStore to verify client.
There is no difference between keystore and truststore files. Both are files in the proprietary JKS file format. The distinction is in the use: To the best of my knowledge, Java will only use the store that is referenced by the -Djavax.net.ssl.trustStore
system property to look for certificates to trust when creating SSL connections. Same for keys and -Djavax.net.ssl.keyStore
. But in theory it's fine to use one and the same file for trust- and keystores.
These are the steps to create a Truststore in your local machine using Keytool. Steps to create truststore for a URL in your local machine.
1) Hit the url in the browser using chrome
2) Check for the "i" icon to the left of the url in the chrome and click it
3) Check for certificate option and click it and a Dialog box will open
4) check the "certificate path" tab for the number of certificates available to create the truststore
5) Go the "details" tab -> click"Copy to File" -> Give the path and the name for the certificate
you want to create.
6) Check if it has parent certificates and follow the point "5".
7) After all the certificates are being create open Command Prompt and navigate to the path where you created the certificates.
8) provide the below Keytool command to add the certificates and create a truststore.
Sample:
keytool -import -alias abcdefg -file abcdefg.cer -keystore cacerts
where "abcdefg" is the alias name and "abcdefg.cer" is the actual certificate name and "cacerts" is the truststore name
9) Provide the keytool command for all the certificates and add them to the trust store.
keytool -list -v -keystore cacerts
The terminology is a bit confusing indeed, but both javax.net.ssl.keyStore
and javax.net.ssl.trustStore
are used to specify which keystores to use, for two different purposes. Keystores come in various formats and are not even necessarily files (see this question), and keytool
is just a tool to perform various operations on them (import/export/list/...).
The javax.net.ssl.keyStore
and javax.net.ssl.trustStore
parameters are the default parameters used to build KeyManager
s and TrustManager
s (respectively), then used to build an SSLContext
which essentially contains the SSL/TLS settings to use when making an SSL/TLS connection via an SSLSocketFactory
or an SSLEngine
. These system properties are just where the default values come from, which is then used by SSLContext.getDefault()
, itself used by SSLSocketFactory.getDefault()
for example. (All of this can be customized via the API in a number of places, if you don't want to use the default values and that specific SSLContext
s for a given purpose.)
The difference between the KeyManager
and TrustManager
(and thus between javax.net.ssl.keyStore
and javax.net.ssl.trustStore
) is as follows (quoted from the JSSE ref guide):
TrustManager: Determines whether the remote authentication credentials (and thus the connection) should be trusted.
KeyManager: Determines which authentication credentials to send to the remote host.
(Other parameters are available and their default values are described in the JSSE ref guide. Note that while there is a default value for the trust store, there isn't one for the key store.)
Essentially, the keystore in javax.net.ssl.keyStore
is meant to contain your private keys and certificates, whereas the javax.net.ssl.trustStore
is meant to contain the CA certificates you're willing to trust when a remote party presents its certificate. In some cases, they can be one and the same store, although it's often better practice to use distinct stores (especially when they're file-based).
keystore simply stores private keys, wheras truststore stores public keys. You will want to generate a java certificate for SSL communication. You can use a keygen command in windows, this will probably be the most easy solution.
In simplest terms :
Keystore is used to store your credential (server or client) while truststore is used to store others credential (Certificates from CA).
Keystore is needed when you are setting up server side on SSL, it is used to store server's identity certificate, which server will present to a client on the connection while trust store setup on client side must contain to make the connection work. If you browser to connect to any website over SSL it verifies certificate presented by server against its truststore.