org.apache.flink.runtime.io.network.netty.SSLHandlerFactory Java Examples

The following examples show how to use org.apache.flink.runtime.io.network.netty.SSLHandlerFactory. 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: SSLUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication server endpoints.
 */
public static SSLHandlerFactory createInternalServerSSLEngineFactory(final Configuration config) throws Exception {
	SSLContext sslContext = createInternalSSLContext(config);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			getEnabledProtocols(config),
			getEnabledCipherSuites(config),
			false,
			true,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #2
Source File: RestClientConfiguration.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a new {@link RestClientConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST client endpoint configuration should be created from
 * @return REST client endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */

public static RestClientConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestClientSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLContext for the REST client", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final long connectionTimeout = config.getLong(RestOptions.CONNECTION_TIMEOUT);

	final long idlenessTimeout = config.getLong(RestOptions.IDLENESS_TIMEOUT);

	int maxContentLength = config.getInteger(RestOptions.CLIENT_MAX_CONTENT_LENGTH);

	return new RestClientConfiguration(sslHandlerFactory, connectionTimeout, idlenessTimeout, maxContentLength);
}
 
Example #3
Source File: RestServerEndpointConfiguration.java    From flink with Apache License 2.0 6 votes vote down vote up
private RestServerEndpointConfiguration(
		final String restAddress,
		@Nullable String restBindAddress,
		String restBindPortRange,
		@Nullable SSLHandlerFactory sslHandlerFactory,
		final Path uploadDir,
		final int maxContentLength,
		final Map<String, String> responseHeaders) {

	Preconditions.checkArgument(maxContentLength > 0, "maxContentLength must be positive, was: %s", maxContentLength);

	this.restAddress = requireNonNull(restAddress);
	this.restBindAddress = restBindAddress;
	this.restBindPortRange = requireNonNull(restBindPortRange);
	this.sslHandlerFactory = sslHandlerFactory;
	this.uploadDir = requireNonNull(uploadDir);
	this.maxContentLength = maxContentLength;
	this.responseHeaders = Collections.unmodifiableMap(requireNonNull(responseHeaders));
}
 
Example #4
Source File: SSLUtilsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that {@link SSLHandlerFactory} is created correctly.
 */
@Test
public void testCreateSSLEngineFactory() throws Exception {
	Configuration serverConfig = createInternalSslConfigWithKeyAndTrustStores();

	// set custom protocol and cipher suites
	serverConfig.setString(SecurityOptions.SSL_PROTOCOL, "TLSv1");
	serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256");

	final SSLHandlerFactory serverSSLHandlerFactory = SSLUtils.createInternalServerSSLEngineFactory(serverConfig);
	final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler();

	assertEquals(1, sslHandler.engine().getEnabledProtocols().length);
	assertEquals("TLSv1", sslHandler.engine().getEnabledProtocols()[0]);

	assertEquals(2, sslHandler.engine().getEnabledCipherSuites().length);
	assertThat(sslHandler.engine().getEnabledCipherSuites(), arrayContainingInAnyOrder(
			"TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"));
}
 
Example #5
Source File: RestServerEndpointConfiguration.java    From flink with Apache License 2.0 6 votes vote down vote up
private RestServerEndpointConfiguration(
		final String restAddress,
		@Nullable String restBindAddress,
		String restBindPortRange,
		@Nullable SSLHandlerFactory sslHandlerFactory,
		final Path uploadDir,
		final int maxContentLength,
		final Map<String, String> responseHeaders) {

	Preconditions.checkArgument(maxContentLength > 0, "maxContentLength must be positive, was: %s", maxContentLength);

	this.restAddress = requireNonNull(restAddress);
	this.restBindAddress = restBindAddress;
	this.restBindPortRange = requireNonNull(restBindPortRange);
	this.sslHandlerFactory = sslHandlerFactory;
	this.uploadDir = requireNonNull(uploadDir);
	this.maxContentLength = maxContentLength;
	this.responseHeaders = Collections.unmodifiableMap(requireNonNull(responseHeaders));
}
 
Example #6
Source File: SSLUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link SSLHandlerFactory} to be used by the REST Clients.
 *
 * @param config The application configuration.
 */
