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

The following examples show how to use javax.net.ssl.SSLContext#getDefaultSSLParameters() . 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
Source File: R2ClientFactory.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
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 File: SecurityUtility.java    From pulsar with 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 File: SSLConfigurationAsserts.java    From j2objc with 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);
}