android - Proguard 导致 Android 上的 SSL keystore 出现问题

标签 android obfuscation ssl-certificate proguard keystore

在 Android 应用程序中,我从 https url 获取内容;为了避免 SSL 证书验证错误,我将 SSL 公钥添加到我的 keystore 中,然后它位于我的应用程序的 res/raw 文件夹中。 按照 http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html 上的说明进行操作,到目前为止一切正常。

..直到我激活 Proguard 和混淆。激活 Proguard 后,出现以下错误,

ERROR/Login(4401): Could not login.
    javax.net.ssl.SSLException: hostname in certificate didn't match: <store.mydomain.com/185.165.192.15> != <store.mydomain.com> OR <store.mydomain.com>
    at xyz.fd.a(Unknown Source)

我不太明白。为什么 url 的识别会以一种它也获取 /<ipAddress> 的方式发生变化?与域名一起使用,而无需 Proguard 混淆即可正常工作。

作为获取 https 内容的 httpClient,我使用 MyHttpClient 中的来源: http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html

proguard.cfg:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference

-keep class * extends DefaultHttpClient

-ignorewarnings
-repackageclasses 'xyz'
-allowaccessmodification

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

更新:

同时删除 -repackageclasses 'xyz' 和 -allowaccessmodification 没有区别,同样的错误。

最佳答案

我使用的是最新的 httpclient 4.1.2。现在当我切换回 4.1.1 时,问题就消失了。

另见:http://comments.gmane.org/gmane.comp.apache.httpclient.user/262

关于android - Proguard 导致 Android 上的 SSL keystore 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8177793/

相关文章:

android - 使用 Volley 在android中获取服务器端 session ID

javascript - 使文本难以通过自动方式解析

android - 在另一个pendingintent中取消一个AlarmManager的pendingIntent

android - 如何在 Android 中创建页眉内容布局?

java - 单元测试时的 RxJava Schedulers.immediate() 行为

Android库项目——混淆

Android 日志去混淆/回溯

postgresql - 使用psql以SSL方式连接PostgreSQL

python - 使用 django 应用程序安装 certbot ssl 时出现问题

将证书添加到 Key Vault 时出现 Azure 错误