【问题标题】:Error in android application: javax.net.ssl.SSLPeerUnverifiedException: No peer certificateandroid 应用程序中的错误:javax.net.ssl.SSLPeerUnverifiedException:没有对等证书
【发布时间】:2015-07-25 18:49:43
【问题描述】:

美好的一天,可以征求意见。 我的代码工作正常,但有一天没有明显的原因并且没有更改服务器上的代码停止工作,显示此错误 我检查了链接引用的决定,但没有一个给出预期的结果。 也许 SSL 协议中有什么东西?

Safely fixing: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

javax.net.ssl.sslpeerunverifiedexception no peer certificate

Android ssl: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Trusting all certificates using HttpClient over HTTPS

class RequestTask extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... params) {

        try {

            HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

            DefaultHttpClient client = new DefaultHttpClient();

            SchemeRegistry registry = new SchemeRegistry();
            SSLSocketFactory socketFactory = SSLSocketFactory
                    .getSocketFactory();
            socketFactory
                    .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
            registry.register(new Scheme("https", socketFactory, 443));
            SingleClientConnManager mgr = new SingleClientConnManager(
                    client.getParams(), registry);
            DefaultHttpClient httpClient = new DefaultHttpClient(mgr,
                    client.getParams());

            HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            ResponseHandler<String> res = new BasicResponseHandler();

            HttpPost postMethod = new HttpPost("https://api.equalibra.net/banners.json");

            nameValuePairs.add(new BasicNameValuePair("lang", "rus"));
            postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                    HTTP.UTF_8));

            String response = "";
            try {
                response = httpClient.execute(postMethod, res);
            } catch (Exception e) {
                Log.d("my", e.toString());
            }

            JSONURL(response);

        } catch (Exception e) {
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
}

【问题讨论】:

  • 使用cloudfare的主机,问题可能与cloudfare的变化有关?

标签: android security ssl https


【解决方案1】:

确实,问题在于我的 Android SDK 不支持 SNI 。 It helped me:

【讨论】:

    【解决方案2】:

    服务器需要使用SNI (server name indication)。不使用 SNI 的连接将简单地失败,而不是通常情况下获得默认证书。由于这是服务器端的设置,因此它最近可能已更改,从而破坏了您的代码。

    虽然 SNI 在较新版本的 Apache HTTP 客户端库中可用,但在您可能使用的 Android SDK 随附的版本中不可用。

    【讨论】:

    • 再次,以防答案不够清楚:服务器需要now SNI,它可能不需要before SNI。这意味着您的应用服务器端更改之前可以工作,但现在不能工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2017-08-04
    • 2013-08-10
    • 1970-01-01
    • 2014-11-22
    • 2012-11-09
    相关资源
    最近更新 更多