0

我从这篇文章中了解到 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
4

1 回答 1

4

你混淆了enabledsupported。支持协议这一事实并不意味着默认启用它。

如果要使用 TLS 1.2,setEnabledProtocols请先使用 启用它,如果getSupportedProtocols.

于 2012-10-11T19:20:50.917 回答