public static SSLHandlerFactory createRestClientSSLEngineFactory(final Configuration config) throws Exception {
	SSLContext sslContext = createRestClientSSLContext(config);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
	}

	return new SSLHandlerFactory(
			sslContext,
			getEnabledProtocols(config),
			getEnabledCipherSuites(config),
			true,
			isRestSSLAuthenticationEnabled(config),
			-1,
			-1);
}
 
Example #7
Source File: SSLUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link SSLHandlerFactory} to be used by the REST Servers.
 *
 * @param config The application configuration.
 */
public static SSLHandlerFactory createRestServerSSLEngineFactory(final Configuration config) throws Exception {
	SSLContext sslContext = createRestServerSSLContext(config);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
	}

	return new SSLHandlerFactory(
			sslContext,
			getEnabledProtocols(config),
			getEnabledCipherSuites(config),
			false,
			isRestSSLAuthenticationEnabled(config),
			-1,
			-1);
}
 
Example #8
Source File: SSLUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication client endpoints.
 */
public static SSLHandlerFactory createInternalClientSSLEngineFactory(final Configuration config) throws Exception {
	SSLContext sslContext = createInternalSSLContext(config);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			getEnabledProtocols(config),
			getEnabledCipherSuites(config),
			true,
			true,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #9
Source File: RestClientConfiguration.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a new {@link RestClientConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST client endpoint configuration should be created from
 * @return REST client endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */

public static RestClientConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestClientSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLContext for the REST client", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final long connectionTimeout = config.getLong(RestOptions.CONNECTION_TIMEOUT);

	final long idlenessTimeout = config.getLong(RestOptions.IDLENESS_TIMEOUT);

	int maxContentLength = config.getInteger(RestOptions.CLIENT_MAX_CONTENT_LENGTH);

	return new RestClientConfiguration(sslHandlerFactory, connectionTimeout, idlenessTimeout, maxContentLength);
}
 
Example #10
Source File: RestClientConfiguration.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a new {@link RestClientConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST client endpoint configuration should be created from
 * @return REST client endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */

public static RestClientConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestClientSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLContext for the REST client", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final long connectionTimeout = config.getLong(RestOptions.CONNECTION_TIMEOUT);

	final long idlenessTimeout = config.getLong(RestOptions.IDLENESS_TIMEOUT);

	int maxContentLength = config.getInteger(RestOptions.CLIENT_MAX_CONTENT_LENGTH);

	return new RestClientConfiguration(sslHandlerFactory, connectionTimeout, idlenessTimeout, maxContentLength);
}
 
Example #11
Source File: RestServerEndpointConfiguration.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private RestServerEndpointConfiguration(
		final String restAddress,
		@Nullable String restBindAddress,
		String restBindPortRange,
		@Nullable SSLHandlerFactory sslHandlerFactory,
		final Path uploadDir,
		final int maxContentLength,
		final Map<String, String> responseHeaders) {

	Preconditions.checkArgument(maxContentLength > 0, "maxContentLength must be positive, was: %d", maxContentLength);

	this.restAddress = requireNonNull(restAddress);
	this.restBindAddress = restBindAddress;
	this.restBindPortRange = requireNonNull(restBindPortRange);
	this.sslHandlerFactory = sslHandlerFactory;
	this.uploadDir = requireNonNull(uploadDir);
	this.maxContentLength = maxContentLength;
	this.responseHeaders = Collections.unmodifiableMap(requireNonNull(responseHeaders));
}
 
Example #12
Source File: RedirectingSslHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public RedirectingSslHandler(
	@Nonnull String confRedirectHost,
	@Nonnull CompletableFuture<String> redirectBaseUrl,
	@Nonnull SSLHandlerFactory sslHandlerFactory) {
	this.confRedirectBaseUrl = "https://" + confRedirectHost + ":";
	this.redirectBaseUrl = redirectBaseUrl;
	this.sslHandlerFactory = sslHandlerFactory;
}
 
Example #13
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that {@link SSLHandlerFactory} is created correctly.
 */
@Test
public void testCreateSSLEngineFactory() throws Exception {
	Configuration serverConfig = createInternalSslConfigWithKeyAndTrustStores();
	final String[] sslAlgorithms;
	final String[] expectedSslProtocols;
	if (sslProvider.equalsIgnoreCase("OPENSSL")) {
		// openSSL does not support the same set of cipher algorithms!
		sslAlgorithms = new String[] {"TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_256_GCM_SHA384"};
		expectedSslProtocols = new String[] {"SSLv2Hello", "TLSv1"};
	} else {
		sslAlgorithms = new String[] {"TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"};
		expectedSslProtocols = new String[] {"TLSv1"};
	}

	// set custom protocol and cipher suites
	serverConfig.setString(SecurityOptions.SSL_PROTOCOL, "TLSv1");
	serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, String.join(",", sslAlgorithms));

	final SSLHandlerFactory serverSSLHandlerFactory = SSLUtils.createInternalServerSSLEngineFactory(serverConfig);
	final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler(UnpooledByteBufAllocator.DEFAULT);

	assertEquals(expectedSslProtocols.length, sslHandler.engine().getEnabledProtocols().length);
	assertThat(
		sslHandler.engine().getEnabledProtocols(),
		arrayContainingInAnyOrder(expectedSslProtocols));

	assertEquals(sslAlgorithms.length, sslHandler.engine().getEnabledCipherSuites().length);
	assertThat(
		sslHandler.engine().getEnabledCipherSuites(),
		arrayContainingInAnyOrder(sslAlgorithms));
}
 
