【问题标题】:Android https request, ssl protocol failedAndroid https请求,ssl协议失败
【发布时间】:2016-03-07 09:28:27
【问题描述】:

背景

SSLv3 协议不安全,阅读some articles 后,我使用this solution 删除此协议。

删除sslv3的方法:

@Override
        public void setEnabledProtocols(String[] protocols) {
            if (protocols != null && protocols.length == 1 && "SSLv3".equals(protocols[0])) {
                // no way jose
                // see issue https://code.google.com/p/android/issues/detail?id=78187
                List<String> enabledProtocols = new ArrayList<String>(Arrays.asList(delegate.getEnabledProtocols()));


            for (String pro : enabledProtocols) {
                VolleyLog.d(pro);
            }
                if (enabledProtocols.size() > 1) {
                    enabledProtocols.remove("SSLv3");
                    VolleyLog.d("Removed SSLv3 from enabled protocols");
                } else {
                    VolleyLog.d("SSL stuck with protocol available for " + String.valueOf(enabledProtocols));
                }
                protocols = enabledProtocols.toArray(new String[enabledProtocols.size()]);
            }

            super.setEnabledProtocols(protocols);
        }

我使用 Volley 作为 http 客户端,这是我初始化请求队列的代码:

HttpStack stack;
        if (Build.VERSION.SDK_INT >= 9) {
            // Use a socket factory that removes sslv3
            // https://code.google.com/p/android/issues/detail?id=78187
            stack = new HurlStack(null, new NoSSLv3Compat.NoSSLv3Factory());
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }

设备和环境

我使用的是小米 M3 和 MIUI ROM,基于 Android 4.4.4。

当调用 setEnabledProtocols 方法时,我会打印一些日志:

D/Volley: [1444] NoSSLv3SSLSocket.setEnabledProtocols: SSLv3
D/Volley: [1444] NoSSLv3SSLSocket.setEnabledProtocols: TLSv1
D/Volley: [1444] NoSSLv3SSLSocket.setEnabledProtocols: Removed SSLv3 from enabled protocols

问题

当我尝试加载这个image,失败,输出:

NoConnectionError: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException:SSL 握手终止: ssl=0x77f49768: SSL 库失败,通常是协议错误

E/CachedHttp: 错误:1409443E:SSL 例程:SSL3_READ_BYTES:tlsv1 警报 不适当的后备(外部/openssl/ssl/s3_pkt.c:1256 0x77f4c280:0x00000003)

此图像服务器支持以下协议:

TLS 1.2、 TLS 1.1、 TLS 1.0、 SSL 3

你能帮我弄清楚吗?

【问题讨论】:

标签: android ssl https android-volley


【解决方案1】:

你检查过钥匙的大小吗?启用调试日志以查看确切的问题。可能是由于您尝试连接的后端的密钥大小不足造成的。

Enable JCE Unlimited for java 7

Identify handshake errors

【讨论】:

    猜你喜欢
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多