如何修复包含不安全的TrustManager实现的应用程序

3

我正在努力让我的Android应用符合Android的新政策,根据这个要求和说明,要有安全的应用程序。

1) 我首先在我的应用程序中添加了SSL和https到URL。 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);
        }
    }    
}

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

1
你为什么需要首先拥有一个 X509TrustManager?你认为你需要它的场景是什么?https://commonsware.com/blog/2016/02/22/about-x509trustmanager-emails.html - CommonsWare
2
如果你遇到了"I don't have an X509TrustManager"的问题,那么这个问题很可能来自于某个第三方库。你需要找出是哪个库引起了这个问题,并查看是否有新版本可以修复这个问题。 - CommonsWare
正如我所指出的,你的问题来自于某个第三方库。你需要确定是哪个库,并查看是否有一些新版本可以解决这个问题。或者,只需将所有第三方库更新到最新版本,然后查看问题是否消失。 - CommonsWare
@CommonsWare 我并没有真正使用第三方库。这是一个简单的应用程序。我认为唯一可能有问题的是远程服务器调用。您认为不是远程服务器调用的问题吗? - Genadinik
我并没有真正使用第三方库,所以我不明白Google为什么会抱怨。Google要求的具体内容是一个自定义的X509TrustManager,其实现存在问题,例如此问题中的问题。你可能有一个自己输入的,或者通过dependencies添加的库中有一个,或者Google的扫描程序出了问题。 - CommonsWare
显示剩余7条评论
1个回答

3
假设Google的扫描程序没有故障,它抱怨的X509TrustManager可能来自两个地方。
它可能来自于您自己的源代码。通常,您会记得这样做,因为在某个类中键入 implements X509TrustManager 并覆盖一堆看起来很糟糕的方法。通过快速搜索您的源代码,可以确定是否是这种情况。
如果不是,那么它来自于某个库。许多(希望大多数)库都已经解决了这个问题。但是,它可能仅在比您目前使用的库更新的版本中进行了清理,要么是因为您在依赖项中列出了旧版本,要么是因为您正在使用本地的JAR文件或其他内容。坏消息是,在此处跟踪罪犯可能会很麻烦,尽管它将局限于需要Internet访问权限的库(例如,recyclerview-v7不会成为问题)。好消息是,修复问题可能只需更新库,或者如果它是您不再使用的应用程序以前实现的垃圾,则删除它即可。
虽然我无法针对Flurry发表意见,但是在旧版ACRA中确实存在此问题。最近几个月已经有各种其他ACRA修复程序,因此我建议您升级到当前版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接