Example #14
Source File: RestClientConfiguration.java    From flink with Apache License 2.0 5 votes vote down vote up
private RestClientConfiguration(
		@Nullable final SSLHandlerFactory sslHandlerFactory,
		final long connectionTimeout,
		final long idlenessTimeout,
		final int maxContentLength) {
	checkArgument(maxContentLength > 0, "maxContentLength must be positive, was: %s", maxContentLength);
	this.sslHandlerFactory = sslHandlerFactory;
	this.connectionTimeout = connectionTimeout;
	this.idlenessTimeout = idlenessTimeout;
	this.maxContentLength = maxContentLength;
}
 
Example #15
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that REST Server SSL Engine is created given a valid SSL configuration.
 */
@Test
public void testRESTServerSSL() throws Exception {
	Configuration serverConfig = createRestSslConfigWithKeyStore();

	SSLHandlerFactory ssl = SSLUtils.createRestServerSSLEngineFactory(serverConfig);
	assertNotNull(ssl);
}
 
Example #16
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if REST Client SSL is created given a valid SSL configuration.
 */
@Test
public void testRESTClientSSL() throws Exception {
	Configuration clientConfig = createRestSslConfigWithTrustStore();

	SSLHandlerFactory ssl = SSLUtils.createRestClientSSLEngineFactory(clientConfig);
	assertNotNull(ssl);
}
 
Example #17
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link SSLHandlerFactory} to be used by the REST Clients.
 *
 * @param config The application configuration.
 */
public static SSLHandlerFactory createRestClientSSLEngineFactory(final Configuration config) throws Exception {
	ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
	SslContext sslContext = createRestNettySSLContext(config, true, clientAuth);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
	}

	return new SSLHandlerFactory(
			sslContext,
			-1,
			-1);
}
 
