Friday, March 14, 2014

Converting HTTP url web service to HTTPS (SSL) web service in Linux - tomcat application

To change the HTTP URL web-service to HTTPS URL.

Our web application was using a HTTP URL for invoking the web-service to fetch values based on the input there was a requirement to change this to HTTPS web-service (HTTP over SSL).

The HTTP web-service client was implemented in Axis 1.0. The web application developed using Spring-Struts framework in Java (1.7) and deployed in tomcat 6.0 hosted in Linux os server.

To implement the HTTPS web-service in the web application the below was followed:

In Linux, we tried to call the HTTPS URL directly using the curl command:

curl <wsdl https url>

we got certificate error stating could not handshake with the remote web-service.

curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). The default bundle is named curl-ca-bundle.crt; you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).

Since we had filtered access to the Linux server we have to validate that the WSDL HTTPS web-service is accessible via Linux. after using

curl -k <wsdl https url> 

we where able to access the wsdl, the option -k masks the handshake.

Obtaining the certificate.
After getting the certificate, in order to generate a keystore and include it the system we have to do the below.

To generate a keystore
1. The certificate (CA authorized)  was .cer file.
           - use java keytool command to create a key store. Example:
            /opt/java1.7/bin/keytool -import -alias <aliasName> -file <CertificateFileName.cer> -keystore <keyStorFileName.keystore>
To include in the tomcat CLASS path
2. include this key store in tomcat JAVA_OPTS path in setenv.bat or in case of Linux setenv.ksh. as
           - Djava.ssl.truststore=<path of the keystore>
3. Stop and Start the application. the HTTPS web-service will work without any issues.

Reference the below link (courtesy
http://javarushi.blogspot.com/2012/07/consuming-secure-web-services-or-web.html 

No comments:

Post a Comment