为什么Volley会退回到SSLV3?

8

我一直在监控我的应用程序错误,但是我发现以下错误出现的次数太多了:

 javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb8f0fc28: Failure in SSL library, usually a protocol error

错误: 14077410: SSL例程: SSL23_GET_SERVER_HELLO: sslv3警报握手失败 (external/openssl/ssl/s23_clnt.c:741 0xaa48cd5c:0x00000000)-javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL握手中止:ssl=0xb8f0fc28:SSL库中的失败,通常是协议错误 错误: 14077410: SSL例程: SSL23_GET_SERVER_HELLO: sslv3警报握手失败 (external/openssl/ssl/s23_clnt.c:741 0xaa48cd5c:0x00000000)

您可以看到此错误与SSLV3有关,而我的服务器仅支持TLSV1.2。

似乎在某些客户端上,Volley会回退到使用SSLV3(出于某种原因),导致他们发生错误。

遇到此错误的用户正在使用Android 4.4.2、4.4.4和4.1.1等操作系统版本。

有趣的是,我还在同一个应用程序中使用DefaultHttpClient,但它似乎没有报告相同的问题。

我正在使用Volley中的默认HurlStack。

我看到了以下内容... Disable SSL as a protocol in HttpsURLConnection

以及 https://code.google.com/p/android/issues/detail?id=78187

那我有哪些选择呢?

  1. 我的假设正确,Volley回退到使用SSLV3吗?

  2. Volley为什么会回退到使用SSLV3?换句话说,是什么原因导致了回退并如何解决?

  3. 我最近下载了Volley,但不确定它是否是最新版本。如何查找我所拥有的版本?

有什么想法吗?


没有人来帮忙吗? - Oved Yavine
我会调查 https://dev59.com/j2Af5IYBdhLWcg3wskiQ - mattm
1个回答

2

由于存在一些安全问题,不建议使用SSLv3,因此您的服务器最好不要支持它。

如果使用Kitkat之前的Android版本,则必须使用一个套接字工厂来删除SSLv3以作为默认配置:

public class VolleyToolboxExtension extends Volley {
    /** Default on-disk cache directory. */
    private static final String DEFAULT_CACHE_DIR = "volley";

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @param stack An {@link HttpStack} to use for the network, or null for default.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
        File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
        String userAgent = "volley/0";
        try {
            String packageName = context.getPackageName();
            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
            userAgent = packageName + "/" + info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {

        }
        if (stack == null) {
            if (Build.VERSION.SDK_INT >= 9) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                    // Use a socket factory that removes sslv3
                    stack = new HurlStack(null, new NoSSLv3Compat.NoSSLv3Factory());
                } else {
                    stack = new HurlStack();
                }
            } 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));
            }
        }
        Network network = new BasicNetwork(stack);
        RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
        queue.start();
        return queue;
    }

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context) {
        return newRequestQueue(context, null);
    }

}

在这里可以找到NoSSLv3Compat类: https://github.com/Floens/volley/blob/master/src/com/android/volley/compat/NoSSLv3Compat.java

使用此扩展来创建您的请求队列:

    /**
     * @return The Volley Request queue, the queue will be created if it is null
     */
    public RequestQueue getRequestQueue() {
        // lazy initialize the request queue, the queue instance will be
        // created when it is accessed for the first time
        if (mRequestQueue == null) {
            // Create the request queue
            mRequestQueue = VolleyToolboxExtension.newRequestQueue(getApplicationContext());
        }

        return mRequestQueue;
    }

您也可以使用Retrofit代替Volley,因为Square发布了支持TLS版本配置的2.1版本库:

http://square.github.io/retrofit/


我在哪里可以找到你正在扩展的DelegateSSLSocket,即这里的Private static class NoSSLv3SSLSocket extends DelegateSSLSocket { - Rohit Gupta
https://github.com/Floens/volley/blob/master/src/com/android/volley/compat/DelegateSSLSocket.java - Uday Nayak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接