Android https请求,ssl协议(protocol)失败

标签 android ssl https android-volley

背景

SSLv3 协议(protocol)是不安全的,在我阅读之后 some articles , 我用 this solution删除此协议(protocol)。

移除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 handshake terminated: ssl=0x77f49768: Failure in SSL library, usually a protocol error

E/CachedHttp: error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate fallback (external/openssl/ssl/s3_pkt.c:1256 0x77f4c280:0x00000003)

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

TLS 1.2、 TLS 1.1、 TLS 1.0、 SSL 3

你能帮我弄清楚吗?

最佳答案

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

Enable JCE Unlimited for java 7

Identify handshake errors

关于Android https请求,ssl协议(protocol)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840179/

相关文章:

java - 混沌游戏安卓

Android:WebView/BaseInputConnection 中的退格键

ssl - Oracle Service Bus (OSB) SSL 握手失败

javascript - 使用不受信任的证书对安全 URL 执行 AJAX 方法

apache - 将 http 重定向到 https ,什么是 ssl 配置?

java - Android应用程序不从Socket输入流读取

mongodb - 为什么 MongoDB(带 SSL)多次要求 .pem 密码?

android - "Location of the Android SDK has not been set up in the preferences"错误

https - 在 HTTPS 代理中响应 403

android - 共享数据库数据