code: public static SSLSocketFactory getSSLSocketFactory(String certificateString) throws CertificateException,
        KeyStoreException, IOException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException {
      byte[] certBytes = parseDERFromPEM(certificateString, CERT_START, CERT_END);
  
      X509Certificate cert = generateCertificateFromDER(certBytes);
      KeyStore keystore = KeyStore.getInstance("JKS");
      keystore.load(null);
      keystore.setCertificateEntry("cert-alias", cert);
  
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(keystore);
      TrustManager[] tm = tmf.getTrustManagers();
      SSLContext context = SSLContext.getInstance("TLS");
  
      context.init(null, tm, null);
  
      return context.getSocketFactory();
    }
docs: This creates an in-memory keystore containing the certificate and initializes the SSLContext with the the trust
  material it contains.
  <p>
  With HttpsURLConnection con, set the connection to use the SSLSocketFactory before {@code con.connect()}: {@code
  con.setSSLSocketFactory(sslSocketFactory)}
  
  @param certificateString the PEM formatted Certificate
  @return a SSLSocketFactory that can be hooked into an HttpsURLConnection via setSSLSocketFactory