You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "PakhomovAlexander (via GitHub)" <gi...@apache.org> on 2023/02/10 18:05:01 UTC
[GitHub] [ignite-3] PakhomovAlexander opened a new pull request, #1662: IGNITE-18578 Add SSL for TCP client
PakhomovAlexander opened a new pull request, #1662:
URL: https://github.com/apache/ignite-3/pull/1662
https://issues.apache.org/jira/browse/IGNITE-18578
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104792713
##########
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:
ok, will fix that too
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104414299
##########
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:
Fixed these two. Does it relate to `try (var is = Files.newInputStream(Path.of(ssl.keyStorePath())))`?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104414299
##########
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:
Fixex these two. Does it relate to `try (var is = Files.newInputStream(Path.of(ssl.keyStorePath())))`?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104407901
##########
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 {
+ keyStorePkcs12Path = tmpDir.resolve("keystore.p12").toAbsolutePath().toString();
Review Comment:
No, that is a temp dir provided by Junit 5 infrastructure and it will be removed at the end of the test automatically.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ptupitsyn commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104114678
##########
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();
+ var builder = SslContextBuilder.forClient().trustManager(loadTrustManagerFactory(ssl));
+
+ ClientAuth clientAuth = toNettyClientAuth(ssl.clientAuthenticationMode());
+ if (ClientAuth.NONE != clientAuth) {
+ builder.clientAuth(clientAuth).keyManager(loadKeyManagerFactory(ssl));
+ }
+
+ var context = builder.build();
+
+ ch.pipeline().addFirst("ssl", context.newHandler(ch.alloc()));
+ } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException | UnrecoverableKeyException e) {
+ throw new IgniteException(CLIENT_SSL_CONFIGURATION_ERR, "Client SSL configuration error: " + e.getMessage(), e);
+ }
+
+ }
+
+ @NotNull
+ private static KeyManagerFactory loadKeyManagerFactory(SslConfiguration ssl)
+ throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
+ KeyStore ks = KeyStore.getInstance(ssl.keyStoreType());
+
+ char[] ksPassword = ssl.keyStorePassword() == null ? null : ssl.keyStorePassword().toCharArray();
+ if (ssl.keyStorePath() != null) {
+ try (var is = Files.newInputStream(Path.of(ssl.keyStorePath()))) {
+ ks.load(is, ksPassword);
+ }
+ } else {
+ ks.load(null, ksPassword);
+ }
+
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ keyManagerFactory.init(ks, ksPassword);
+ return keyManagerFactory;
+ }
+
+ @NotNull
+ private static TrustManagerFactory loadTrustManagerFactory(SslConfiguration ssl)
+ throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
+ KeyStore ts = KeyStore.getInstance(ssl.trustStoreType());
+ char[] tsPassword = ssl.trustStorePassword() == null ? null : ssl.trustStorePassword().toCharArray();
+ if (ssl.trustStorePath() != null) {
+ try (var is = Files.newInputStream(Path.of(ssl.trustStorePath()))) {
+ ts.load(is, tsPassword);
+ }
+ } else {
+ ts.load(null, tsPassword);
+ }
+
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
+ TrustManagerFactory.getDefaultAlgorithm()
+ );
+ trustManagerFactory.init(ts);
+ return trustManagerFactory;
+ }
+
+ private ClientAuth toNettyClientAuth(ClientAuthenticationMode igniteClientAuth) {
Review Comment:
```suggestion
private static ClientAuth toNettyClientAuth(ClientAuthenticationMode igniteClientAuth) {
```
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104411457
##########
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:
But I thought that `WorkDirectory` is used as a working directory for Ignite node. Why can't we use the standard unit 5 extension to store some temporary configuration files?
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ptupitsyn merged pull request #1662: IGNITE-18578 Add SSL for Java client
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn merged PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ptupitsyn commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104115943
##########
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;
Review Comment:
Can be converted to a local variable.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104765597
##########
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:
Just for consistency. The only difference between `TempDir` and `WorkDirectory` is that you can keep the generated folder for debugging purposes
##########
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:
yes
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104796392
##########
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:
No problem will use WorkDirectory
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ptupitsyn commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #1662:
URL: https://github.com/apache/ignite-3/pull/1662#discussion_r1104054264
##########
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 {
+ keyStorePkcs12Path = tmpDir.resolve("keystore.p12").toAbsolutePath().toString();
Review Comment:
Should we remove this in `tearDown`?
##########
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:
Rename to `ssl` to be consistent with builder.
##########
modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java:
##########
@@ -260,6 +263,23 @@ public Builder heartbeatTimeout(long heartbeatTimeout) {
return this;
}
+ /**
+ * Sets the SSL configuration.
+ *
+ * @param sslConfiguration SSL configuration.
+ * @return This instance.
+ */
+ public Builder ssl(@Nullable SslConfiguration sslConfiguration) {
+ if (sslConfiguration == null) {
+ this.sslConfiguration = SslConfiguration.builder().build();
Review Comment:
Let's just keep it null, I'm not sure why do we need a default instance in this case.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a diff in pull request #1662: IGNITE-18578 Add SSL for TCP client
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org