title: Get SSLContext for default system truststore in Java(JSEE)
body: <p>I've been using custom keystore in my program by specifying <strong>javax.net.ssl.keyStore</strong>, <strong>javax.net.ssl.keyStorePassword</strong>, <strong>javax.net.ssl.trustStore</strong>, <strong>javax.net.ssl.trustStorePassword</strong>. My truststore contains self-signed certificates. Now I want to make some https request(say to <a href="https://google.com" rel="noreferrer">https://google.com</a>) and use default jre system trusstore that contains information about different CAs. To make http requests I use OkHttp library. Its client has an option to specify <strong>SslSocketFactory</strong>, but to get it I need to initialise <strong>SSLContext</strong> for default jre truststore. How can I do that?</p>
  
  <p>UPDATE:
  The code I went with is</p>
  
  <pre><code>    KeyStore keyStore = KeyStore.getInstance("JKS");
  
      // load default jvm keystore
      keyStore.load(new FileInputStream(
              System.getProperties()
                    .getProperty("java.home") + File.separator
                  + "lib" + File.separator + "security" + File.separator
                  + "cacerts"), "changeit".toCharArray());
  
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(
              TrustManagerFactory.getDefaultAlgorithm());
  
      tmf.init(keyStore);
  
      SSLContext ctx = SSLContext.getInstance("TLS");
  
      ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
  </code></pre>