Amazon: SSLHandshakeException happening intermittently - java

This is a difficult problem for me. The following shows the portion of the code that throws the exception when I try doing an Amazon search:
AWSECommerceServiceLocator locator = new AWSECommerceServiceLocator(fooConfig);
locator.setAWSECommerceServicePortEndpointAddress(SourceCountry.USA.getPortAddress());
//throws exception
AWSECommerceServicePortType type = locator.getAWSECommerceServicePort();
Heres the exception:
NativeException: bc.exceptions.FatalException:
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
The weird thing is that this happens intermittently. At times, everything works perfectly. Anybody have any ideas? At this point, any help is greatly appreciated.
Thanks.

There could be several root causes:
Outdated java installation which doesn't contain a valid root certificate for some of the Amazon servers
Invalid server-side certificate that is not trusted by any valid issuer
To debug to the console from the client side, add -Djavax.net.debug=all to the command line. The page on Debugging SSL/TLS connections may provide insight into the underlying error.

Related

How to fix "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException"

I'm trying to hit an API from AWS EC2 and I'm getting Exception
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException
But when I hit the same API on browser it works fine without giving any kind of warning.
API is:
https://idgenvip.qa.ch3.s.com/IDGen/services/id/generate?idType=GIFT_REGISTRY_ID
I asked one of the guy in infra, he told me it's not certificate related issue.
I have tried putting all the certs present in the server in which this API is working fine to my AWS EC2 instance, but still getting the same error.
EDIT:
I've tried to ping on the idgenvip.qa.ch3.s.com and it's getting 0% packet loss.
Please help to resolve this issue.. Help of any kind would be appreciated.

HTTPS vs HTTP in java

We got an wsdl from a website and we generated the java code with Axis2. Works perfect but the site is HTTPS and has the SSL certificatite turned off.
When I make a request I get
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
The admin from the site told me to disable SSL
I can't seem to find a solution for this.
What do I need to call before the request to disable this?

Automaticly resolve Java SSL errors? - Unable to find valid certification path to requested target

I'm trying to put together a simple web crawler using the jsoup library.
However when calling "Jsoup.connect(url).get()" On some sites I'm getting the error below.
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
There are a number of other questions about this error, but all of them suggest resolving it by manually creating a cert for the site in question. Since I'm trying to do a web crawler that will connect to many sites, that's not really a solution.
Is there a recommended way to resolve this? For a simple web crawler security is not particularly a concern, so the authenticity of the cert does not matter.
Solution I'm using for now, Option 2 mentioned in a related question here. Accept server's self-signed ssl certificate in Java client
You should ignore TSL validation, set validateTLSCertificates(false):
Document document = Jsoup.connect(url).timeout(10000).validateTLSCertificates(false).get();

Facebook graph API /me/permissions?access_token=XYZ returns 500 response with error - unable to find valid certification path to requested target

My application validates user permissions based on the the access token and I am hitting - https://graph.facebook.com/me/permissions?access_token=XYZ URL with a valid token.
Things were working fine, however recently it has started breaking. HTTP GET on the mentioned URL returns 500 response with an error -
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
There are no changes on the code front.
Moreover,
The mentioned URL with a valid token works fine when I hit it in the browser. But in code it does not work.
Also when I run the application on my laptop this all works fine. But it fails with the mentioned error on the production.
Not sure what's going on .. Can anyone please help me in this ?
Thanks in advance.

Ignore certification authentication on Axis client for WCF service

I created an axis client to WCF service (the client was generated by Eclipse, using the WSDL as an input).
The client works fine when using HTTP.
When using HTTPS I'm getting the following exception:
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 understand the error, but I don't want to give it a place where the certificates are located.
I want to tell Axis to avoid this step (accept any certificate without checking it).
I know how to do it with HttpsURLConnection (create a custom validator which does nothing), but I don't know how to do it with axis... (How can I tell axis to use my custom validator, or better, how can I tell it to ignore this step at all).
Can someone help me?
Thanks,
Mattan
I had the same problem and fixed it using:
AxisProperties.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
In case this doesn't work, have a look here.

Categories

Resources