Предупреждение Google Play и "небезопасная реализация X509TrustManager"
Мы получили письмо о том, что "вы используете небезопасную реализацию X509TrustManagfer". Чтобы решить эту проблему, мы применили решение от http://transoceanic.blogspot.in/2011/11/android-import-ssl-certificate-and-use.html
Здесь мы сгенерировали новое хранилище ключей BKS и передали это хранилище ключей SSLSocketFactory. Эта фабрика отвечает за проверку сертификата сервера. У нас уже есть Keystore, но его нет в формате.BKS. Вот почему мы создали новый для специально HTTPS-звонка. Пожалуйста, просмотрите мой код ниже:
DefaultHttpClient sslClient = new MyHttpClient(StartupActivity.activity);
public class MyHttpClient extends DefaultHttpClient {
final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
// Register for port 443 our SSLSocketFactory with our keystore
// to the ConnectionManager
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
private SSLSocketFactory newSslSocketFactory() {
try {
// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted = KeyStore.getInstance("BKS");
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = context.getResources().openRawResource(
R.raw.mykeystore);
try {
// Initialize the keystore with the provided trusted
// certificates
// Also provide the password of the keystore
trusted.load(in, "keystore_password".toCharArray());
} finally {
in.close();
}
// Pass the keystore to the SSLSocketFactory. The factory is
// responsible
// for the verification of the server certificate.
SSLSocketFactory sf = new SSLSocketFactory(trusted);
// Hostname verification from certificate
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
Можете ли вы проверить и подтвердить, что с этим решением наше приложение будет в безопасности?
Дайте нам знать, если у вас есть другое лучшее решение.