What's the difference between a keystore and a truststore?
相关问题
- Export CngKey in PKCS8 with encryption c#
- Export PublicKey and PrivateKey from PKCS12 file
- Could not transfer artifact from/to central becaus
- Android, Multiple Apps, Multiple Customers, One Ke
- How to mock keystore class and assign mock behavio
相关文章
- Recursively change system property at runtime in j
- Get public Key from imported certificate in Keysto
- Generating a BKS keystore and storing app key
- Keystore and Aliases - is there a use to multiple
- Using two private keys (keystore) and two public k
- Seckey from public key string from server in Swift
- Android KeyStore Initialization
- Storing a hmac key in Android keystore
Here's the description from the Java docs at Java Secure Socket Extension (JSSE) Reference Guide. I don't think it tells you anything different from what others have said. But it does provide the official reference.
A keystore contains private keys, and the certificates with their corresponding public keys.
A truststore contains certificates from other parties that you expect to communicate with, or from Certificate Authorities that you trust to identify other parties.
In a SSL handshake the purpose of trustStore is to verify credentials and the purpose of keyStore is to provide credential.
keyStore
keyStore in Java stores private key and certificates corresponding to their public keys and require if you are SSL Server or SSL requires client authentication.
TrustStore
TrustStore stores certificates from third party, your Java application communicate or certificates signed by CA(certificate authorities like Verisign, Thawte, Geotrust or GoDaddy) which can be used to identify third party.
TrustManager
TrustManager determines whether remote connection should be trusted or not i.e. whether remote party is who it claims to and KeyManager decides which authentication credentials should be sent to the remote host for authentication during SSL handshake.
If you are an SSL Server you will use private key during key exchange algorithm and send certificates corresponding to your public keys to client, this certificate is acquired from keyStore. On SSL client side, if its written in Java, it will use certificates stored in trustStore to verify identity of Server. SSL certificates are most commonly comes as .cer file which is added into keyStore or trustStore by using any key management utility e.g. keytool.
Source: http://javarevisited.blogspot.ch
First and major difference between trustStore and keyStore is that trustStore is used by TrustManager to determine whether remote connection should be trusted, keyStore is used from KeyManager deciding which authentication credentials should be sent to the remote host for authentication during SSL handshake.
Another difference is that keyStore theoretically contains private keys required only if you are running a Server in SSL connection or you have enabled client authentication on server side and on the other hand trustStore stores public key or certificates from CA (Certificate Authorities) which are used to trust remote party or SSL connection.
In fact you can store in the same file both private and public keys, given that the the tool to manage those file is the same (keytool), so you could use a single file for both the purposes, but you probably should not.
At least on my Mac OSX the default keyStore is
${user.home}/.keystore
, and the default trustStore is/System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts
.If you want to override them you should add the JVM parameters
-Djavax.net.ssl.keyStore /path/to/keyStore
or-Djavax.net.ssl.trustStore /path/to/trustStore
. You might also need to set the keyStore password in case ofjava.security.UnrecoverableKeyException: Password must not be null
, using the parameter-Djavax.net.ssl.trustStorePassword=password
or-Djavax.net.ssl.trustStorePassword=password
Main Source:
A keystore contains private keys. You only need this if you are a server, or if the server requires client authentication.
A truststore contains CA certificates to trust. If your server’s certificate is signed by a recognized CA, the default truststore that ships with the JRE will already trust it (because it already trusts trustworthy CAs), so you don’t need to build your own, or to add anything to the one from the JRE.
Source
You may also be interested in the write-up from Sun, as part of the standard JSSE documentation:
http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#Stores
Typically, the trust store is used to store only public keys, for verification purposes, such as with X.509 authentication. For manageability purposes, it's quite common for admins or developers to simply conflate the two into a single store.