java - Establishing connection to HTTPS using client certificates -
i want upload file https-server using java. server not open url hence need client certificates establish connection. having .pem , .jks , .pkcs12
client certificate files.
can 1 suggest me how use certificate files in application establish communication ? need use 3 certificate files ?
the .jks
file java keystore. should contain correct client certificates (and maybe intermediate certificates certificate chain).
i assume going write client uploads file https server? should use .jks
file client certificate (let's apache) httpclient
.
you need create sslcontext
, load keystore
sslcontext sslcontext = sslcontexts.custom().loadtrustmaterial(new file("keystore", "yourpassword".tochararray(), new trustselfsignedstrategy()).build();
then have put sslcontext
in sslconnectionsocketfactory
sslconnectionsocketfactory sslsf = new sslconnectionsocketfactory(sslcontext, new string[] { "tlsv1" }, null, sslconnectionsocketfactory.getdefaulthostnameverifier());
and build httpclient
httpclient httpclient = httpclients.custom().setsslsocketfactory(sslsf).build();
after these steps httpclient should use client certificate keystore desired request.
Comments
Post a Comment