Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1529

How to bypass SSL handshake for SSLContext?

$
0
0

I am modifying a test which previously used a HTTP call to an external api. There is a new endpoint which now uses HTTPS and so I am trying to modify the test to be able to work with this.

The issue im facing is that I'm getting a handshake error when trying to run the test.

the base boilerplate is:

@Testpublic void testApi() throws Exception {  MockWebServer mockWebServer = new MockWebServer();    // Begin new code    SSLContext sslContext = SSLContext.getInstance("TLS");    sslContext.init(null, null, null);    SSLSocketFactory socketFactory = sslContext.getSocketFactory();    mockWebServer.useHttps(socketFactory, false);    // End new code    mockWebServer.enqueue(new MockResponse().setBody("{}").setHeader("Content-Type", "application/json"));    mockWebServer.play();    FooCaller fooCaller = new FooCaller();    fooCaller.postRequest("jsonString");    RecordedRequest request = mockWebServer.takeRequest();//Assertions on request...}

Unfortunately I don't have access to create a local certificate or key/truststore so I can't initialise the SSL context's KeyStoreManager and TrustStoreManager with anything other than null. Is there a way to bypass this handshake or to bypass the authentication?

(notes:

  1. I'm using com.google.mockwebserver not the newer okhttp version
  2. the code that inside the // Begin new code - End new code comments is the only new code and the test was working with the http call before switching to https)

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>