这是我第一次在 Play 商店上发布应用程序,但我的应用程序被拒绝了。
这是来自谷歌播放的消息:
如何修复包含不安全的 TrustManager 实现的应用程序。...
要正确处理 SSL 证书验证,请更改自定义 X509TrustManager 接口的 checkServerTrusted 方法中的代码,以在服务器提供的证书不符合您的期望时引发 CertificateException 或 IllegalArgumentException
这是我的自定义 TrustManager :
public static OkHttpClient getUnsafeOkHttpClient(final X509TrustManager tm) {
try{
//Create a trust manager taht does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
try{
tm.checkClientTrusted(chain, authType);
}catch (CertificateException ce){}
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException{
if(chain == null || chain.length == 0)throw new IllegalArgumentException("certificate is null or empty");
if(authType == null || authType.length() == 0) throw new IllegalArgumentException("authtype is null or empty");
if(!authType.equalsIgnoreCase("RSA"))throw new CertificateException("certificate is not trust");
tm.checkServerTrusted(chain,authType);
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return tm.getAcceptedIssuers();
}
}};
我必须实现 chekcServerTrusted 方法,我尝试了多种实现,但我的应用程序总是被拒绝。
请你能帮助或提出问题。