带有 TLS 的 Apache httpclient,但无法在 wireshark 中捕获 tls 数据包

Apache httpclient with TLS, but can not catch tls packet in wireshark

我使用 apache.httpcomponent.httpcore 和 httpclient 4.3 版,我想使用 httpclient post 到我的 https 服务器。 但是当我使用 wireshark 捕获数据包时,数据包是 TCP 而不是 TLS。谁能告诉我为什么?

下面的代码是我用trustmanager配置SSLContext。我将服务器的证书加载到信任管理器中。

SSLContext ctx = null;
String keystoreName = "/Users/user/ec_key/in_keystore";
char[] password = "123456".toCharArray();       //keystore's password

    FileInputStream fIn;
    KeyStore keystore;
    TrustManagerFactory tmf=null;

    try {
        fIn = new FileInputStream(keystoreName);
        keystore = KeyStore.getInstance("JKS");
        keystore.load(fIn, password);               //loading keysotre

        tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());   //TrustManagerFactory.getDefaultAlgorithm()=PKIX
        tmf.init(keystore);

        ctx = SSLContext.getInstance("TLSv1.2");
        // Initial SSLContext
        ctx.init(null, tmf.getTrustManagers(), new java.security.SecureRandom());

        fIn.close();

    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (KeyStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

        // create SSLConnectionSocketFactory
        SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(ctx);

    CloseableHttpClient httpClient = HttpClientBuilder.create()
            .setSSLSocketFactory(factory)
            .disableAutomaticRetries()
            .build();

//execute http method
HttpResponse httpResponse = httpClient.execute(method);

我使用服务器自签名证书。我用

openssl s_client -connect 127.0.0.1:8443/webpage -CAfile test-ca.crt 

连接我的服务器。 test-ca.crt 是我自己 CA 的证书。结果是验证 return 代码为 0(ok)。所以我的服务器工作正常。

捕获的包没问题。 Wireshark 根据(主要)用作源 and/or 目标的端口解码显示 。它知道一些标准端口如 443 和 465 是 SSL/TLS 但它不知道 8443.

在消息列表窗格中右键单击此会话的数据包并选择 DecodeAs...,或 select 一个数据包并单击 Analyze / DecodeAs...。在版本 2 中单击“+” (添加)按钮;然后在必要时调整端口值(到 8443)并在右侧下拉列表(或版本 1 列表框中)select SSL。