【问题标题】:How to fix apps containing an unsafe implementation of TrustManager如何修复包含不安全的 TrustManager 实现的应用程序
【发布时间】:2016-07-23 08:45:36
【问题描述】:

我正在努力使我的 Android 应用程序符合 Android 的新政策,即根据 requirement and instructions 提供安全应用程序。

1) 我首先将 SSL 和 https 添加到我的应用程序的网址中 2)然后我开始使用类 HttpsURLConnection 而不是 HttpURLConnection

这是我使用的远程调用示例:

   public void sendFeedback(String name , String email , String password ) 
   {  
        String[] params = new String[] { "https://www.problemio.com/auth/create_profile_mobile.php", name , email , password };

        DownloadWebPageTask task = new DownloadWebPageTask();
        task.execute(params);        
   }

   public class DownloadWebPageTask extends AsyncTask<String, Void, String> 
   {       
        private boolean connectionError = false;


     @Override
     protected void onPreExecute( ) 
     {
          dialog = new Dialog(CreateProfileActivity.this);

          dialog.setContentView(R.layout.please_wait);
          dialog.setTitle("Creating Profile");

          TextView text = (TextView) dialog.findViewById(R.id.please_wait_text);
          text.setText("Please wait while your profile is created... ");
          dialog.show();
     }             

    @Override
    protected String doInBackground(String... theParams) 
    {
        String myUrl = theParams[0];
        final String name = theParams[1];
        final String email = theParams[2];
        final String password = theParams[3];

        String charset = "UTF-8";                       
        String response = null;

        try 
        {               
            String query = String.format("name=%s&email=%s&password=%s", 
                     URLEncoder.encode(name, charset), 
                     URLEncoder.encode(email, charset), 
                     URLEncoder.encode(password, charset));

            final URL url = new URL( myUrl + "?" + query );

            final HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

            conn.setDoOutput(true); 
            conn.setRequestMethod("POST");

            conn.setDoOutput(true);

            conn.setUseCaches(false);

            conn.connect();

            final InputStream is = conn.getInputStream();
            final byte[] buffer = new byte[8196];
            int readCount;
            final StringBuilder builder = new StringBuilder();
            while ((readCount = is.read(buffer)) > -1) 
            {
                builder.append(new String(buffer, 0, readCount));
            }

            response = builder.toString();      
        } 
        catch (Exception e) 
        {
              connectionError = true;
        }

        return response;
    }

    @Override
    protected void onPostExecute(String result) 
    {       
        // Some code

            // Make an intent to go to the home screen
            Intent myIntent = new Intent(CreateProfileActivity.this, MainActivity.class);
            CreateProfileActivity.this.startActivity(myIntent);
        }
    }    
}

但它并没有删除我的开发者控制台上的警告标志。知道我做错了什么以及如何解决这个问题吗?

【问题讨论】:

  • 为什么你首先有一个X509TrustManager?你认为你需要一个的场景是什么? commonsware.com/blog/2016/02/22/…
  • @CommonsWare 我在那个页面上读到这为他们解决了......我个人对此知之甚少stackoverflow.com/questions/35530558/…
  • 这很好,但它不能回答我的问题。为什么你首先有一个X509TrustManager?如果您没有,然后开始从 Play 商店收到此消息,您的问题可能来自 a third-party library。如果您在收到此消息之前有自己的 X509TrustManager... 为什么?
  • @CommonsWare 我没有 X509TrustManager 管理器。
  • “我没有 X509TrustManager”——那么您的问题来自某个第三方库。您需要确定该库是什么,并查看是否有修复此问题的新版本。

标签: android android-security android-securityexception


【解决方案1】:

假设 Google 的扫描仪没有损坏,它所抱怨的 X509TrustManager 可能来自两个地方之一。

它可能来自您自己的源代码。通常,您会记得这样做,因为您在某个类的某个地方输入了implements X509TrustManager 并覆盖了一堆看起来很恶心的方法。快速搜索您的源代码应该可以确定是否是这种情况。

如果不是,它来自某个图书馆。许多 - 希望大多数 - 图书馆将清理这一点。但是,它可能只在比您当前使用的新版本的库中被清理,或者因为您的依赖项中列出了旧版本,或者您正在使用本地 JAR 或其他东西。坏消息是在这里追查罪魁祸首可能会很痛苦,尽管它仅限于需要互联网访问的图书馆(例如,recyclerview-v7 不会有问题)。好消息是,解决问题可能就像更新库一样简单,或者如果它从您不再使用的应用的过去实现中删除,则将其删除。

虽然我不能谈论 Flurry,但这个问题确实存在于旧版本的 ACRA 中。最近几个月对 ACRA 进行了各种其他修复,因此我建议您还是升级到当前版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多