0

I want to upload a file to a HTTPS-server using Java. The server is not a open URL hence I need a client certificates to establish a connection. I am having .pem , .jks , .pkcs12 client certificate files.

Can any one suggest me how to use this certificate files in my application to establish communication ? Do I need to use all 3 certificate files ?

1

1 Answer 1

1

The .jks file is the Java Keystore. It should contain the correct client certificates (and maybe also the intermediate certificates from the certificate chain).

I assume you are going to write a client that uploads the file to the HTTPS server? Then you should use the .jks file with the client certificate with the (let's say apache) HttpClient.

You need to create a SSLContext and load the keystore

SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new File("keystore", "yourPassword".toCharArray(), new TrustSelfSignedStrategy()).build();

Then you have to put the sslContextin a SSLConnectionSocketFactory

SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());

And then finally build the HttpClient

HttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

After all these steps the httpClient should use your client certificate from the keystore for your desired request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.