question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot get requests with certificate to work

See original GitHub issue

Hello. 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:closed
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
BogdanJelerROcommented, Feb 8, 2018

found the solution . before each test class use this . works without any other hacks

RestAssured.config = RestAssured.config().sslConfig(SSLConfig.sslConfig()
                                                                    .trustStore(this.getClass().getResource(trustStore).getFile(), trustStorePassword).trustStoreType("JKS")
                                                                    .keyStore(this.getClass().getResource(keyStore).getFile(), keyStorePassword).keystoreType("PKCS12"));
0reactions
lauragarzongcommented, Jun 2, 2022

Someone could explain me how did you add the certificates?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to get local issuer certificate when using requests in ...
Hello, it looks like Python uses certifi module for SSL communications. This certifi module uses cacert.pem file to validate against the SSL ...
Read more >
Solve the dreadful certificate issues in Python requests module
Recently I have been working with the Python requests module to secure an API call using the server's certificate.
Read more >
Can connect to URL with curl but not with requests (i.e. ...
I have already tried a number of things, like trying to use the system CA bundle: export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt ...
Read more >
SSL Certificate Verification - Python requests - GeeksforGeeks
Requests verifies SSL certificates for HTTPS requests, just like a web browser. SSL Certificates are small data files that digitally bind a ...
Read more >
Advanced Usage — Requests 2.28.1 documentation
Whenever a call is made to requests.get() and friends, you are doing two major ... You can also specify a local cert to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found