私はapache.httpcomponent.httpcoreとhttpclientバージョン4.3を使用していますが、httpclientを使用してhttpsサーバに送信します。 しかし、パケットを捕まえるためにwiresharkを使用すると、パケットはTLSではなくTCPになります。なぜ誰かが私に言うことができますか?Apache HTTPClient(TLSあり)、wiresharkの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の証明書です。結果はベリファイリターンコードが0(ok)になります。だから私のサーバーは仕事です。
ありがとう@dave_thompson_085!できます! –