Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1013484 // disableCertificateValidation

JavaX fragment (include)

import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

static volatile bool disableCertificateValidation_attempted;

static void disableCertificateValidation() ctex {
  if (disableCertificateValidation_attempted) ret;
  set disableCertificateValidation_attempted;
  print("Disabling certificate validation for whole VM");
  
  pcall {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { 
      new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() { 
          return new X509Certificate[0]; 
        }
        public void checkClientTrusted(X509Certificate[] certs, String authType) {}
        public void checkServerTrusted(X509Certificate[] certs, String authType) {}
    }};
  
    // Ignore differences between given hostname and certificate hostname
    HostnameVerifier hv = new HostnameVerifier() {
      public boolean verify(String hostname, SSLSession session) { return true; }
    };
  
    // Install the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
  }
}

Author comment

from https://stackoverflow.com/questions/875467/java-client-certificates-over-https-ssl

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1013484
Snippet name: disableCertificateValidation
Eternal ID of this version: #1013484/5
Text MD5: acd2e6fa3f4c34fa66d336a119898b2d
Author: stefan
Category: javax / ssl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-06 15:47:11
Source code size: 1366 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 437 / 489
Version history: 4 change(s)
Referenced in: [show references]