android-如何修复包含不安全的TrustManager实现的应用
作者:互联网
我试图使我的Android应用程序符合Android的新政策,即每requirement and instructions拥有安全应用程序.
1)我首先在应用程序的URL中添加了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);
}
}
}
但这并没有删除开发人员控制台上的警告标志.知道我在做什么错以及如何解决吗?
解决方法:
假设Google的扫描仪没有损坏,它抱怨的X509TrustManager可能来自两个位置之一.
它可能来自您自己的源代码.通常,您会记得这样做,因为您在某个地方的类中输入了X509TrustManager的实现,并覆盖了一些看起来很讨厌的方法.快速搜索源代码应确定是否是这种情况.
如果不是,则来自某个库.许多(希望是大多数)图书馆将对此进行清理.但是,它可能仅在当前使用的较新版本的库中清除,这可能是因为您的依赖项中列出了旧版本,或者您正在使用本地JAR或其他内容.坏消息是,在这里追查罪魁祸首可能很痛苦,尽管它仅限于需要Internet访问的图书馆(例如recyclerview-v7不会有问题).好消息是,解决问题可能很简单,例如更新库,或者如果它不再使用您以前不再使用的应用实现,则将其删除.
尽管我无法谈论Flurry,但旧版本的ACRA中确实存在此问题.最近几个月,ACRA还进行了许多其他修复,因此我建议您还是升级到当前版本.
标签:android-security,android-securityexception,android 来源: https://codeday.me/bug/20191118/2031317.html