3
私は何の問題もなく、次のcurlコマンドを作ることができています:カールcacert相当
curl -s --cacert cert_ca.pem -X POST --data-urlencode name=abcde https://abcd.com/resource
あなたは私が同じことを達成するためにJavaで何かを考え出す助けることはできますか?私は同様の投稿を見てきましたが、彼らは完全なSSLハンドシェイクについて話します。ここでは、指定した証明書ファイルを使用してピアを検証するためのCA証明書を提示しています。
もう1つの質問は正しいですか?>ここでは、私の代わりに証明書を提示していないため、ピア証明書を検証するためにCA証明書でtruststoreを設定する必要があります。私は次の例外を取得しています
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(new File("test_ca.jks")
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
String openEndpoint = "URL";
HttpPost httpPost = new HttpPost(openEndpoint);
httpPost.setEntity(new UrlEncodedFormEntity(reqBodyParams));
CloseableHttpResponse httpResponse = (CloseableHttpResponse) httpClient.execute(httpPost);
:
は、私は次のコードでロバートの提案をしようとする際にもCA証明書のためのJKSファイルを持っているあなたに
ありがとう
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1769)
at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:124)
at sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:1130)
at sun.security.ssl.ClientHandshaker.sendChangeCipherAndFinish(ClientHandshaker.java:1216)
at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:1128)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:348)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
私は 'javax.net.ssl.SSLException取得しています:受信致命的な警告:sun.security.ssl.Alerts.getSSLExceptionでunexpected_message \tを(Alerts.java :208) 私は、唯一の違いであるトラストマテリアルをロードする際にパスワードを指定しません。ここで間違いが何であるか分かりません – user3688037
コメントにコードを入れないでください。全く読めません。代わりに質問を編集してください。 SOはフォーラムではありません! – Robert
私の謝罪、私は私の変更と私が見ている結果で質問を更新しました。例外は冗長ではなく、有用な情報は私にはありません。 私のcurlコマンドでわかるように、私はちょうどCA certを指定して電話をかけ、それが動作します。私は同じようにjavaを使用して達成することができるはずです。ここに誤解がある場合はお知らせください – user3688037