2

I have a webservice client developed in Java 8. I've verified the host I'm connecting to is using TLSv1.2 via this site. https://www.ssllabs.com/ssltest/

I am getting the error below when sending executing the post request:

javax.net.ssl.SSLException: Received fatal alert: protocol_version

I have added this line at the start of my code. No luck.

System.setProperty("https.protocols", "TLSv1.2");

I have also added a JVM argument in my WebSphere server application.

-Dhttps.protocols=TLSv1.2

Still, the error is there.

I have read similar questions, and I think using Java 8 defaults to TLSv1.2. The error keeps coming up so I still added those properties. So I'm not sure why this is coming up.

Here's my code.

Loggers.general().debug(LOG, "### getOKTAToken()...");
String OKTAresponse = "";
OKTAResponse oktaReply = new OKTAResponse();
HttpClient httpClient = HttpClientBuilder.create().build();
Loggers.general().debug(LOG, "### ipsum");
//pass webservice URL
Loggers.general().debug(LOG, "URL:{}",Constants.URL);
HttpPost httpPost = new HttpPost(Constants.URL);        
ArrayList<NameValuePair> postParameters;

//required keys for OKTA call
Loggers.general().debug(LOG, "Setting Body");
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("client_id", 
Constants.clientID));
postParameters.add(new BasicNameValuePair("client_secret", 
Constants.clientSecret));
postParameters.add(new BasicNameValuePair("grant_type", 
Constants.grantType));

try 
{
Loggers.general().debug(LOG, "Setting entity...");
httpPost.setEntity(new UrlEncodedFormEntity(postParameters,"UTF-8"));
HttpResponse response = httpClient.execute(httpPost);

The error points to the last line. HttpResponse response = httpClient.execute(httpPost); Does anyone have an idea why this error keep coming up? Need reinforcements.

Environment:

  • Java 8
  • WebSphere 8.5.5
  • Windows 10

2 Answers2

1

You have to change a TLS protocol version on the Websphere Application Server level not during Java run time execution.

Set the protocol to TLSv1.2 from WAS admin console as on the below screen shot and restart your Websphere Application Server.

enter image description here

kels
  • 138
  • 2
  • 11
0

Kel's answer helped, but I also needed to add the -Dhttps.protocols=TLSv1.2 flag you mentioned in your question and -Dcom.ibm.jsse2.overrideDefaultTLS=true from this answer. I am using the IBM JDK and WebSphere 9.0.0.

TarHalda
  • 1,050
  • 1
  • 9
  • 27