Home > Java > javaTutorial > How to Configure Java HTTPS Client Certificate Authentication?

How to Configure Java HTTPS Client Certificate Authentication?

Mary-Kate Olsen
Release: 2024-12-22 19:20:15
Original
338 people have browsed it

How to Configure Java HTTPS Client Certificate Authentication?

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:

  1. Client's public certificate
  2. Client's private key

Example command to generate the keystore:

openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12 -name "Whatever"
Copy after login

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
Copy after login

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:

  1. Client certificate authentication is server-enforced.
  2. The client certificate must be signed by a CA trusted by the server.
  3. Use a packet analyzer like Wireshark for debugging and analysis.

Using Apache HttpClient

To use HttpClient for HTTPS with client authentication:

  1. Replace the URL with its HTTPS equivalent.
  2. Add the following JVM arguments:
-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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template