SSL certificate problem in a web service proxy

萝らか妹 提交于 2019-12-31 02:42:06

问题


I am building a JAVA web service client in which i connect to a service.

This service has a ssl certificate verification.

How to call this service using ssl certificate verification.

I am using JAX-RPC implementation in client built using Eclipse.

An example would be appriciated.


回答1:


I am able to do the web service connection...

I added the key store using the command:

keytool -import -trustcacerts -file <file path/filename.cer> -alias <aliasName> -keystore <JAVA_HOME/jre/lib/security/cacerts> 

gave the password as "changeit" and added the certificate in keystore.

Now in code i added two lines:

System.setProperty("javax.net.ssl.trustStore", "<JAVA_HOME>/jre/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

also added

_call.setUsername("username");
_call.setPassword("password"); 

where _call is the call object of Call Class.

And it worked!!!!!!




回答2:


All you need to do is injecting the server root certificate to your JDK/JRE environments by using the following command line: -

keytool -importcerts -trustcacerts -file <path_to_root_cer_file> -alias <the_server_alias> -keystore <your_keystore>

The default [your_keystore] is

 1. <JDK_HOME>/jre/lib/security/cacerts
 2. <JRE_HOME>/lib/security/cacerts

The default password is changeit.

When you call the web service, just mention the

"https://<host>:<SSL_port>/Path/To/Services"

I hope this may help to achieve your requirement.

Regards,

Charlee Ch.




回答3:


You mean your web service is protected with a "client certificate"? If yes, get the certificate in either a .p12 (PFX) or keystore format from the service provider and use the following System properties to set it before your call:

javax.net.ssl.keyStore - Path to the keystore on your server

javax.net.ssl.keyStorePassword - passphrase for that keystore

javax.net.ssl.keyStoreType - Set it to "pkcs12" is the client certificate provided to you is .p12

If you application is client to only one web service provider, set these properties as VM arguments, if not, you may need to create specific SSLConnectionFactory for each secured endpoint. Refer to my response on this post for details on creating custom SSL Socket Factories.



来源:https://stackoverflow.com/questions/6492122/ssl-certificate-problem-in-a-web-service-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!