Java HTTPS Client Certificate Authentication
When authenticating with server certificates, Java clients must present the following credentials:
Client Keystore
The client keystore, in PKCS#12 format, contains the following:
Example command to generate the keystore:
openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12 -name "Whatever"
Client Truststore
The client truststore, in JKS format, contains the root or intermediate CA certificates that determine the trusted endpoints.
Example command to generate the truststore:
keytool -genkey -dname "cn=CLIENT" -alias truststorekey -keyalg RSA -keystore ./client-truststore.jks -keypass whatever -storepass whatever keytool -import -keystore ./client-truststore.jks -file myca.crt -alias myca
Authentication Process
When the server requests client authentication during the TLS handshake, it provides a list of trusted CAs. If the client certificate is signed by one of these CAs, it will be presented for authentication.
Additional Considerations:
Using Apache HttpClient
To use HttpClient for HTTPS with client authentication:
-Djavax.net.debug=ssl -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStore=client.p12 -Djavax.net.ssl.keyStorePassword=whatever -Djavax.net.ssl.trustStoreType=jks -Djavax.net.ssl.trustStore=client-truststore.jks -Djavax.net.ssl.trustStorePassword=whatever
The above is the detailed content of How to Configure Java HTTPS Client Certificate Authentication?. For more information, please follow other related articles on the PHP Chinese website!