javax.net.ssl.SSLPeerUnverifiedException: Host name 'xxx' does not match the

javax.net.ssl.SSLPeerUnverifiedException: Host name ‘xxx’ does not match the certificate subject provided by the peer (CN=*.lenovo.com, OU=ITS, O=Lenovo (Beijing) Limited, L=Beijing, C=CN)

原因是对ssl链接中的证书做了验证
需要在代码中屏蔽对ssl链接的证书验证

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,你遇到的问题是javax.net.ssl.SSLException: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty。这个错误通常是由于缺少信任锚点导致的。信任锚点是用于验证SSL证书的根证书。解决这个问题的方法是确保信任锚点参数不为空。 以下是一种解决方法: ```java import.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; public class CustomTrustManager implements X509TrustManager { private X509TrustManager defaultTrustManager; public CustomTrustManager() throws Exception { // 获取默认的信任管理器 TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); for (TrustManager trustManager : trustManagers) { if (trustManager instanceof X509TrustManager) { defaultTrustManager = (X509TrustManager) trustManager; return; } } throw new Exception("Failed to initialize default trust manager."); } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { defaultTrustManager.checkClientTrusted(chain, authType); } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { if (chain == null || chain.length == 0) { throw new CertificateException("No certificates found in the chain."); } defaultTrustManager.checkServerTrusted(chain, authType); } @Override public X509Certificate[] getAcceptedIssuers() { return defaultTrustManager.getAcceptedIssuers(); } } ``` 你可以使用上述代码创建一个自定义的信任管理器,并将其设置为SSL上下文的信任管理器。这样就可以解决javax.net.ssl.SSLException: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值