hmpatel / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Setting keystore doesn't work #398

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I supply the keystore file but it doesn't work.. I also made a liitle java 
program to see if the keystore works at all.

openssl s_client -connect https://unity-unl-acc.powerhouse.local -starttls ssl 
> essent.cer

System.setProperty("javax.net.ssl.trustStore","/path/to/myKeystore");
System.setProperty("javax.net.ssl.trustStorePassword","password");

URL url = new URL("https://url.local");
URLConnection con = url.openConnection();
Reader reader = new InputStreamReader(con.getInputStream());
while (true) {
    int ch = reader.read();
    if (ch == -1) {
        break;
    }
    System.out.print((char) ch);
}

Gives expected output. (without keystore it does NOT)

My rest assured test look like this:

RestAssured.baseURI = getData().getUrl();
RestAssured.requestSpecification = new 
RequestSpecBuilder().log(LogDetail.ALL).setContentType(ContentType.JSON).build()
;
RestAssured.defaultParser = Parser.JSON;

/* Object creation */
Session session = new Session();
session.setGebruikersnaam("test1");
session.setWachtwoord("test1");

char[] password = "changeit".toCharArray();

FileInputStream fIn = new FileInputStream("path/to/myKeystore");
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(fIn, password);

/* Rest call */
Response res = 
given().trustStore(keystore).body(session).post("/rest/session").then().extract(
).response();

and gives the following output:
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:1917)

What can be the cause of this? How to debug/fix this?

Any help is much appreciated! 

Original issue reported on code.google.com by dekleijn...@gmail.com on 28 Apr 2015 at 9:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Anybody looking at these issues ?

Original comment by dekleijn...@gmail.com on 18 May 2015 at 11:00

GoogleCodeExporter commented 9 years ago
Yes I've seen it but I haven't had the time to look into it. I'm working on 
this project on my spare time.

Original comment by johan.ha...@gmail.com on 18 May 2015 at 12:02

GoogleCodeExporter commented 9 years ago
Let me know if I have to provide more details...

Current situation is that I have to use apache http client for some testscript 
instead of Rest Assured.

Original comment by dekleijn...@gmail.com on 24 May 2015 at 7:33

GoogleCodeExporter commented 9 years ago
What does the code look like when you're using HTTP Client?

Original comment by johan.ha...@gmail.com on 26 May 2015 at 9:13

GoogleCodeExporter commented 9 years ago
Herewith the code I'm using with HTTP client

System.setProperty("javax.net.ssl.trustStore", new 
File("src/test/resources/myKeystore").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("localhost/rest/session");

post.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
StringEntity params = new StringEntity("some body");

post.setEntity(params);

HttpResponse response = client.execute(post);
System.out.println("Response Code : " + 
response.getStatusLine().getStatusCode());

Original comment by dekleijn...@gmail.com on 26 May 2015 at 10:01

GoogleCodeExporter commented 9 years ago
I suppose you ought to be able to do this using setParam in HttpClientConfig? 
https://code.google.com/p/rest-assured/wiki/Usage#HTTP_Client_Config

Original comment by johan.ha...@gmail.com on 26 May 2015 at 10:30

GoogleCodeExporter commented 9 years ago
Do you mean this:

RestAssured.config = 
newConfig().httpClient(httpClientConfig().setParam("javax.net.ssl.trustStore", 
new 
File("src/test/resources/myKeystore").getAbsolutePath()).setParam("javax.net.ssl
.trustStorePassword", "changeit"));

Because the code above is not working..

Original comment by dekleijn...@gmail.com on 26 May 2015 at 1:04