public static void setupSSLConfig(String keystoresDir, String sslConfDir, Configuration conf,
    boolean useClientCert) throws Exception {
    String clientKS = keystoresDir + "/clientKS.jks";
    String clientPassword = "clientP";
    String serverKS = keystoresDir + "/serverKS.jks";
    String serverPassword = "serverP";
    String trustKS = keystoresDir + "/trustKS.jks";
    String trustPassword = "trustP";

    File sslClientConfFile = new File(sslConfDir + "/ssl-client-" + System.nanoTime() + "-"
      + HBaseCommonTestingUtil.getRandomUUID() + ".xml");
    File sslServerConfFile = new File(sslConfDir + "/ssl-server-" + System.nanoTime() + "-"
      + HBaseCommonTestingUtil.getRandomUUID() + ".xml");

    Map<String, X509Certificate> certs = new HashMap<>();

    if (useClientCert) {
      KeyPair cKP = KeyStoreTestUtil.generateKeyPair("RSA");
      X509Certificate cCert =
        KeyStoreTestUtil.generateCertificate("CN=localhost, O=client", cKP, 30, "SHA1withRSA");
      KeyStoreTestUtil.createKeyStore(clientKS, clientPassword, "client", cKP.getPrivate(), cCert);
      certs.put("client", cCert);
    }

    KeyPair sKP = KeyStoreTestUtil.generateKeyPair("RSA");
    X509Certificate sCert =
      KeyStoreTestUtil.generateCertificate("CN=localhost, O=server", sKP, 30, "SHA1withRSA");
    KeyStoreTestUtil.createKeyStore(serverKS, serverPassword, "server", sKP.getPrivate(), sCert);
    certs.put("server", sCert);

    KeyStoreTestUtil.createTrustStore(trustKS, trustPassword, certs);

    Configuration clientSSLConf =
      createClientSSLConfig(clientKS, clientPassword, clientPassword, trustKS);
    Configuration serverSSLConf =
      createServerSSLConfig(serverKS, serverPassword, serverPassword, trustKS);

    saveConfig(sslClientConfFile, clientSSLConf);
    saveConfig(sslServerConfFile, serverSSLConf);

    conf.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "ALLOW_ALL");
    conf.set(SSLFactory.SSL_CLIENT_CONF_KEY, sslClientConfFile.getName());
    conf.set(SSLFactory.SSL_SERVER_CONF_KEY, sslServerConfFile.getName());
    conf.set("dfs.https.server.keystore.resource", sslServerConfFile.getName());

    conf.setBoolean(SSLFactory.SSL_REQUIRE_CLIENT_CERT_KEY, useClientCert);
  }
Performs complete setup of SSL configuration in preparation for testing an SSLFactory. This
includes keys, certs, keystores, truststores, the server SSL configuration file, the client SSL
configuration file, and the master configuration file read by the SSLFactory.
@param keystoresDir  String directory to save keystores
@param sslConfDir    String directory to save SSL configuration files
@param conf          Configuration master configuration to be used by an SSLFactory, which will
                     be mutated by this method
@param useClientCert boolean true to make the client present a cert in the SSL handshake
hbase-http/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java