Returns a new {@link SSLEngine} constructed from the config settings.

@return a {@link SSLEngine} ready to be used.
764424
public SSLEngine get() {
        try {
            String pass = env.sslKeystorePassword();
            char[] password = pass == null || pass.isEmpty() ? null : pass.toCharArray();

            KeyStore ks = env.sslKeystore();
            if (ks == null) {
                String ksFile = env.sslKeystoreFile();
                if (ksFile != null && !ksFile.isEmpty()) {
                    ks = KeyStore.getInstance(KeyStore.getDefaultType());
                    ks.load(new FileInputStream(ksFile), password);
                }
            }

            KeyStore ts = env.sslTruststore();
            if (ts == null) {
                String tsFile = env.sslTruststoreFile();
                if (tsFile != null && !tsFile.isEmpty()) {
                    // filepath found, open and init
                    String tsPassword = env.sslTruststorePassword();
                    char[] tspass = tsPassword == null || tsPassword.isEmpty() ? null : tsPassword.toCharArray();
                    ts = KeyStore.getInstance(KeyStore.getDefaultType());
                    ts.load(new FileInputStream(tsFile), tspass);
                }
            }

            if (ks == null && ts == null) {
                throw new IllegalStateException("Either a KeyStore or a TrustStore " +
                    "need to be provided (or both).");
            } else if (ks == null) {
                ks = ts;
                LOGGER.debug("No KeyStore provided, using provided TrustStore to initialize both factories.");
            } else if (ts == null) {
                ts = ks;
                LOGGER.debug("No TrustStore provided, using provided KeyStore to initialize both factories.");
            }

            String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
            kmf.init(ks, password);
            tmf.init(ts);

            if (!sslContextProtocol.startsWith("TLS")) {
                throw new IllegalArgumentException(
                    "SSLContext Protocol does not start with TLS, this is to prevent "
                        + "insecure protocols (Like SSL*) to be used. Potential candidates "
                        + "are TLS (default), TLSv1, TLSv1.1, TLSv1.2, TLSv1.3 depending on "
                        + "the Java version used.");
            }
            SSLContext ctx = SSLContext.getInstance(sslContextProtocol);
            ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

            SSLEngine engine = ctx.createSSLEngine();
            engine.setUseClientMode(true);
            return engine;
        } catch (Exception ex) {
            throw new SSLException("Could not create SSLEngine.", ex);
        }
    }
179355
public static com.typesafe.config.Config getConfig() {
		if (config == null) {
			init(null);
		}
		return config;
	}
442572
public static SSLContext buildSSLContext(HttpClientConfig config) throws IOException, GeneralSecurityException {

    KeyManagerFactory kmf = null;
    if (isSslKeyManagerEnabled(config)) {
      kmf = getKeyManagerFactory(config.getKeyStorePath(),
          new StoreProperties(config.getKeyStorePassword(), config.getKeyManagerType(),
              config.getKeyStoreType(), config.getKeyStoreProvider()));
    }
    TrustManagerFactory tmf = null;
    if (isSslTrustStoreEnbaled(config)) {
      tmf = getTrustManagerFactory(config.getTrustStorePath(), new StoreProperties(config.getTrustStorePassword(),
          config.getTrustManagerType(), config.getTrustStoreType(), config.getTrustStoreProvider()));
    }

    SSLContext sslContext = SSLContext.getInstance(config.getSslContextType());
    sslContext.init(kmf != null ? kmf.getKeyManagers() : null,
        tmf != null ? tmf.getTrustManagers() : null,
        null);

    return sslContext;
  }
638704
public SSLSocket getSSLSocket() throws KeystoreException, CommunicationException {
		SSLSocketFactory socketFactory = getSSLSocketFactory();
		logger.debug("Creating SSLSocket to " + getServerHost() + ":" + getServerPort());

		try {
			if (ProxyManager.isUsingProxy(server)) {
				return tunnelThroughProxy(socketFactory);
			} else {
				return (SSLSocket) socketFactory.createSocket(getServerHost(), getServerPort());
			}
		} catch (Exception e) {
			throw new CommunicationException("Communication exception: " + e, e);
		}
	}
883848
private static Credentials newNTCredentials(HttpClientSettings settings) {
        return new NTCredentials(settings.getProxyUsername(),
                settings.getProxyPassword(),
                settings.getProxyWorkstation(),
                settings.getProxyDomain());
    }
