8

アプリのエラーを常に監視していますが、次のエラーが何度も表示されます

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

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 を使用しています

私は次を見てきました... HttpsURLConnection のプロトコルとして SSL を無効にします

および https://code.google.com/p/android/issues/detail?id=78187

それで、私のオプションは何ですか?

  1. Volley が SSLV3 にフォールバックするという私の仮定は正しいですか?

  2. ボレーが SSLV3 にフォールバックするのはなぜですか? つまり、フォールバックの原因となった元の障害とその解決方法は?

  3. i Volley を最近ダウンロードしましたが、最新かどうかわかりません。所有しているバージョンを確認するにはどうすればよいですか?.

何かご意見は?

4

1 に答える 1

2

SSLv3 にはセキュリティ上の問題があり、使用すべきではないため、サーバーは 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;
    }

Square が TLS バージョン構成をサポートするこのライブラリの 2.1 バージョンをリリースしたため、Volley の代わりに Retrofit を使用することもできます。

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

于 2015-10-23T08:40:53.790 に答える