Cannot get requests with certificate to work
See original GitHub issueHello. I have certain endpoints in the apis which are secured with a p12 certificate. I cannot get those tests to run anymore.
Here is my setup . Each test class extends a BaseApiTest in which I have this :
@BeforeClass
public void setUpCaseFlow() throws Exception
{
RestAssured.useRelaxedHTTPSValidation("TLSv1.2");
RestAssured.trustStore("resources/vlm.jks", "changeit");
RestAssured.config().getSSLConfig().with().keyStore("D:\\Development_Repos_ToServeTest\\vlm_systemtest\\src\\stest\\resources\\backend_client.p12","changeit");
//RestAssured.keyStore("/resources/backend_client.p12" ,"changeit");
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
My p12 certificate is found in the /src/stest/resources. In the tests for which I have secured endpoints I do this
@Test(priority = 2)
public void getPackageDescriptors() throws Exception
{
String backendClientCertificate = "backend_client.p12";
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File file = new File(classLoader.getResource(backendClientCertificate).getFile());
packageDescriptorEbri = given().spec(reqSpecWithCertificate).auth().certificate(file.getName(), "changeit",
new CertificateAuthSettings().
trustStoreType("PKCS12")).
when().get(ENDPOINT + firstPackageName + "/" + VERSION).then().statusCode(200).extract().path("ebri");
The exception I get is this :
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(Unknown Source) at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) at sun.security.ssl.Handshaker.processLoop(Unknown Source) at sun.security.ssl.Handshaker.process_record(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:573) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:557) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
Any ideas about this ? I tried almost everything suggested on the web and did not workout for me
Issue Analytics
- State:
- Created 6 years ago
- Comments:12
Top GitHub Comments
found the solution . before each test class use this . works without any other hacks
Someone could explain me how did you add the certificates?