简体   繁体   English

为什么我得到一个异常javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份验证?

[英]Why am I getting an exception javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated?

I'm using Apache HttpComponents HttpClient(4.0.1) to make a HTTPS call, but I'm this exception as the response: 我正在使用Apache HttpComponents HttpClient(4.0.1)进行HTTPS调用,但我将此异常作为响应:

 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
        at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:345)
        at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
        at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
        at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
        at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:561)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)

I provided all the required paramters. 我提供了所有必需的参数。 The destination system doesn't require any user name/password or proxy, but it contains JKS csrtificates that are installed in server. 目标系统不需要任何用户名/密码或代理,但它包含安装在服务器中的JKS证书。 The user name and passwords are blank values. 用户名和密码是空值。

This is working with org.apache.commons.httpclient.methods.PostMethod - Version 3.0 - commons-httpclient-3.0.jar Now we have implemented with org.apache.http.client.methods.HttpPost - Version 4.0.1 - commons-httpclient.jar 这与org.apache.commons.httpclient.methods.PostMethod一起使用 - 版本3.0 - commons-httpclient-3.0.jar现在我们已经用org.apache.http.client.methods.HttpPost实现了 - 版本4.0.1 - commons- httpclient.jar

This is the sample code snippet which is not working: 这是不起作用的示例代码段:

HttpParams param = new BasicHttpParams();
HttpProtocolParams.setVersion(param, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(param, "UTF-8");
HttpProtocolParams.setUseExpectContinue(param, true);
DefaultHttpClient httpClient = new DefaultHttpClient(param);
httpClient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT,10000)));
httpClient.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT,10000)));
httpClient.getCredentialsProvider().setCredentials(new AuthScope(<HOST IP,PORT)),
    AuthScope.ANY_REALM),
    new UsernamePasswordCredentials("", ""));

try {
HttpPost httpPost = new HttpPost(END POINT URL);
StringEntity requestEntity = new StringEntity(inputString, "text/xml", "UTF-8");
httpPost.setEntity(requestEntity);
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
if (null != responseEntity) 
{
    responseBody = EntityUtils.toString(responseEntity);
}
if (null != httpPost.getURI()) {
    url = httpPost.getURI().toString();
}
} catch (IOException e) {
    e.printStackTrace();
} finally {
   httpClient.getConnectionManager().shutdown();
}

The exception message 异常消息

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份验证

doesn't always indicate the root cause of the issue. 并不总是表明问题的根本原因。 You may need to enable the SSL handshake debug by adding theJava VM parameter -Djavax.net.debug=ssl:handshake . 您可能需要通过添加Java VM参数-Djavax.net.debug=ssl:handshake来启用SSL握手调试。 Once you've added that you will get more helpful error messages. 添加完成后,您将收到更多有用的错误消息。 If the remote server uses a certificate that is not trusted you will see the following error message: 如果远程服务器使用不受信任的证书,您将看到以下错误消息:

javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

If that is the case then the answer by @Abhishek will solve the issue. 如果是这种情况,那么@Abhishek的答案将解决问题。

as mentioned above either you import the certificate 如上所述,您要么导入证书

  1. Start command prompt in directory which you have placed certificate (eg XYZ.cer) 在已放置证书的目录中启动命令提示符(例如XYZ.cer)
  2. Run following command just change the active jre path (and please notice ~ symbol ) 运行以下命令只需更改活动的jre路径(请注意〜符号)
  3. keytool -import -alias XYZ -file XYZ.cer -keystore C:/Program~1/Java/jdk1.6.0_23/jre/lib/security/cacerts -storepass changeit keytool -import -alias XYZ -file XYZ.cer -keystore C:/Program~1/Java/jdk1.6.0_23/jre/lib/security/cacerts-storepass changeit

      OR 

use your own trust manager http://tech.chitgoks.com/2011/04/24/how-to-avoid-javax-net-ssl-sslpeerunverifiedexception-peer-not-authenticated-problem-using-apache-httpclient/ 使用您自己的信托经理http://tech.chitgoks.com/2011/04/24/how-to-avoid-javax-net-ssl-sslpeerunverifiedexception-peer-not-authenticated-problem-using-apache-httpclient/

Any SSL connection issue can result in this error. 任何SSL连接问题都可能导致此错误。

One of my solution is upgrade java from 6 to 8. Our problem is the server we meant to communicate is stop supporting TLS 1.0. 我的一个解决方案是将java从6升级到8.我们的问题是我们打算通信的服务器是停止支持TLS 1.0。 And java 6 does not support upper version of TLS 1.0. 而java 6不支持TLS 1.0的上层版本。 After update Java (even without upgrade dropwizard) it works. 更新Java(即使没有升级dropwizard)它的工作原理。

Make sure that the server URL is supposed to use https instead of http. 确保服务器URL应该使用https而不是http。 You can get this error trying to set up a secure connection to an http URL. 尝试建立与http URL的安全连接时,您可能会收到此错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异常:javax.net.ssl.SSLPeerUnverifiedException:对等端未经过身份验证 - Exception : javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Apache HttpClient错误:javax.net.ssl.SSLPeerUnverifiedException:对等方未通过身份验证 - Apache HttpClient Error: javax.net.ssl.SSLPeerUnverifiedException: Peer Not Authenticated Java 8 javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份验证,但不是Java 7 - Java 8 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated, but not Java 7 javax.net.ssl.SSLPeerUnverifiedException:未在Tomcat中使用Apache HttpClient对等体进行身份验证 - javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated in Tomcat with Apache HttpClient javax.net.ssl.SSLPeerUnverifiedException:在netbeans中未对等身份验证 - javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated in netbeans JDK 11. javax.net.ssl.SSLPeerUnverifiedException:对等方未通过身份验证 - JDK 11. javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Java - javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份验证 - Java - javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated javax.net.ssl.SSLPeerUnverifiedException:仅在生产服务器上未对等身份验证 - javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated only on production server 如何使用Java解决Rally Rest api中的javax.net.ssl.SSLPeerUnverifiedException:对等体未通过身份验证的异常? - How to solve javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Exception in Rally Rest api using java? 我得到了javax.net.ssl.SSLPeerUnverifiedException:peer在我的JUnit测试中未经过身份验证 - I got javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated on my JUnit test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM