为什么getEnabledProtocols()返回TLS v1而不是TLSv1.2?

时间:2012-10-11 18:55:47

标签: android ssl

我从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

1 个答案:

答案 0 :(得分:3)

您对已启用支持感到困惑。支持协议这一事实并不意味着它默认启用。

如果您想使用TLS 1.2,请先使用setEnabledProtocols启用它,如果getSupportedProtocols支持它,则应该有效。