grails / grails-data-mapping

GORM - Groovy Object Mapping
http://gorm.grails.org/
217 stars 198 forks source link

ignoreSSLIssues function in grails RestBuilder #1023

Open saqib-ahmed opened 6 years ago

saqib-ahmed commented 6 years ago

Task List

Steps to Reproduce

  1. Clone the example application.
  2. Start the project by executing grails run-app or gradle bootRun.
  3. Call http://localhost:8080/demo/index

Expected Behaviour

There should be a utility function to ignore any sort of SSL issues like there is for HTTPBuilder. I trust the server and I want to bypass any SSL checks. So the request should get through. I don't want to add a certificate in the jre keytools as well.

Actual Behaviour

The request throws an exception for the incorrect certificate. The stack trace follows:

Stacktrace

ERROR org.grails.web.errors.GrailsExceptionResolver - SunCertPathBuilderException occurred when processing request: [GET] /demo/index
unable to find valid certification path to requested target. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
    at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
    at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
    at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
    at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
    at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://self-signed.badssl.com/": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is 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 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:633)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:588)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:507)
    at grails.plugins.rest.client.RestBuilder.invokeRestTemplate(RestBuilder.groovy:310)
    at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:274)
    at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:262)
    at grails.plugins.rest.client.RestBuilder.get(RestBuilder.groovy:107)
    at sslisuedemo.DemoController.index(DemoController.groovy:9)
    ... 14 common frames omitted
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 org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:619)
    ... 21 common frames omitted
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    ... 25 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
    ... 25 common frames omitted

Environment Information

Example Application

Example application is given at https://github.com/saqibahmed515/sslIssueDemo.

minhajkk commented 5 years ago

Were you able to find a workaround for this?

saqib-ahmed commented 5 years ago

I had to use HTTP Builder for HTTPS connections. Couldn't find anything in this plugin.