Spring Boot忽略https证书:No subject alternative names present

来源:互联网 发布:windows redis自启动 编辑:程序博客网 时间:2024/06/08 18:06
  • 在启动时候调用:
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();       }   }
原创粉丝点击