ptupitsyn commented on code in PR #1639:
URL: https://github.com/apache/ignite-3/pull/1639#discussion_r1098892187


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientConnectorSslConfigurationSchema.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.configuration;
+
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.ConfigValue;
+import org.apache.ignite.configuration.annotation.Value;
+import 
org.apache.ignite.internal.network.configuration.KeyStoreConfigurationSchema;
+
+/** Client connector ssl configuration schema. */
+@Config
+public class ClientConnectorSslConfigurationSchema {

Review Comment:
   Looks like there is no way to configure client auth 
(https://netty.io/4.1/api/io/netty/handler/ssl/ClientAuth.html), let's add this 
too. Should be disabled by default.



##########
modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/ItSslClientHandlerTest.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.SocketException;
+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.msgpack.core.MessagePack;
+
+/** Ssl client integration test. */
+public class ItSslClientHandlerTest {
+
+    /** Magic bytes. */
+    private static final byte[] MAGIC = {0x49, 0x47, 0x4E, 0x49};
+
+    ClientHandlerModule serverModule;
+
+    TestServer testServer;
+
+    int serverPort;
+
+    String password;
+
+    String keyStorePkcs12Path;
+
+    @BeforeEach
+    void setUp() {
+        password = "changeit";
+        keyStorePkcs12Path = 
ItSslClientHandlerTest.class.getClassLoader().getResource("ssl/keystore.pfx").getPath();
+    }
+
+    @Test
+    @DisplayName("When ssl not configured (by default) the client can connect")
+    void sslNotConfigured(TestInfo testInfo) throws IOException {
+        // Given server started
+        testServer = new TestServer();
+        serverModule = testServer.start(testInfo);
+
+        // Then
+        performAndCheckHandshake();
+    }
+
+    @Test
+    @DisplayName("When ssl configured on the server but not configured on the 
client then exception is thrown")
+    void sslConfiguredOnlyForServer(TestInfo testInfo) {
+        // Given server started
+        testServer = new TestServer(
+                TestSslConfig.builder()
+                        .keyStorePath(keyStorePkcs12Path)
+                        .keyStorePassword(password)
+                        .build()
+        );
+        serverModule = testServer.start(testInfo);
+
+        // Then
+        assertThrows(SocketException.class, this::performAndCheckHandshake);
+    }
+
+    private void performAndCheckHandshake() throws IOException {
+        serverPort = serverModule.localAddress().getPort();
+
+        try (var sock = new Socket("127.0.0.1", serverPort)) {
+            OutputStream out = sock.getOutputStream();
+
+            // Magic: IGNI
+            out.write(MAGIC);
+
+            // Handshake.
+            var packer = MessagePack.newDefaultBufferPacker();
+            packer.packInt(0);
+            packer.packInt(0);
+            packer.packInt(0);
+            packer.packInt(7); // Size.
+
+            packer.packInt(3); // Major.
+            packer.packInt(0); // Minor.
+            packer.packInt(0); // Patch.
+
+            packer.packInt(2); // Client type: general purpose.
+
+            packer.packBinaryHeader(0); // Features.
+            packer.packMapHeader(0); // Extensions.
+
+            out.write(packer.toByteArray());
+            out.flush();
+
+            // Read response.
+            var unpacker = 
MessagePack.newDefaultUnpacker(sock.getInputStream());
+            var magic = unpacker.readPayload(4);
+            unpacker.skipValue(3); // LE int zeros.
+            var len = unpacker.unpackInt();
+            var major = unpacker.unpackInt();
+            var minor = unpacker.unpackInt();
+            var patch = unpacker.unpackInt();
+            var success = unpacker.tryUnpackNil();
+            assertTrue(success);
+
+            var idleTimeout = unpacker.unpackLong();
+            var nodeId = unpacker.unpackString();
+            var nodeName = unpacker.unpackString();
+            unpacker.skipValue(); // Cluster id.
+
+            var featuresLen = unpacker.unpackBinaryHeader();
+            unpacker.skipValue(featuresLen);
+
+            var extensionsLen = unpacker.unpackMapHeader();
+            unpacker.skipValue(extensionsLen);
+
+            assertArrayEquals(MAGIC, magic);
+            assertEquals(44, len);
+            assertEquals(3, major);
+            assertEquals(0, minor);
+            assertEquals(0, patch);
+            assertEquals(0, idleTimeout);
+            assertEquals("id", nodeId);
+            assertEquals("consistent-id", nodeName);

Review Comment:
   We expect this code to fail, I think most of it is unnecessary. Magic header 
should be enough to trigger disconnect due to SSL handshake error.



-- 
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]

Reply via email to