private static SSLFactory createSSLFactory(TlsConfig tlsConfig, boolean insecureMode) {
    return createSSLFactory(
        tlsConfig.getKeyStoreType(), tlsConfig.getKeyStorePath(), tlsConfig.getKeyStorePassword(),
        tlsConfig.getTrustStoreType(), tlsConfig.getTrustStorePath(), tlsConfig.getTrustStorePassword(),
        null, null, true, tlsConfig.isInsecure() || insecureMode);
  }
@Test
  public void swappableSSLFactoryHasSameAsStaticOnes()
      throws NoSuchAlgorithmException, KeyManagementException, IOException, URISyntaxException {
    SecureRandom secureRandom = new SecureRandom();
    KeyManagerFactory keyManagerFactory =
        TlsUtils.createKeyManagerFactory(TLS_KEYSTORE_FILE_PATH, PASSWORD, KEYSTORE_TYPE);
    TrustManagerFactory trustManagerFactory =
        TlsUtils.createTrustManagerFactory(TLS_TRUSTSTORE_FILE_PATH, PASSWORD, TRUSTSTORE_TYPE);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), secureRandom);
    SSLFactory sslFactory =
        RenewableTlsUtils.createSSLFactory(KEYSTORE_TYPE, TLS_KEYSTORE_FILE_PATH, PASSWORD,
            TRUSTSTORE_TYPE, TLS_TRUSTSTORE_FILE_PATH, PASSWORD, "TLS", secureRandom, true, false);
    KeyManagerFactory swappableKeyManagerFactory = sslFactory.getKeyManagerFactory().get();
    assertEquals(swappableKeyManagerFactory.getKeyManagers().length, keyManagerFactory.getKeyManagers().length);
    assertEquals(swappableKeyManagerFactory.getKeyManagers().length, 1);
    assertSSLKeyManagersEqual(swappableKeyManagerFactory.getKeyManagers()[0], keyManagerFactory.getKeyManagers()[0]);
    TrustManagerFactory swappableTrustManagerFactory = sslFactory.getTrustManagerFactory().get();
    assertEquals(swappableTrustManagerFactory.getTrustManagers().length,
        trustManagerFactory.getTrustManagers().length);
    assertEquals(swappableTrustManagerFactory.getTrustManagers().length, 1);
    assertSSLTrustManagersEqual(swappableTrustManagerFactory.getTrustManagers()[0],
        trustManagerFactory.getTrustManagers()[0]);
    SSLContext swappableSSLContext = sslFactory.getSslContext();
    assertEquals(swappableSSLContext.getProtocol(), sslContext.getProtocol());
    assertEquals(swappableSSLContext.getProvider(), sslContext.getProvider());
  }