Java Code Examples for javax.net.ssl.SSLContext#getDefaultSSLParameters()

The following examples show how to use javax.net.ssl.SSLContext#getDefaultSSLParameters() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Client createHttpClient(Config config) {
  boolean isSSLEnabled = config.getBoolean(SSL_ENABLED);
  SSLContext sslContext = null;
  SSLParameters sslParameters = null;

  if (isSSLEnabled) {
    sslContext = SSLContextFactory.createInstance(config);
    sslParameters = sslContext.getDefaultSSLParameters();
  }
  Map<String, Object> properties = new HashMap<>();
  properties.put(HttpClientFactory.HTTP_SSL_CONTEXT, sslContext);
  properties.put(HttpClientFactory.HTTP_SSL_PARAMS, sslParameters);

  if (config.hasPath(PROPERTIES)) {
    properties.putAll(toMap(config.getConfig(PROPERTIES)));
  }

  return new R2HttpClientProxy(new HttpClientFactory(), properties);
}
 
Example 2
Source Project: pulsar   File: SecurityUtility.java    License: Apache License 2.0 5 votes vote down vote up
public static SSLContext createSslContext(boolean allowInsecureConnection, Certificate[] trustCertficates,
        Certificate[] certificates, PrivateKey privateKey) throws GeneralSecurityException {
    KeyStoreHolder ksh = new KeyStoreHolder();
    TrustManager[] trustManagers = null;
    KeyManager[] keyManagers = null;

    trustManagers = setupTrustCerts(ksh, allowInsecureConnection, trustCertficates);
    keyManagers = setupKeyManager(ksh, privateKey, certificates);

    SSLContext sslCtx = SSLContext.getInstance("TLS");
    sslCtx.init(keyManagers, trustManagers, new SecureRandom());
    sslCtx.getDefaultSSLParameters();
    return sslCtx;
}
 
Example 3
Source Project: j2objc   File: SSLConfigurationAsserts.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the provided {@link SSLContext} has the expected default configuration, and that
 * {@link SSLSocketFactory}, {@link SSLServerSocketFactory}, {@link SSLSocket},
 * {@link SSLServerSocket} and {@link SSLEngine} instances created from the context match the
 * configuration.
 */
public static void assertSSLContextDefaultConfiguration(SSLContext sslContext)
    throws IOException {
  SSLParameters defaultParameters = sslContext.getDefaultSSLParameters();
  StandardNames.assertSSLContextEnabledProtocols(sslContext.getProtocol(),
      defaultParameters.getProtocols());
  StandardNames.assertDefaultCipherSuites(defaultParameters.getCipherSuites());
  assertFalse(defaultParameters.getWantClientAuth());
  assertFalse(defaultParameters.getNeedClientAuth());

  SSLParameters supportedParameters = sslContext.getSupportedSSLParameters();
  StandardNames.assertSupportedCipherSuites(supportedParameters.getCipherSuites());
  StandardNames.assertSupportedProtocols(supportedParameters.getProtocols());
  assertFalse(supportedParameters.getWantClientAuth());
  assertFalse(supportedParameters.getNeedClientAuth());

  assertContainsAll("Unsupported enabled cipher suites", supportedParameters.getCipherSuites(),
      defaultParameters.getCipherSuites());
  assertContainsAll("Unsupported enabled protocols", supportedParameters.getProtocols(),
      defaultParameters.getProtocols());

  assertSSLSocketFactoryConfigSameAsSSLContext(sslContext.getSocketFactory(), sslContext);
  assertSSLServerSocketFactoryConfigSameAsSSLContext(sslContext.getServerSocketFactory(),
      sslContext);

  SSLEngine sslEngine = sslContext.createSSLEngine();
  assertFalse(sslEngine.getUseClientMode());
  assertSSLEngineConfigSameAsSSLContext(sslEngine, sslContext);
}