如何修复“java.security.cert.CertificateException:No subject alternative names present”错误?

如何修复“java.security.cert.CertificateException:No subject alternative names present”错误?,第1张

如何修复“java.security.cert.CertificateException:No subject alternative names present”错误?

我通过使用此处介绍的方法禁用HTTPS检查来解决此问题:

我将以下代码放入

ISomeService
该类中:

static {    disableSslVerification();}private static void disableSslVerification() {    try    {        // Create a trust manager that does not validate certificate chains        TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() {     return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { }        }        };        // Install the all-trusting trust manager        SSLContext sc = SSLContext.getInstance("SSL");        sc.init(null, trustAllCerts, new java.security.SecureRandom());        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());        // Create all-trusting host name verifier        HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) {     return true; }        };        // Install the all-trusting host verifier        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);    } catch (NoSuchAlgorithmException e) {        e.printStackTrace();    } catch (KeyManagementException e) {        e.printStackTrace();    }}

由于我

https://AAA.BBB.CCC.DDD:9443/ISomeService
仅将它们用于测试目的,所以这是一个足够好的解决方案。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5432009.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存