First, a brief point of terminology in public key cryptography:
- you sign and decrypt / decrypt using the private key,
- you verify (signature) and encrypt / encrypt using the public key.
(You do not decrypt using the public key.)
Using SSL / TLS with or without client authentication, the server presents a certificate (*) for which it has a private key. The server sends its certificate during the SSL / TLS connection establishment (at the beginning of the connection) and can decrypt what the client sends using its private key (which it keeps confidential). The private key and certificates are stored in the keystore (or equivalent, if it is not implemented in Java).
As part of this, the client uses its trusted network, which is a keystore that contains trusted certificates, to verify the server’s certificate. A server certificate can be trusted if it is explicitly specified in a trusted store or, in most cases, trusted by reference to a trusted CA certificate in a trusted store (PKI).
The terminology between the keystore and truststore in Java can be a bit confusing, you can find more details in this answer .
As for your question, the client power of attorney does not contain the public key of the server, but either its certificate or CA certificate, with which it must be verifiable. (This is not just having a public key, but also knowing it, using other parts of the information in the certificate.)
If you use client certificate authentication in addition to this, there is a trust store (or its equivalent) on the server side and a client-side keystore, because for this purpose the roles are reversed.
In an SSL / TLS confirmation using client authentication, the server requests a certificate from the client that sends it (if available).
At the end of this handshake, the client sends a CertificateVerify
message, which signs all the messages exchanged so far between the client and the server (so this is what both know) using the client’s private key certificate. The server can then verify this signature against the public key in the client certificate that it received as part of this exchange. This proves to the server that the one on the client side has a private key corresponding to the public key in the sent certificate.
The next step for the server is to check whether to trust this certificate, i.e. trust the binding between the identifier and the public key as presented and "sealed" in the certificate. This is usually done using PKI, through which you verify the certificate against a known CA, or if your deployment environment is small enough, against a fixed set of trusted certificates. (There may be alternative verification methods , but their usability will really depend on the conditions in which you want to deploy this system.)
Therefore, for your second question:
- Client client storage should contain at least a client certificate and its private key.
- In the trusted client store, the server certificate or CA certificate must be specified with which you can verify the server certificate.
Since both the keystore and the trust store are the keystore (in terms of the storage format, usually a file) used for another purpose, you can often use the same keystore to serve both the keystore and the trust store.
(*) There are cipher suites that do not rely on certificates, but this is unusual and not relevant to the subject.