how to provide client certificate with https POST
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jignesh_Mehta
Posted On:   Tuesday, October 30, 2001 07:42 PM


I have to send a "POST" request to a secured server using https from my java code. for access to the server i need to pass my client certificate. how can i send my certificate in my code. i have this certificate installed in my browser, and I am able to connect to that server from the browser.


thanks in advance

jignesh

Re: how to provide client certificate with https POST

Posted By:   Eugene_Kuleshov  
Posted On:   Wednesday, October 31, 2001 07:43 AM

You have to init X509KeyManager used by SSLSockedFactory.


char[] passphrase = "passphrase".toCharArray();

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("testkeys"), passphrase);

KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, passphrase);

SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), null, null);

SSLSocketFactory factory = ctx.getSocketFactory();
SSLSocket socket = (SSLSocket)factory.createSocket(host, port);


Unfortunately because SSLSockedFactory called from the within https handler you have to specify own SSLSockedFactory provider by using following:


Security.setProperty( "ssl.SocketFactory.provider", "DummySSLSocketFactory");


You may find and example of DummySSLSocketFactory in here (you have to add that code above to init internal SSLContext).
About | Sitemap | Contact