GlassFish connecting to SLL web service - java

I have a web app running on GlassFish v3 locally. The app connects to a REST web service that is on another server (not local). The connection is done through HTTPS. While trying to connect I get:
javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
I added the cert from the external ws directory to the local java keystore but that did not fix the problem.
Do I have to instruct GlassF to use the local keystore or something ? Or just by adding it to the java keystore it should work for the local GlassF too ?

You have two options:
1.) Replace the cacerts in the $JAVA_HOME/jre/lib/security directory with your keystore.
2.) Change the keystore at runtime like this:
System.setProperty("javax.net.ssl.keyStore", <path to the new keystore>);
System.setProperty("javax.net.ssl.keyStorePassword",<password of the keystore>);
System.setProperty("javax.net.ssl.trustStore",<path to the new keystore>);
Hope that helps!
EDIT: You might find this question helpful as well. The selected answer suggests to:
1.) Copy your keystore file to C:\glassfish3\glassfish\domains\domain1\config\
2.) Configure GlassFish to use SSL

Related

SunCertPathBuilderException; JAVA_OPTS with keystore required?

When connecting via a java API service to a remote server by https I got the following exception
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
The server is a Windows Server 2012 which has the corresponding wildcard certificate installed as root certificate too.
I've used keytool to import that exact same certificate to the keystore called cacerts, so the jvm is using it to prevent the exception above.
As keytool shows, the certificate is installed correctly but the handshake exception still occurs when connecting to the server.
I've checked the windows environment variables on the server and found out that the JAVA_OPTS is missing.
Even tried restarting the entire server but this did not help either.
In order to get it work, do I need to add the environment variable manually referencing the keystore as shown below?
-Djavax.net.ssl.trustStore=C:\path\to\cacerts
I was able to fix this issue by adding the certificate to the java applications keystore too.

How to deploy my code to App Engine behind proxy

I am using Eclipse Neon 6.4.3 and i am trying to deploy my project to App Engine using the Google Cloud Platform plugin for Eclipse. https://cloud.google.com/eclipse/docs/quickstart
Until the 1st of April i could deploy projects using this plugin. But after that date, i get the following error:
Failed to retrieve projects; An error occurred while retrieving projects:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuiderException: unable to find valid certification path to requested target.
Reason: Failed to retrieve projects.
Details: Failed to retrieve projects
javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
After I press OK, I get the same message again. Then I get the "Deploy to App Engine Standard" menu with my account but my project list is blank.
I am working in a company that uses proxies and it's doing a SSL Inspection. I imported these 2 certificates used for SSL Inspection in my Eclipse cacerts file but i get the same error. These two certificates are issued by our internal certificate authority.
I wanted to add this as a comment, but still don't have enough points:
Are you using maven or appcfg? Have you tried using appcfg with --proxy argument?
From Deploying a Java app documentation:
If you are using an HTTP proxy, include the --proxy argument to tell appcfg its address. If you use a different proxy for HTTPS, then also include the --proxy_https argument.
The current certificate for the URL used to retrieve the projects https://cloudresourcemanager.googleapis.com/ was issued on April 5 2017, this may be the reason for the error. If you open that url and check the certificate you can verify whether it's signing CA is in the truststore you use, or you need to add either the CA or the certificate itself to your truststore.

PKIX path building failed in Java application, for self-signed SSL certificate

I created a pair of SSL certificates using OpenSSL, self-signed, to secure the HTTPS connection for a JBoss application.
When I ran the application and tried to get access by HTTPS, it did not show the site and threw an error in my console:
PKIX path building failed in Java application
I know that I should import some certs into Java, like what they said:
The long story short here is to run java InstallCert server:1234 to
generate a file called jssecacerts. Then, drop this file in
${JAVA_HOME}/lib/security directory.
What I do not understand:
1.in fact I try to get access to host B from host A, using HTTPS, why should I add the certificate of my own host to Java, not the client one?
2.using this method, there is nothing to do with my actual certificates (I mean .key and .crt), is that normal?
you need to enter your certificate inside java cacert file
This link demonstrate it the best.
Step 1 : Download certificate
Step 2 : store inside cacert
That is it! your problem resolved.

SOAP Web service need to send request using https protocol in java

I need to send request to my web service using https protocol.
Using SOAP UI it's working fine and providing response for https request as well however if i am sending https request it's providing below exception
javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://abc:8443/xyz/FileTransferService?wsdl. It failed with:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:184)
at ##com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:166)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:131)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:267)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1497)
If you want to use https, you just download the wsdl first, and make the wsdlLocation and url in your generated client class point to that file.
or generate your client like this
URL url = new URL("https://......?wsdl");
QName qname = new QName("NameSpace of the Service", "ServiceName");
Service service = Service.create(url, qname);
ServiceClass port= service.getPort(ServiceClass.class);
then you could can start to use the port.
You can find the example of later one in the website.
http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/
Oh, I forgot one thing. You have to add trust key in your java keystore. The following website shows the way to do it.
http://java.globinch.com/enterprise-java/security/pkix-path-building-failed-validation-sun-security-validatorexception/
I know it is a quite old question but maybe an answer is never bad.
Normally this happens when the JVM cacerts file does not contains the root CA's certificate who signed your server SSL certificate. But be careful which JVM is running so which cacerts file you should edit. You can find the cacerts file under $JAVA_HOME/jre/lib/security/
If you are using glassfish 3 you should edit the cacerts.jks file under your specific domain config directory and not in the common JVM runtime folder.
Probably you have switched off the SSL certificate check in your SOAP UI.

org.apache.axis2.AxisFault: sun.security.validator.ValidatorException:

org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I am getting the baove exception, i know it is because it is not able to find the certificates.
when i created a new JKS file with only the certificate enteries provided by the 3rd party and setting in system.setProperty("javax.net.XXXX") it works.
But due to this my other functionalities in application does not work as it is not able to find any certificate.
so i created jssecacerts using class file and imported the two certificates as well, but pointing and setting in system properties this jssecaerts file, it does not work and rest everything works fine.
What could be the issue..???
You could add your additional certificates for use by Axis2 in your own X509TrustManager and build an SSLContext from it. This is described in this answer.
Then you would have to pass the subsequent SSLSocketFactory to Axis2 using an Apache HttpClient 3.x SecureProtocolSocketFactory (see the Axis 2 documentation on the subject).

Categories