java - 如何检查请求的 TLS 版本
问题描述
我有okhttp3.OkHttpClient
并且我使用 Retrofit2 发出 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 版本?
解决方案
response.handshake().tlsVersion()
将例如TlsVersion.TLS_1_2
。
见https://square.github.io/okhttp/4.x/okhttp/okhttp3/-tls-version/
推荐阅读
- python - 以最快的方式比较两个字典列表以获得性能
- spring - Spring Cassandra:在另一个键空间中的运行时创建模式
- r - 对具有相同值的行进行分组
- ios - 将 Xamarin.Forms 应用程序部署到 iOS:MT1006 EOF 错误(错误:0xe800000e)
- git - 打包器中的Git克隆操作
- python-3.x - 如何使用 Python 处理 API Gateway 中的自定义 Lambda 错误
- angular - 开始路由之前的Angular 6调用后端api
- sql - 查询以根据同一表中其他列的值更新数据
- ios - 切换到 Xcode 10 会导致 iOS9 的“UserNotifications.framekwor dyld: Library not loaded crash”
- apache-spark - 如何使用 spark 获取包含大量文件的目录的大小?