如何检查请求的tls版本

3zwjbxry  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(869)

我有 okhttp3.OkHttpClient 我使用第2个命令发出rest请求。

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();
}

我向我的虚拟服务器发出请求。

@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;
    }

}
如您所见,我可以检查http协议的版本。但如何检查所使用的tls版本?

am46iovg

am46iovg1#

response.handshake().tlsVersion()

比如说 TlsVersion.TLS_1_2 .
看见https://square.github.io/okhttp/4.x/okhttp/okhttp3/-tls-version/

相关问题