0

I'm reading xml text from an https link which if I open in a browser asks to verify for the certificate.

URL oracle = new URL(url); //url is a String
URLConnection yc = oracle.openConnection();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(yc.getInputStream()));

I'm getting an IOException in the 3rd line in the inputReader. I've tried the same code on a simple http link that doesn't require certification approval and works just fine. Do you know what I should change?

Thanks

Vicky
  • 1

1 Answers1

0

You have not include the trace of the exception but surely the SSL server is refusing the connection because you are not authenticating with certificate.

You need to create a https connection using a client certificate configured on your JVM. This is called Two-Way SSL Authentication (check this tutorial)

You need

1) Create a keystore (PKCS12 or JKS) and include the private key of the client certificate

2) Create a trustore (could be the same file) and include the public key of the server certificate

3) Configure your JVM to use the keystore and truststore in SSL connections to that server.

-Djavax.net.ssl.keyStoreType=pkcs12
-Djavax.net.ssl.keyStore=client.p12
-Djavax.net.ssl.keyStorePassword=whatever
-Djavax.net.ssl.trustStoreType=jks
-Djavax.net.ssl.trustStore=client-truststore.jks
-Djavax.net.ssl.trustStorePassword=whatever

Check a full example https://stackoverflow.com/a/1710543/6371459

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142