javax.net.ssl.SSLException: hostname in certificate didn't match:

每个协议有自己的一套SSL东西,Android 链接https经常会抛出如下错误

 javax.net.ssl.SSLException: hostname in certificate didn't match: <test.rigbee.cn> != <rigbee.cn> OR <rigbee.cn> OR <www.rigbee.cn>
 	at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185)
 	at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
 	at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
 	at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:95)
 	at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
 	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
 	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
 	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

如果使用org.apache.http,修改主机名验证解决问题

import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.SSLSocketFactory;  
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier()); 

如果使用原生URLConnect的话添加如下设置

try {
    SSLContext sc = SSLContext.getInstance("TLS");
    sc.init(null, new TrustManager[] { new X509TrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }  

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType)  

        throws CertificateException {
        }  

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } }, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String arg0, SSLSession arg1) {
            return true;
        }
    });
} catch (Exception e) {
    e.printStackTrace();
}  

版权声明:本文为博主原创文章,未经博主允许不得转载。

javax.net.ssl.SSLException: hostname in certificate didn't match:

时间: 2024-10-12 22:07:42

javax.net.ssl.SSLException: hostname in certificate didn't match:的相关文章

微信证书 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

这几天在做微信退款接口,按照api写完之后,在本地测试了下没有问题,于是交给测试让他们在测试环境开测.他们说退款没有成功,感觉去查日志,发现后台报了 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty .退款证书没

android 5.0 SSL Socket exception javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

更新到最新版本的android 5.0版本 测试我的app,当我使用 api调用 Https 访问的时候报如下的错误. javax.net.ssl.SSLPeerUnverifiedException: No peer certificate 11-26 15:35:01.919: W/System.err(353): at com.android.org.conscrypt.SSLNullSession.getPeerCertificates(SSLNullSession.java:104)

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection

客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证 1.SSL单向验证时 代码如下: Java代码   import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.a

javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair 问题解决

原文出处:https://www.cnblogs.com/yinliang/p/9929595.html       亲测有效 解决这个异常的重点就在于下载两个jar包: bcprov-ext-jdk15on-1.52 bcprov-jdk15on-1.52 传送门:https://pan.baidu.com/s/1c563m9gR-t1v9X-qYfE9EA    提取码vsuj 然后下载完毕之后就需要将这两个jar包放到 $JAVA_HOME/jre/lib/ext放在指定的目录下之后,接下

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

使用HttpClient4.3 调用https出现如下错误: 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

解决 Java 调用 Azure SDK 证书错误 javax.net.ssl.SSLHandshakeException

Azure 作为微软的公有云平台,提供了非常丰富的 SDK 和 API 让开发人员可以非常方便的调用的各项服务,目前除了自家的 .NET.Java.Python. nodeJS.Ruby,PHP 等语言都提供支持,详细的文档说明请参考: https://azure.microsoft.com/en-us/documentation/ 然而在使用过程中,以 Java 语言为例,在初始调用 Azure SDK/API 的时候大家会碰到类似下面的错误: [WARN] ServiceBusContrac

jvax.net.ssl.SSLException: 异常解决

后台报错抛出异常:javax.net.ssl.SSLException: Server selected improper ciphersuite SSL_RSA_WITH_DES_CBC_SHAat sun.security.ssl.Alerts.getSSLException(Unknown Source)at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)at sun.security.ssl.Handshaker.fatalSE(

javax.net.ssl.SSLHandshakeException(Cas导入证书)

一.报错: javax.net.ssl.SSLHandshakeException 二.原因分析:CAS部署时,常常要涉及到HTTPS的证书发布问题.由于在实验环境中,CAS和应用服务常常是共用一台PC机,它们跑在相同的JRE环境和Tomcat服务器上,因此忽略了证书的实际用途,一旦将CAS和应用分别部署在不同的机器上时,就晕了! 这里假设如下实验环境来说明相应的部署  机器A: 部署CAS服务  机器B: 部署OA应用 机器C: 用户浏览器端 1.由机器A上生成.keystore的证书文件,证

转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案 这个是jdk导致的,jdk里面有一个jce的包,安全性机制导致的访问https会报错,官网上有替代的jar包,换掉就好了 目录 %JAVA_HOME%\jre\lib\security里的local_policy.jar,US_export_policy.jar JDK7 http://www.oracle.com/technetwo