Two Way SSL
Please note that the link and screenshot used in this post may be outdated as it was implemented few years back. Please use this for reference purpose only.
In Two Way SSL (mutual authentication) the client verifies the identity of the server, and then the server verifies the credentials of the client. The figure below gives an overview of the Two Way SSL process.
Two Way SSL Flow Diagram
Implementation
Weblogic Version: 10, Glassfish Version 3, OS: Windows
Example below shows how to configure Two Way SSL for client connecting to Weblogic/Glassfish Server. Both servers provide default keystore (database of private keys and certificate) which are complete in themselves for SSL implementation in testing environment. In production environment you should implement your own certificate signed by your own CA.
More information on configuring SSL on Weblogic at: Weblogic SSL
Java provides keytool, a key and certificate management utility. It enables users to administer their own public/private key pairs and associated certificates for use in self-authentication.
keytool stores the keys and certificates in a so-called keystore.
For more information on keytool visit: Keytool Tutorial
Following are the steps to implement Two Way SSL:
- Set the path to use keytool: set the path to your jdk
set path="c:\Program Files\Java\jdk{version}\bin"
-
Configure the servers to enable Two Way SSL
Weblogic
-
Configure the servers to enable Two Way SSL
For Weblogic
Start Weblogic -> Login to console -> Click on Environment -> Servers -> SSL ->Advanced
-
Make sure in Two Way Client Cert behavior option Client Certs Requested and Enforced is selected
Two Way SSL configuration on weblogic
Glassfish
Make sure that client authentication is enabled
Two Way SSL config for glassfish
-
-
To view the information about certificate(s) in default keystore
Weblogic
C:\>keytool -list -v -keystore D:\Oracle\Middleware\wlserver_10.3\server\lib\DemoIdentity.jks
Default Password for DemoIdentity.jks is DemoIdentityKeyStorePassPhrase
Glassfish
C:\>keytool -list -v -keystore "c:\Program Files\glassfish-v3- prelude\glassfish\domains\domain1\config\keystore.jks
Keystore password is masterpassword of domain that is defined by user during domain creation. (For netbeans glassfish the password is “changeit”)
-
Export the certificate in keystore to a file. This certificate file will be imported to client keystore.
Weblogic
C:\>keytool -export -alias demoidentity -file D:\certificates\server.cer –keystore D:\Oracle\Middleware\wlserver_10.3\server\lib\DemoIdentity.jks
Glassfish
C:\> keytool -export -v -alias s1as -file D:\certificates\glasscert.cer –keystore "D:\Program Files\glassfish-v3-prelude-b28c\glassfish\domains\domain1\config\keystore.jks"
-
To print the information about the certificate created
C:\>keytool -printcert -v -file D:\certificates\server.cer
-
To view the information about certificates in the client keystore(Java provides its own truststore which is placed in
C:\Program Files\Java\jdk1.6.0_06\jre\lib\security
directory with name cacertsC:\>keytool -list -v -keystore "C:\Program Files\Java\jdk1.6.0_06\jre\lib\security\cacerts"
-
Import the server certificate into the client cacert
Weblogic
C:\>keytool -import -alias demoidentity -trustcacerts -file D:\certificates\server.cer - keystore "c:\Program Files\Java\jdk1.6.0_06\jre\lib\security\cacerts"
Glassfish
C:\>keytool -import -v -trustcacerts -alias s1as -keystore "C:\Program Files\Jav a\jdk1.6.0_06\jre\lib\security\cacerts" -file D:\certificates\glasscert.cer
-
Import the client certificate into the server cacert
Weblogic
C:\>keytool -import -v -trustcacerts -alias clientalias -keystore D:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks -file D:\certificates\clientcert.cer
Glassfish
keytool -import -v -trustcacerts -alias clientalias -file D:\certificates\clientcert.cer -keystore "D:\Program Files\glassfish-v3-prelude-b28c\glassfish\domains\domain1\config\cacerts.jks"
Additional Information
Note: If you are using self-signed certificate include following property in JAVA_OPTIONS of setDomainEnv of weblogic else weblogic will show Basic CA constraint error and restart the server.
Errors and Solution
Error
If you get the following error while running your client:
Solution
Make sure that certificates are imported correctly on both client and server side. Error signifies that either server hello or client hello was incomplete.
To check for detailed debug information for SSL include the following property during invocation of client
Error
Solution
Error signifies that the client was not able to find a valid certificate keystore path. Include the following properties during client invocation
Error
When Weblogic is acting as client (i.e. when service deployed on weblogic is accessing the service deployed on another server) in Two Way SSL, you may get the following error “No suitable identity certificate chain has been found.”
Solution
Go to SSL tab of your server where application is deployed and enable Use Server Certs
Error
If you get the following error while running your client:
Solution
Include the following code in your codebase
Or For Weblogic goto
Start Weblogic -> Login to console -> Click on Environment -> Servers -> SSL -> Advanced -> Set the Hostname Verification to None
SSL Hostname Verification Weblogic Setting
Client Run