935979
public SSLEngine initSslEngine(boolean client) throws Exception {
    // Load the keystore
    KeyStore keyStore = loadKeystore(properties.sslKeyStorePath(), properties.sslKeyStorePassword());

    // Setup the keyManager to use our keystore
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, keyStoreKeyPass(properties));

    // Setup the Trust keystore
    KeyStore trustStore;
    if (properties.sslTrustStorePath() != null) {
      // Use the separate Trust keystore
      LOGGER.debug("Using separate trust store");
      trustStore = loadKeystore(properties.sslTrustStorePath(), properties.sslTrustStorePassword());
    } else {
      // Reuse the existing keystore
      trustStore = keyStore;
      LOGGER.debug("Using key store as trust store");
    }

    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(trustStore);

    KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
    TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagers, trustManagers, null);
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(client);
    sslEngine.setWantClientAuth(true);
    sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
    sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
    sslEngine.setEnableSessionCreation(true);

    return sslEngine;
  }
165138
private CloseableHttpClient createHttpClient() throws AzkabanClientException {
    try {
    // SSLSocketFactory using custom TrustStrategy that ignores warnings about untrusted certificates
    // Self sign SSL
    SSLContextBuilder sslcb = new SSLContextBuilder();
    sslcb.loadTrustMaterial(null, (TrustStrategy) new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcb.build());

    HttpClientBuilder builder = HttpClientBuilder.create();
    RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT)
          .setSocketTimeout(10000)
          .setConnectTimeout(10000)
          .setConnectionRequestTimeout(10000)
          .build();

      builder.disableCookieManagement()
          .useSystemProperties()
          .setDefaultRequestConfig(requestConfig)
          .setConnectionManager(new BasicHttpClientConnectionManager())
          .setSSLSocketFactory(sslsf);

      return builder.build();
    } catch (Exception e) {
      throw new AzkabanClientException("HttpClient cannot be created", e);
    }
  }
1143793
public static ServerSocketFactory createSSLServerSocketFactory(Configuration config) throws Exception {
		SSLContext sslContext = createInternalSSLContext(config);
		if (sslContext == null) {
			throw new IllegalConfigurationException("SSL is not enabled");
		}

		String[] protocols = getEnabledProtocols(config);
		String[] cipherSuites = getEnabledCipherSuites(config);

		SSLServerSocketFactory factory = sslContext.getServerSocketFactory();
		return new ConfiguringSSLServerSocketFactory(factory, protocols, cipherSuites);
	}
456687
private static KeyPair newKeyPair() throws Exception {
        KeyPairGenerator kpGen = KeyPairGenerator.getInstance(KEY_ALGORITHM, BC);
        kpGen.initialize(KEY_LENGTH, new SecureRandom());
        return kpGen.generateKeyPair();
    }
165459
public static SSLEngine getOutboundSSLEngine(SSLContext context,
                                                 SSLLinkConfig config, String host, int port, SSLConnectionLink connLink) {
        // PK46069 - use engine that allows session id re-use
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "getOutboundSSLEngine, host=" + host + ", port=" + port);
        }
        SSLEngine engine = context.createSSLEngine(host, port);

        configureEngine(engine, FlowType.OUTBOUND, config, connLink);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "getOutboundSSLEngine, hc=" + engine.hashCode());
        }
        return engine;
    }
606286
public static SocketFactory createSSLClientSocketFactory(Configuration config) throws Exception {
		SSLContext sslContext = createInternalSSLContext(config);
		if (sslContext == null) {
			throw new IllegalConfigurationException("SSL is not enabled");
		}

		return sslContext.getSocketFactory();
	}
892452
@RequestMapping(value = "configurations/create", method = RequestMethod.POST)
    public SVNConfiguration newConfiguration(@RequestBody SVNConfiguration configuration) {
        return svnConfigurationService.newConfiguration(configuration);
    }
1347725
public SSLEngine get() {
    try {
      String pass = env.sslKeystorePassword();
      char[] password = pass == null || pass.isEmpty() ? null : pass.toCharArray();

      KeyStore ks = env.sslKeystore();
      if (ks == null) {
        ks = KeyStore.getInstance(KeyStore.getDefaultType());
        String ksFile = env.sslKeystoreFile();
        if (ksFile == null || ksFile.isEmpty()) {
          throw new IllegalArgumentException("Path to Keystore File must not be null or empty.");
        }
        ks.load(new FileInputStream(ksFile), password);
      }
      String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
      KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
      kmf.init(ks, password);
      tmf.init(ks);

      SSLContext ctx = SSLContext.getInstance("TLS");
      ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

      SSLEngine engine = ctx.createSSLEngine();
      engine.setUseClientMode(true);
      return engine;
    } catch (Exception ex) {
      throw new SSLException("Could not create SSLEngine.", ex);
    }
  }
