JAVA : How to make SSL connection with public certificate and private key -
i hoping if regarding issue have been facing today:
i trying authenticate client server of 1 of our clients, able issuing following command:
curl -v -k -h "content-type:application/json" --key privkey.pem --cert pub.cer --data @search.json https://....
as can tell command above have following:
- public certificate
- private key
keystore
now, trying same thing in java, have no clue how done. guides have read tell me should use keystore have. hit roadblocks when following guides.
i or point me direction, appreciate it.
thanks in advance, peter
it sounds need use https url connection connect server requires client authentication. you'll need 2 things there are.
first, you'll need create java style keystore private key , public certificate. detailed instructions can found in answers question:
importing existing x509 certificate , private key in java keystore use in ssl
you'll need import server's certificate keystore.
second, you'll need write java code use newly created keystore. creating sslcontext using keystore, , setting https url connection use socket factory context - along lines of this:
sslcontext sslcontext = sslconnections.getsslcontext(keystorefile, keystorefilepassword); httpsurlconnection.setsslsocketfactory(sslcontext.getsocketfactory());
this should done after httpsurlconnection created, before connected - is, before read or write it, or call connect() on it.
Comments
Post a Comment