I\'m trying to connect to an HTTPS URL, but I need to use client authentication with a certificate placed on my system by third party software.
I haven\'t the slight
From what I remember from my last attempt of doing that, you can't use HttpsURLConnection
. You can have a look to the Apache HttpClient library that has support for this.
Here is a code sample giving an idea of the process:
String server = "example.com";
int port = 443;
EasySSLProtocolSocketFactory psf = new EasySSLProtocolSocketFactory();
InputStream is = readFile("/path/to/certificate");
KeyMaterial km = new KeyMaterial(is, "certpasswd".toCharArray());
easy.setKeyMaterial(km);
Protocol proto = new Protocol("https", (ProtocolSocketFactory) psf, port);
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setHost(server, port, proto);
Edit (regarding Tom comment):
Here are some thoughts on how you can obtain the certificates stored in the Windows key store:
ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
. The JVM will load the Windos keystore and take care of asking for the keystore password.