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:

  1. public certificate
  2. private key
  3. 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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -