Created
          July 21, 2023 21:41 
        
      - 
      
 - 
        
Save uchagani/f4566fd6ffe2c93dd52dd559cebb19ac to your computer and use it in GitHub Desktop.  
    Ignore SSL OKHTTP3 Configuration
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Add this when creating an OKHttp3 Client | |
| var trustManager = new IgnoreSslTrustManager[]{new IgnoreSslTrustManager()}; | |
| var sslContext = SSLContext.getInstance("SSL"); | |
| sslContext.init(null, trustManager, new java.security.SecureRandom()); | |
| var okHttpClient = clientBuilder.addInterceptor(new AuthenticationInterceptor()) | |
| .sslSocketFactory(sslContext.getSocketFactory(), trustManager[0]) | |
| .hostnameVerifier((hostname, session) -> true) | |
| .build(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import javax.net.ssl.X509TrustManager; | |
| public class IgnoreSslTrustManager implements X509TrustManager { | |
| @Override | |
| public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { | |
| } | |
| @Override | |
| public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { | |
| } | |
| @Override | |
| public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
| return new java.security.cert.X509Certificate[]{}; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment