为什么volley会在没有告知的情况下加密我的post-request

时间:2015-08-30 22:17:59

标签: java android https android-volley

我正在尝试登录使用https的远程地址。 为此,我使用volley发送带有用户数据的post-request。

这是我的相关代码(includes setting up a StringRequest -> fire StringRequest):

StringRequest myStringRequest = new StringRequest(Request.Method.POST, remoteurl, this, this) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<>();
                headers.put("Accept-Charset","utf-8");
                headers.put("Connection","keep-alive");
                headers.put("User-Agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0");
                headers.put("Content-Type","application/x-www-form-urlencoded");
                return headers;
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("name","myname");
                params.put("pw","mypw");
                params.put("totp","");
                params.put("app","76");
                return params;
            }
        };
SingleTonVolley.getInstance().getRequestQueue(getActivity().getApplicationContext()).add(myStringRequest);

我的用于实例化newRequestQueue的SingleTon看起来如下:

public class SingleTonVolley {
private static SingleTonVolley mInstance = new SingleTonVolley();
private RequestQueue mRequestQueue;

private SingleTonVolley() {
}

public static SingleTonVolley getInstance() {
    return mInstance;
}

public synchronized RequestQueue getRequestQueue(Context context) {
    if(mRequestQueue == null)
    {
        mRequestQueue = Volley.newRequestQueue(context);
    }
    return mRequestQueue;
}

}

但是,在运行我的代码时,我可以看到WireShark我的数据是使用TLSv1.2加密发送的:

No.     Time           Source                Destination           Protocol Length Info
 11 2.898033000    192.168.0.19          80.190.158.9          TCP      74     57186 > https [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=11207479 TSecr=0 WS=128
 12 2.929011000    80.190.158.9          192.168.0.19          TCP      74     https > 57186 [SYN, ACK] Seq=0 Ack=1 Win=14480 Len=0 MSS=1460 SACK_PERM=1 TSval=210621220 TSecr=11207479 WS=128
 13 2.929044000    192.168.0.19          80.190.158.9          TCP      66     57186 > https [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=11207487 TSecr=210621220
 14 2.930506000    192.168.0.19          80.190.158.9          TLSv1.2  284    Client Hello
 15 2.959979000    80.190.158.9          192.168.0.19          TCP      66     https > 57186 [ACK] Seq=1 Ack=219 Win=15616 Len=0 TSval=210621228 TSecr=11207487
 16 2.964700000    80.190.158.9          192.168.0.19          TLSv1.2  1514   Server Hello
 17 2.964742000    192.168.0.19          80.190.158.9          TCP      66     57186 > https [ACK] Seq=219 Ack=1449 Win=32128 Len=0 TSval=11207496 TSecr=210621229
 18 2.967946000    80.190.158.9          192.168.0.19          TLSv1.2  1725   Certificate
 19 2.967997000    192.168.0.19          80.190.158.9          TCP      66     57186 > https [ACK] Seq=219 Ack=3108 Win=35456 Len=0 TSval=11207496 TSecr=210621229
 20 2.993710000    192.168.0.19          80.190.158.9          TLSv1.2  192    Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
 21 3.027476000    80.190.158.9          192.168.0.19          TLSv1.2  324    New Session Ticket, Change Cipher Spec, Encrypted Handshake Message
 22 3.030701000    192.168.0.19          80.190.158.9          TLSv1.2  471    Application Data
 23 3.107383000    80.190.158.9          192.168.0.19          TCP      66     https > 57186 [ACK] Seq=3366 Ack=750 Win=16640 Len=0 TSval=210621265 TSecr=11207512
 35 3.194115000    80.190.158.9          192.168.0.19          TCP      1514   [TCP segment of a reassembled PDU]
 36 3.195622000    80.190.158.9          192.168.0.19          TLSv1.2  6488   Application Data
 37 3.195653000    192.168.0.19          80.190.158.9          TCP      66     57186 > https [ACK] Seq=750 Ack=11236 Win=54144 Len=0 TSval=11207553 TSecr=210621286
535 63.283062000   80.190.158.9          192.168.0.19          TLSv1.2  97     Encrypted Alert
536 63.283534000   80.190.158.9          192.168.0.19          TCP      66     https > 57186 [FIN, ACK] Seq=11267 Ack=750 Win=16640 Len=0 TSval=210636286 TSecr=11207553
537 63.320615000   192.168.0.19          80.190.158.9          TCP      66     57186 > https [ACK] Seq=750 Ack=11268 Win=54144 Len=0 TSval=11222585 TSecr=210636286

关于SO上的许多其他问题,我可以看到每个人在创建SSLSocketFactory时都必须传递newRequestQueue。虽然这听起来对我来说绝对合乎逻辑,但我想知道为什么我的程序默认执行此操作,因为我没有添加任何SSLSocketFactory。我想知道我是否有比其他用户在过去询问SO时使用的更新版本的凌空。但是,在查看source-code of volley时,在使用https-url自动将SSLSocketFactory分配给RequestQueue时,我无法找到任何检测结果。 希望有人能为我的问题带来一些启示。

加成

我可以找到的SSLSocketFactory相关内容只有HurlStack.class

构造

public HurlStack(UrlRewriter urlRewriter, SSLSocketFactory sslSocketFactory) {
    mUrlRewriter = urlRewriter;
    mSslSocketFactory = sslSocketFactory;
}

评估是否已通过SSLSocketFactory:

    // use caller-provided custom SslSocketFactory, if any, for HTTPS
    if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) {
        ((HttpsURLConnection)connection).setSSLSocketFactory(mSslSocketFactory);
    }

所以"https".equals(url.getProtocol())在我的情况下评估为true,但mSslSocketFactory != null不会!

1 个答案:

答案 0 :(得分:-1)

它与套接字工厂没有任何关系。您已指定Max height = N; Min Height = floor( lg(N) ) = ceil( (lg(N+1) - 1) ) ,但您已HTTPS