Android <= 4.4.2 和 TLS 1.2

Android <= 4.4.2 and TLS 1.2

我为一家公司做了一个应用程序,它支持 API 级别 13+ (3.0+)。它通过 XML 从他们的 CMS 收集数据并将其显示在应用程序上。这是通过 HTTPS 完成的,在他们将服务器升级到 TLS 1.2 之前工作正常。现在 android 低于 API 级别 20 的版本将无法获取 XML 因为 SSLPeerUnverifiedException 并且很多手机再也看不到这个应用程序了。

有没有办法在启用 TLS 1.2 的同时通过 SSLPeerUnverified

注:目前SSL证书如下:

AddTrust External CA Root
--> COMODO High-Assurance Secure Server CA
  --> *.appdomain.com

迄今为止最有帮助的 SOF 文章: Implementing TLS 1.2 on Android 2.3.3

团队中的其他人回答了这个问题,但结果包括以下内容:

  • SSLContext helper=null;
  • helper.init(null,null,null);
  • SSLContext.getInstance("TLSv1.2");
  • SSLEngine engine = helper.createSSLEngine();

这是他用来检查ssl的函数,把所有东西都放进去:

public void sslCheck() {

        int PLAY_SERVICES_RESOLUTION_REQUEST=9000;
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        //Log.i("log_tag2", String.valueOf(resultCode));
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                Log.i("log_tag2","Not good!");
                if (MyAppActivity.instance != null) {
                    Log.i("log_tag2","but can fix");
                    GooglePlayServicesUtil.getErrorDialog(
                            resultCode,
                            MyAppActivity.instance,
                            PLAY_SERVICES_RESOLUTION_REQUEST).show();
                }
            }
        }
        else {
            Log.i("log_tag2","Already good!");
            try {
                ProviderInstaller.installIfNeeded(this);
                Log.i("log_tag", "1");
            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            } catch (GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            }
            SSLContext helper=null;
            try {
                helper = SSLContext.getInstance("TLSv1.2");
                Log.i("log_tag","2");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            try {
                helper.init(null,null,null);
                Log.i("log_tag", "3");
            } catch (KeyManagementException e) {
                e.printStackTrace();
            }
            SSLEngine engine = helper.createSSLEngine();
        }
    }