sashapolo commented on code in PR #1662: URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104279871
########## modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/ItSslClientHandlerTest.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.client.handler; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import io.netty.handler.ssl.util.SelfSignedCertificate; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.Socket; +import java.net.SocketException; +import java.nio.file.Path; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.io.TempDir; +import org.msgpack.core.MessagePack; + +/** SSL client integration test. */ +public class ItSslClientHandlerTest { + + /** Magic bytes. */ + private static final byte[] MAGIC = {0x49, 0x47, 0x4E, 0x49}; + + private ClientHandlerModule serverModule; + + private TestServer testServer; + + private int serverPort; + + private String keyStorePkcs12Path; + + @BeforeEach + void setUp(@TempDir Path tmpDir) throws Exception { Review Comment: We don't use `@TempDir` anywhere and usually use `@WorkDirectory` instead ########## modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java: ########## @@ -198,17 +200,24 @@ protected void initChannel(Channel ch) { ch.pipeline().addLast(new IdleChannelHandler()); } - ch.pipeline().addLast( - new ClientMessageDecoder(), - new ClientInboundMessageHandler( - igniteTables, - igniteTransactions, - queryProcessor, - configuration, - igniteCompute, - clusterService, - sql, - clusterId)); + if (configuration.ssl().enabled()) { + SslContext sslContext = SslContextProvider.createServerSslContext(configuration.ssl()); + + ch.pipeline().addFirst("ssl", sslContext.newHandler(ch.alloc())); + } + + ch.pipeline() + .addLast( Review Comment: This formatting is little bit weird, I think that the previous version was better ########## modules/client/src/main/java/org/apache/ignite/client/IgniteClientConfiguration.java: ########## @@ -141,4 +141,14 @@ public interface IgniteClientConfiguration { * @return Configured logger factory. */ @Nullable LoggerFactory loggerFactory(); + + /** + * Returns the client SSL configuration. This configuration will be used to setup the SSL connection with + * the Ignite 3 nodes. + * + * <p>When {@code null} then no SSL is used. + * + * @return Client SSL configuration. + */ + SslConfiguration sslConfiguration(); Review Comment: Should be `@Nullable` ########## modules/client/src/main/java/org/apache/ignite/internal/client/io/netty/NettyClientConnectionMultiplexer.java: ########## @@ -75,6 +94,77 @@ public void initChannel(SocketChannel ch) { } } + private void setupSsl(SocketChannel ch, IgniteClientConfiguration clientCfg) { + if (clientCfg.sslConfiguration() == null || !clientCfg.sslConfiguration().enabled()) { + return; + } + + try { + var ssl = clientCfg.sslConfiguration(); Review Comment: These usages of `var` contradict the code style ########## modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.client.handler; + +import static org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL; +import static org.mockito.Answers.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; + +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.client.handler.configuration.ClientConnectorConfiguration; +import org.apache.ignite.compute.IgniteCompute; +import org.apache.ignite.internal.configuration.ConfigurationManager; +import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage; +import org.apache.ignite.internal.network.configuration.NetworkConfiguration; +import org.apache.ignite.internal.sql.engine.QueryProcessor; +import org.apache.ignite.internal.table.IgniteTablesInternal; +import org.apache.ignite.network.ClusterService; +import org.apache.ignite.network.NettyBootstrapFactory; +import org.apache.ignite.sql.IgniteSql; +import org.apache.ignite.tx.IgniteTransactions; +import org.junit.jupiter.api.TestInfo; +import org.mockito.Mockito; + +/** Test server that can be started with SSL configuration. */ +public class TestServer { + private final ConfigurationManager configurationManager; + + private NettyBootstrapFactory bootstrapFactory; + + private final TestSslConfig testSslConfig; + + TestServer(TestSslConfig testSslConfig) { Review Comment: This parameter and field should be marked as `@Nullable` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