Example #18
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
public RestClient(RestClientConfiguration configuration, Executor executor) {
	Preconditions.checkNotNull(configuration);
	this.executor = Preconditions.checkNotNull(executor);
	this.terminationFuture = new CompletableFuture<>();

	final SSLHandlerFactory sslHandlerFactory = configuration.getSslHandlerFactory();
	ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel socketChannel) {
			try {
				// SSL should be the first handler in the pipeline
				if (sslHandlerFactory != null) {
					socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler(socketChannel.alloc()));
				}

				socketChannel.pipeline()
					.addLast(new HttpClientCodec())
					.addLast(new HttpObjectAggregator(configuration.getMaxContentLength()))
					.addLast(new ChunkedWriteHandler()) // required for multipart-requests
					.addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS))
					.addLast(new ClientHandler());
			} catch (Throwable t) {
				t.printStackTrace();
				ExceptionUtils.rethrow(t);
			}
		}
	};
	NioEventLoopGroup group = new NioEventLoopGroup(1, new ExecutorThreadFactory("flink-rest-client-netty"));

	bootstrap = new Bootstrap();
	bootstrap
		.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(configuration.getConnectionTimeout()))
		.group(group)
		.channel(NioSocketChannel.class)
		.handler(initializer);

	LOG.debug("Rest client endpoint started.");
}
 
Example #19
Source File: RedirectingSslHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public RedirectingSslHandler(
	@Nonnull String confRedirectHost,
	@Nonnull CompletableFuture<String> redirectBaseUrl,
	@Nonnull SSLHandlerFactory sslHandlerFactory) {
	this.confRedirectBaseUrl = "https://" + confRedirectHost + ":";
	this.redirectBaseUrl = redirectBaseUrl;
	this.sslHandlerFactory = sslHandlerFactory;
}
 
Example #20
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication server endpoints.
 */
public static SSLHandlerFactory createInternalServerSSLEngineFactory(final Configuration config) throws Exception {
	SslContext sslContext = createInternalNettySSLContext(config, false);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #21
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication client endpoints.
 */
public static SSLHandlerFactory createInternalClientSSLEngineFactory(final Configuration config) throws Exception {
	SslContext sslContext = createInternalNettySSLContext(config, true);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #22
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link SSLHandlerFactory} to be used by the REST Servers.
 *
 * @param config The application configuration.
 */
public static SSLHandlerFactory createRestServerSSLEngineFactory(final Configuration config) throws Exception {
	ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
	SslContext sslContext = createRestNettySSLContext(config, false, clientAuth);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
	}

	return new SSLHandlerFactory(
			sslContext,
			-1,
			-1);
}
 
Example #23
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link SSLHandlerFactory} to be used by the REST Clients.
 *
 * @param config The application configuration.
 */
public static SSLHandlerFactory createRestClientSSLEngineFactory(final Configuration config) throws Exception {
	ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
	SslContext sslContext = createRestNettySSLContext(config, true, clientAuth);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
	}

	return new SSLHandlerFactory(
			sslContext,
			-1,
			-1);
}
 
Example #24
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if REST Client SSL is created given a valid SSL configuration.
 */
@Test
public void testRESTClientSSL() throws Exception {
	Configuration clientConfig = createRestSslConfigWithTrustStore();

	SSLHandlerFactory ssl = SSLUtils.createRestClientSSLEngineFactory(clientConfig);
	assertNotNull(ssl);
}
 
Example #25
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that REST Server SSL Engine is created given a valid SSL configuration.
 */
@Test
public void testRESTServerSSL() throws Exception {
	Configuration serverConfig = createRestSslConfigWithKeyStore();

	SSLHandlerFactory ssl = SSLUtils.createRestServerSSLEngineFactory(serverConfig);
	assertNotNull(ssl);
}
 
Example #26
Source File: SSLUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that {@link SSLHandlerFactory} is created correctly.
 */
