ttt
ttt

Reputation: 4004

Apache HttpClient for RestTemplate default behaviour if not setting up SSLSocketFactory and SSLContext

I am using Spring RestTemplate (config using HttpClient) to make a restful service call for a URL with https.

I explicitly setup SSL using following code:

SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial().setProtocol().build
return new SSLConnectionSocketFactory(sslContext)

It works without any problem.

What would be the default behaviour if I don't setup SSLSocketFactory and SSLContext for HttpClient? Will it look for the cacerts under the installed JDK or it will disable the ssl?

Upvotes: 1

Views: 371

Answers (1)

clevertension
clevertension

Reputation: 7077

I say Yes If your https website can be passed by your browser, or your certificate file is coming from the Certificate Authority such as GlobalSign, Verisign

enter image description here

we can see the SSLContext and SSLSocketFactory will be created automatically, so you can visit https without doing anything

if your certificate file is not trusted, and import to jdk cacerts still can't solve this, because HttpClient download the certificate file via SSLSocket, not from the jdk cacerts

verify

Upvotes: 1

Related Questions