Link to home
Start Free TrialLog in
Avatar of NishantKashyap
NishantKashyap

asked on

SSL + rest assured

I have to make a GET request in my rest assured framework to a path using SSL certificate, I am following this wiki https://github.com/jayway/rest-assured/wiki/Usage#ssl-config

generated my keystore jks file and used in my code like

given().keystore(jksfilePath, password).spec(requestSpec.getRequestSpec()).when().get(urlPath);

Open in new window


I got this below error:-

groovy.lang.MissingMethodException: No signature of method: com.jayway.restassured.internal.http.AuthConfig.certificate() is applicable for argument types: (java.io.File, java.lang.String, java.lang.String, java.lang.Integer, null, org.apache.http.conn.ssl.AllowAllHostnameVerifier, null) values: [<my jks file path>,<password> jks, -1, ...]
Possible solutions: certificate(java.lang.String, java.lang.String, java.lang.String, int, java.security.KeyStore, org.apache.http.conn.ssl.X509HostnameVerifier, org.apache.http.conn.ssl.SSLSocketFactory)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
      at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      at com.jayway.restassured.authentication.CertAuthScheme.authenticate(CertAuthScheme.groovy:35)
      at com.jayway.restassured.authentication.AuthenticationScheme$authenticate.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1091)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccesso
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why don't you just import the cert into your existing cacerts? In theory, you shouldn't have to do anything after doing that
Avatar of NishantKashyap
NishantKashyap

ASKER

I imported that cert in existing cacerts , and then made a GET call using rest assured , but there was a handshake failure. Moreover , I cant use this approach while running tests on a remote agent.
Well if there was a handshake failure, that would probably be for different reasons. Try running the app with the following JVM param set and post the trace here

-Djava.net.debug=ssl

Open in new window

I used this command to run my test
gradle test --tests *SampleTest -Djava.net.debug=ssl


Log trace :- file attached


Please let me know if I am missing something.
logtrace
I am able to make a request to https://google.com/ by using this :

given().config(RestAssured.config().sslConfig(sslConfig().relaxedHTTPSValidation("TLS"))).when().get(urlPath);

Open in new window


  , which has a similar certificate as my website except that "No certificate transparency information was supplied by the server" message in my certificate.
when I am trying to access that website through POSTMAN , a simple GET would return me the result without any other settings

and the same thing with java code throws - javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

given().when().get(urlPath);

Open in new window

I did add the certificate under existing cacerts
 gradle test --tests *SampleTest -Djava.net.debug=ssl

Open in new window

didn't work. Try

 gradle -Djava.net.debug=ssl test --tests *SampleTest

Open in new window

same log trace with above command as well

Snippet:-

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
      at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
      at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:535)
      at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:403)
      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
      at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
      at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
      at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
No. That's not it. This is the sort of thing you should be getting (in addition to your stack trace)
Incidentally, you will note that i have a similar exception so you should be able to produce an almost identical log
ssl-me.log
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
messaged you the log file
Issue got fixed ... I updated to java 1.8 from 1.7  , thanks for pointing the debug option
debug helped me to find the root cause and resolve the issue
:)