class SSLUtils {

  private static final Logger LOG = LoggerFactory.getLogger(SSLUtils.class);

  private SSLUtils() {
    //Utility
  }

  public static boolean isHttpsAvailable(Config config) {
    HttpsURLConnection conn = null;
    try {
      URL url = new URL(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl());
      conn = (HttpsURLConnection) url.openConnection();

      SSLContext sslContext = SSLUtils.sslContext(config);
      conn.setSSLSocketFactory(sslContext.getSocketFactory());
      conn.setConnectTimeout(1000);
      conn.setReadTimeout(1000);
      conn.connect();
      return true;
    } catch (Throwable t) {
      LOG.warn("SSL handshake failed. Falling back to insecure connection.");
    } finally {
      if (conn != null) {
        conn.disconnect();
      }
    }
    return false;
  }

  public static SSLContext sslContext(Config config) throws CertificateException, UnrecoverableKeyException,
      NoSuchAlgorithmException, KeyStoreException, IOException, InvalidKeySpecException, KeyManagementException {
    return sslContext(keyManagers(config), trustManagers(config));
  }

  public static SSLContext sslContext(KeyManager[] keyManagers, TrustManager[] trustManagers) {
    SSLContext sslContext = null;
    NoSuchAlgorithmException noSuch = null;
    // v1.3 is not supported on all vms, and of course there may be later versions added.
    // so try to find one starting with the latest
    for (TlsVersion version : TlsVersion.values()) {
      try {
        sslContext = SSLContext.getInstance(version.javaName());
        break;
      } catch (NoSuchAlgorithmException e) {
        if (noSuch == null) {
          noSuch = e;
        }
        continue;
      }
    }

    if (sslContext == null) {
      throw KubernetesClientException.launderThrowable(noSuch);
    }

    try {
      sslContext.init(keyManagers, trustManagers, new SecureRandom());
      return sslContext;
    } catch (KeyManagementException e) {
      throw KubernetesClientException.launderThrowable(e);
    }
  }

  public static TrustManager[] trustManagers(Config config)
      throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
    return trustManagers(config.getCaCertData(), config.getCaCertFile(), config.isTrustCerts(), config.getTrustStoreFile(),
        config.getTrustStorePassphrase());
  }

  public static TrustManager[] trustManagers(String certData, String certFile, boolean isTrustCerts, String trustStoreFile,
      String trustStorePassphrase) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore trustStore = null;
    if (isTrustCerts) {
      return new TrustManager[] {
          new X509ExtendedTrustManager() {
            @Override
            public void checkClientTrusted(X509Certificate[] chain, String s) {
              //not needed
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String s) {
              //not needed
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[0];
            }

            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket)
                throws CertificateException {
              //not needed
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket)
                throws CertificateException {
              //not needed
            }

            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine)
                throws CertificateException {
              //not needed
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine)
                throws CertificateException {
              //not needed
            }
          }
      };
    } else if (Utils.isNotNullOrEmpty(certData) || Utils.isNotNullOrEmpty(certFile)) {
      trustStore = createTrustStore(certData, certFile, trustStoreFile, trustStorePassphrase);
    }
    tmf.init(trustStore);
    return tmf.getTrustManagers();
  }

  public static KeyManager[] keyManagers(Config config) throws NoSuchAlgorithmException, UnrecoverableKeyException,
      KeyStoreException, CertificateException, InvalidKeySpecException, IOException {
    return keyManagers(config.getClientCertData(), config.getClientCertFile(), config.getClientKeyData(),
        config.getClientKeyFile(), config.getClientKeyAlgo(), config.getClientKeyPassphrase(), config.getKeyStoreFile(),
        config.getKeyStorePassphrase());
  }

  public static KeyManager[] keyManagers(String certData, String certFile, String keyData, String keyFile, String algo,
      String passphrase, String keyStoreFile, String keyStorePassphrase) throws NoSuchAlgorithmException,
      UnrecoverableKeyException, KeyStoreException, CertificateException, InvalidKeySpecException, IOException {<FILL_FUNCTION_BODY>}

  public static KeyManager[] keyManagers(InputStream certInputStream, InputStream keyInputStream, String algo,
      String passphrase, String keyStoreFile, String keyStorePassphrase) throws NoSuchAlgorithmException,
      UnrecoverableKeyException, KeyStoreException, CertificateException, InvalidKeySpecException, IOException {
    KeyStore keyStore = createKeyStore(certInputStream, keyInputStream, algo, passphrase.toCharArray(), keyStoreFile,
        keyStorePassphrase.toCharArray());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keyStore, passphrase.toCharArray());
    return kmf.getKeyManagers();
  }
}

    KeyManager[] keyManagers = null;
    if ((Utils.isNotNullOrEmpty(certData) || Utils.isNotNullOrEmpty(certFile))
        && (Utils.isNotNullOrEmpty(keyData) || Utils.isNotNullOrEmpty(keyFile))) {
      KeyStore keyStore = createKeyStore(certData, certFile, keyData, keyFile, algo, passphrase, keyStoreFile,
          keyStorePassphrase);
      KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(keyStore, passphrase.toCharArray());
      keyManagers = kmf.getKeyManagers();
    }
    return keyManagers;
  
<no_super_class>