今天,我写道:
SSLContext.getInstance("TLSv1.3")
,但我更喜欢这样的东西:
SSLContext.getInstance("TLSvLatest")
。
我找不到使用现有API/ctor的直接方法。这可以模拟吗?
一个古怪的想法:
private static SSLContext
_getSSLContextTLSLatest()
throws NoSuchAlgorithmException
{
for (int i = 9; i >= 3; --i)
{
final String protocol = "TLSv1." + i;
try {
final SSLContext x = SSLContext.getInstance(protocol);
return x;
}
catch (NoSuchAlgorithmException e)
{
// do nothing
}
}
throw new NoSuchAlgorithmException("SSLContext: Failed to final TLS latest");
}
注意:如果可以使用更好的标签,请重新标记此问题。