960791
public HashMap<String, String> ssoTokenGenerator() throws Exception {
        String protocol = "https://";
        HashMap<String, String> cookieToken = new HashMap<>();

        SSLContext sslContext = SSLContext.getInstance("SSL");
        // set up a TrustManager that trusts everything
        sslContext.init(null, ALL_TRUSTING_TRUST_MANAGER, new SecureRandom());
        HttpClientContext context = HttpClientContext.create();
        HttpGet httpGet = new HttpGet(protocol + ssoHost + "/login");
        HttpClient client = HttpClientBuilder.create()
                .setSslcontext(sslContext)
                .setRedirectStrategy(new LaxRedirectStrategy())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setCookieSpec(CookieSpecs.STANDARD).setCircularRedirectsAllowed(true).build()).build();
        try {
            HttpResponse firstResponse = client.execute(httpGet, context);

            logger.debug(firstResponse.getStatusLine().toString());
            Document doc = Jsoup.parse(getStringFromIS(firstResponse.getEntity().getContent()));
            Elements code = doc.select("[name=lt]");
            String loginCode = code.attr("value");
            String executionCode = doc.select("[name=execution]").attr("value");
            for (Header oneHeader : firstResponse.getAllHeaders()) {
                logger.debug(oneHeader.getName() + ":" + oneHeader.getValue());
            }

            URI redirect = context.getRedirectLocations().get(context.getRedirectLocations().size() - 1);

            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("_eventId", "submit"));
            params.add(new BasicNameValuePair("submit", "LOGIN"));
            params.add(new BasicNameValuePair("username", userName));
            params.add(new BasicNameValuePair("password", passWord));

            if (tenant != null) {
                params.add(new BasicNameValuePair("tenant", tenant));
            }

            params.add(new BasicNameValuePair("lt", loginCode));
            params.add(new BasicNameValuePair("execution", executionCode));
            HttpPost httpPost = new HttpPost(redirect);
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse secondResponse = client.execute(httpPost, context);

            for (Header oneHeader : secondResponse.getAllHeaders()) {
                logger.debug(oneHeader.getName() + ":" + oneHeader.getValue());
            }

            HttpGet managementGet = new HttpGet(protocol + ssoHost + managementHost);
            client.execute(managementGet, context);

            for (Cookie oneCookie : context.getCookieStore().getCookies()) {
                logger.debug(oneCookie.getName() + ":" + oneCookie.getValue());
                cookieToken.put(oneCookie.getName(), oneCookie.getValue());
            }

        } catch (Exception e) {
            e.getStackTrace();
        }
        return cookieToken;
    }
1339656
CipherBox newReadCipher() throws NoSuchAlgorithmException {
        BulkCipher cipher = cipherSuite.cipher;
        CipherBox box;
        if (isClient) {
            box = cipher.newCipher(protocolVersion, svrWriteKey, svrWriteIV,
                                   sslContext.getSecureRandom(), false);
            svrWriteKey = null;
            svrWriteIV = null;
        } else {
            box = cipher.newCipher(protocolVersion, clntWriteKey, clntWriteIV,
                                   sslContext.getSecureRandom(), false);
            clntWriteKey = null;
            clntWriteIV = null;
        }
        return box;
    }
145951
static SSLContext createSSLContext() {
    try {
      SSLContext sc = SSLContext.getInstance("SSL");
      TrustManager[] tm = {
          new X509TrustManager() {
            @SuppressLint("TrustAllX509TrustManager") @Override
            public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate,
                String paramString) {
            }

            @SuppressLint("TrustAllX509TrustManager") @Override
            public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate,
                String paramString) {
            }

            @Override public X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[] {};
            }
          }
      };
      sc.init(null, tm, new SecureRandom());
      return sc;
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
      e.printStackTrace();
    }

    return null;
  }
270704
public SSLSocketFactory createSslSocketFactory() {
        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[]{this}, null);
            return sslContext.getSocketFactory();
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            throw new AssertionError(e);
        }
    }