【发布时间】:2015-02-04 08:58:10
【问题描述】:
我正在实习。 在这里,他们给了我一个 Android 应用程序的代码,该代码已由代码安全机构进行了修订,并告诉我更改文档中存在的一些要点。 现在他们担心信息泄露,因为应用程序在连接到银行服务器时没有检查 SSL 证书,从而面临“中间人”攻击的风险。
是否有任何类可以用来检查证书的到期日期。或者是否可信?
应用中的http连接示例:
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams bhttpparams = new BasicHttpParams();
HttpProtocolParams.setVersion(bhttpparams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(bhttpparams, "utf-8");
bhttpparams.setBooleanParameter("http.protocol.expect-continue", false);
HttpConnectionParams.setConnectionTimeout(bhttpparams, 20000);
HttpConnectionParams.setSoTimeout(bhttpparams, 200000);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(bhttpparams, registry);
client = new DefaultHttpClient(ccm, bhttpparams);
client.getCredentialsProvider().setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials("", ""));
HttpResponse response = client.execute(urlws);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"), 8);
【问题讨论】:
-
Android SSL 堆栈默认是安全的。只需丢弃任何自定义 SSL 内容并使用默认值。