SpringBoot忽略https证书:No subject alternative names present

  • 在启动时候调用:
  • 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();
           }
       }

     

 

 

如果我的文章有帮助到您,欢迎打赏一下鼓励博主。

SpringBoot忽略https证书:No subject alternative names present_第1张图片

你可能感兴趣的:(SpringBoot忽略https证书:No subject alternative names present)