2

I have okhttp3.OkHttpClient and I make REST request using Retrofit2.

interface WebService {
    @GET("/httptwo")
    public Call<String> executeRequest();
}


//in these 2 methods I initialize server IP, SSLContext, keystore, truststore and all the stuff.
OkHttpClient client = getClient();
Retrofit retrofit = getRetrofit(client);

//make call
WebService service = retrofit.create(WebService.class);
Call<String> call = service.executeRequest();
try {
    Response<String> response = call.execute();
    String responseBody = response.body();
    System.out.println(responseBody);
} catch (Exception e) {
    e.printStackTrace();
}

I make request to my dummy Server.

@RestController
class SecureServiceController {
@RequestMapping(value = "/httptwo")
    public String httpTwoHandler() {
        String httpVersion = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getProtocol();
        System.out.println("http version: " + httpVersion);
        
        return "Hello from " + httpVersion;
    }

}

As you can see, I can check version of http protocol. But how can I check version of TLS that was used?

Igor_M
  • 308
  • 2
  • 12

1 Answers1

3
response.handshake().tlsVersion()

Will be for example TlsVersion.TLS_1_2.

See https://square.github.io/okhttp/4.x/okhttp/okhttp3/-tls-version/

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • 2
    Just small note for future generations: here is used okhttp3.Response. I work with Retrofit2, so I had retrofit2.Response. To get okhttp3.Response I used myRetrofitResponse.raw() – Igor_M Jul 05 '21 at 08:04