@Test
public void testCreateSSLEngineFactory() throws Exception {
	Configuration serverConfig = createInternalSslConfigWithKeyAndTrustStores();
	final String[] sslAlgorithms;
	final String[] expectedSslProtocols;
	if (sslProvider.equalsIgnoreCase("OPENSSL")) {
		// openSSL does not support the same set of cipher algorithms!
		sslAlgorithms = new String[] {"TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_256_GCM_SHA384"};
		expectedSslProtocols = new String[] {"SSLv2Hello", "TLSv1"};
	} else {
		sslAlgorithms = new String[] {"TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"};
		expectedSslProtocols = new String[] {"TLSv1"};
	}

	// set custom protocol and cipher suites
	serverConfig.setString(SecurityOptions.SSL_PROTOCOL, "TLSv1");
	serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, String.join(",", sslAlgorithms));

	final SSLHandlerFactory serverSSLHandlerFactory = SSLUtils.createInternalServerSSLEngineFactory(serverConfig);
	final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler(UnpooledByteBufAllocator.DEFAULT);

	assertEquals(expectedSslProtocols.length, sslHandler.engine().getEnabledProtocols().length);
	assertThat(
		sslHandler.engine().getEnabledProtocols(),
		arrayContainingInAnyOrder(expectedSslProtocols));

	assertEquals(sslAlgorithms.length, sslHandler.engine().getEnabledCipherSuites().length);
	assertThat(
		sslHandler.engine().getEnabledCipherSuites(),
		arrayContainingInAnyOrder(sslAlgorithms));
}
 
Example #27
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication client endpoints.
 */
public static SSLHandlerFactory createInternalClientSSLEngineFactory(final Configuration config) throws Exception {
	SslContext sslContext = createInternalNettySSLContext(config, true);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #28
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SSLEngineFactory to be used by internal communication server endpoints.
 */
public static SSLHandlerFactory createInternalServerSSLEngineFactory(final Configuration config) throws Exception {
	SslContext sslContext = createInternalNettySSLContext(config, false);
	if (sslContext == null) {
		throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
	}

	return new SSLHandlerFactory(
			sslContext,
			config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
			config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
 
Example #29
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
public RestClient(RestClientConfiguration configuration, Executor executor) {
	Preconditions.checkNotNull(configuration);
	this.executor = Preconditions.checkNotNull(executor);
	this.terminationFuture = new CompletableFuture<>();

	final SSLHandlerFactory sslHandlerFactory = configuration.getSslHandlerFactory();
	ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel socketChannel) {
			try {
				// SSL should be the first handler in the pipeline
				if (sslHandlerFactory != null) {
					socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler(socketChannel.alloc()));
				}

				socketChannel.pipeline()
					.addLast(new HttpClientCodec())
					.addLast(new HttpObjectAggregator(configuration.getMaxContentLength()))
					.addLast(new ChunkedWriteHandler()) // required for multipart-requests
					.addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS))
					.addLast(new ClientHandler());
			} catch (Throwable t) {
				t.printStackTrace();
				ExceptionUtils.rethrow(t);
			}
		}
	};
	NioEventLoopGroup group = new NioEventLoopGroup(1, new ExecutorThreadFactory("flink-rest-client-netty"));

	bootstrap = new Bootstrap();
	bootstrap
		.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(configuration.getConnectionTimeout()))
		.group(group)
		.channel(NioSocketChannel.class)
		.handler(initializer);

	LOG.info("Rest client endpoint started.");
}
 
Example #30
Source File: RestClientConfiguration.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private RestClientConfiguration(
		@Nullable final SSLHandlerFactory sslHandlerFactory,
		final long connectionTimeout,
		final long idlenessTimeout,
		final int maxContentLength) {
	checkArgument(maxContentLength > 0, "maxContentLength must be positive, was: %d", maxContentLength);
	this.sslHandlerFactory = sslHandlerFactory;
	this.connectionTimeout = connectionTimeout;
	this.idlenessTimeout = idlenessTimeout;
	this.maxContentLength = maxContentLength;
}