我从this帖子了解到JB支持TLSv1.2。当我运行以下测试代码时,我现在陷入困境。我得到支持的协议为TLS1.0而不是TLSv1.2。我做错了什么?
public class SSLTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ssltest);
SSLSocketFactory mSslSocketFactory = null;
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("Default");
} catch (NoSuchAlgorithmException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mSslSocketFactory = sslContext.getSocketFactory();
SSLSocket sock = null;
try {
sock = (SSLSocket)mSslSocketFactory.createSocket();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] prots = sock.getEnabledProtocols();
for(int i=0;i<prots.length;i++){
Log.d("TEMP","$$$$$$$$$$$$$$$$$$$$$$$ ::: " + prots[i]);
}
SSLParameters sslp = sock.getSSLParameters();
String[] newprots = sslp.getProtocols();
for(int i=0;i<newprots.length;i++){
Log.d("TEMP","$$$$$$$$$$$$$$$$$$$$$$$ ::: " + newprots[i]);
}
}
输出:
10-11 11:57:53.280: D/TEMP(7928): $$$$$$$$$$$$$$$$$$$$$$$ ::: SSLv3
10-11 11:57:53.280: D/TEMP(7928): $$$$$$$$$$$$$$$$$$$$$$$ ::: TLSv1
10-11 11:57:53.280: D/TEMP(7928): $$$$$$$$$$$$$$$$$$$$$$$ ::: SSLv3
10-11 11:57:53.280: D/TEMP(7928): $$$$$$$$$$$$$$$$$$$$$$$ ::: TLSv1
答案 0 :(得分:3)
您对已启用和支持感到困惑。支持协议这一事实并不意味着它默认启用。
如果您想使用TLS 1.2,请先使用setEnabledProtocols
启用它,如果getSupportedProtocols
支持它,则应该有效。