You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "isapego (via GitHub)" <gi...@apache.org> on 2025/06/24 05:48:21 UTC

[PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

isapego opened a new pull request, #6102:
URL: https://github.com/apache/ignite-3/pull/6102

   https://issues.apache.org/jira/browse/IGNITE-25745
   
   - Added support for SSL;
   - Added tests.


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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163019164


##########
modules/platforms/cpp/tests/odbc-test/ssl_test.cpp:
##########
@@ -0,0 +1,264 @@
+/*
+* 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.
+*/
+
+
+#include "odbc_suite.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock-matchers.h>
+
+using namespace ignite;
+
+/**
+ * Test suite.
+ */
+class ssl_test : public odbc_suite {
+public:
+    void SetUp() override {
+        odbc_connect(get_basic_connection_string());
+        exec_query("DELETE FROM " + TABLE_NAME_ALL_COLUMNS_SQL);
+        odbc_clean_up();
+    }
+
+    /**
+     * Get a path to a SSL file.
+     * @param file
+     * @return
+     */
+    static std::string get_ssl_file(const std::string &file)
+    {
+        auto test_dir = resolve_test_dir();
+        auto ssl_files_dir = test_dir / "odbc-test" / "ssl";
+        if (!std::filesystem::is_directory(ssl_files_dir))
+            throw ignite_error("Can not find an 'ssl' directory in the current 'tests' directory: " + ssl_files_dir.string());
+
+        return (ssl_files_dir / file).string();
+    }
+
+    /**
+     * Get SSL connection string params.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string_params(std::string key_file, std::string cert_file, std::string ca_file) {
+        std::string conn_str{};
+
+        conn_str += ";ssl_mode=require";
+        conn_str += ";ssl_cert_file=" + get_ssl_file(key_file);
+        conn_str += ";ssl_key_file=" + get_ssl_file(cert_file);

Review Comment:
   Fixed.



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163335690


##########
modules/platforms/cpp/ignite/odbc/config/configuration.h:
##########
@@ -104,7 +108,7 @@ class configuration {
     void set_schema(std::string schema) { m_schema = {std::move(schema), true}; }
 
     /**
-     * Get authentication type.
+     * Get an authentication type.

Review Comment:
   Fixed.



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego merged PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102


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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163302843


##########
modules/platforms/cpp/ignite/odbc/config/configuration.h:
##########
@@ -104,7 +108,7 @@ class configuration {
     void set_schema(std::string schema) { m_schema = {std::move(schema), true}; }
 
     /**
-     * Get authentication type.
+     * Get an authentication type.

Review Comment:
   ```suggestion
        * Get the authentication type.
   ```



##########
modules/platforms/cpp/ignite/odbc/config/configuration.h:
##########
@@ -145,6 +149,34 @@ class configuration {
      */
     [[nodiscard]] const value_with_default<std::string> &get_timezone() const { return m_timezone; };
 
+    /**
+     * Get SSL Mode.

Review Comment:
   ```suggestion
        * Get the SSL Mode.
   ```



##########
modules/platforms/cpp/ignite/odbc/sql_connection.cpp:
##########
@@ -119,9 +119,37 @@ void sql_connection::establish(const configuration &cfg) {
     IGNITE_ODBC_API_CALL(internal_establish(cfg));
 }
 
-void sql_connection::init_socket() {
-    if (!m_socket)
+sql_result sql_connection::init_socket() {
+    if (m_socket)
+        return sql_result::AI_SUCCESS;
+
+    if (m_config.get_ssl_mode().get_value() == ssl_mode_t::DISABLE) {
         m_socket = network::make_tcp_socket_client();
+
+        return sql_result::AI_SUCCESS;
+    }
+
+    try
+    {
+        network::ensure_ssl_loaded();
+    }
+    catch (const ignite_error &err)
+    {
+        LOG_MSG("Can not load OpenSSL library: " << err.what());
+
+        add_status_record("Can not load OpenSSL library (did you set OPENSSL_HOME environment variable?)");

Review Comment:
   Should we check the actual value of `OPENSSL_HOME` env var and include it in the message?
   
   E.g. `Failed to load OpenSSL library [OPENSSL_HOME='foobar']`



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163360055


##########
modules/platforms/cpp/ignite/odbc/sql_connection.cpp:
##########
@@ -119,9 +119,37 @@ void sql_connection::establish(const configuration &cfg) {
     IGNITE_ODBC_API_CALL(internal_establish(cfg));
 }
 
-void sql_connection::init_socket() {
-    if (!m_socket)
+sql_result sql_connection::init_socket() {
+    if (m_socket)
+        return sql_result::AI_SUCCESS;
+
+    if (m_config.get_ssl_mode().get_value() == ssl_mode_t::DISABLE) {
         m_socket = network::make_tcp_socket_client();
+
+        return sql_result::AI_SUCCESS;
+    }
+
+    try
+    {
+        network::ensure_ssl_loaded();
+    }
+    catch (const ignite_error &err)
+    {
+        LOG_MSG("Can not load OpenSSL library: " << err.what());
+
+        add_status_record("Can not load OpenSSL library (did you set OPENSSL_HOME environment variable?)");

Review Comment:
   Done.



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163022546


##########
modules/platforms/cpp/tests/odbc-test/ssl_test.cpp:
##########
@@ -0,0 +1,264 @@
+/*
+* 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.
+*/
+
+
+#include "odbc_suite.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock-matchers.h>
+
+using namespace ignite;
+
+/**
+ * Test suite.
+ */
+class ssl_test : public odbc_suite {
+public:
+    void SetUp() override {
+        odbc_connect(get_basic_connection_string());
+        exec_query("DELETE FROM " + TABLE_NAME_ALL_COLUMNS_SQL);
+        odbc_clean_up();
+    }
+
+    /**
+     * Get a path to a SSL file.
+     * @param file
+     * @return
+     */
+    static std::string get_ssl_file(const std::string &file)
+    {
+        auto test_dir = resolve_test_dir();
+        auto ssl_files_dir = test_dir / "odbc-test" / "ssl";
+        if (!std::filesystem::is_directory(ssl_files_dir))
+            throw ignite_error("Can not find an 'ssl' directory in the current 'tests' directory: " + ssl_files_dir.string());
+
+        return (ssl_files_dir / file).string();
+    }
+
+    /**
+     * Get SSL connection string params.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string_params(std::string key_file, std::string cert_file, std::string ca_file) {
+        std::string conn_str{};
+
+        conn_str += ";ssl_mode=require";
+        conn_str += ";ssl_cert_file=" + get_ssl_file(key_file);
+        conn_str += ";ssl_key_file=" + get_ssl_file(cert_file);
+        conn_str += ";ssl_ca_file=" + get_ssl_file(ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Get SSL connection string.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string(std::string key_file, std::string cert_file, std::string ca_file) {
+        auto addresses = get_nodes_address(ignite_runner::get_ssl_node_addrs());
+        auto conn_str = get_basic_connection_string(addresses)
+            + get_ssl_connection_string_params(key_file, cert_file, ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Get SSL connection string.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_ca_connection_string(std::string key_file, std::string cert_file, std::string ca_file) {
+        auto addresses = get_nodes_address(ignite_runner::get_ssl_node_ca_addrs());
+        auto conn_str = get_basic_connection_string(addresses)
+            + get_ssl_connection_string_params(key_file, cert_file, ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Try to connect to SSL server successfully.
+     * @return Client.
+     */
+    void connect_successfully_to_ssl_server() {
+        odbc_connect(get_ssl_connection_string("client.pem", "client.pem", "ca.pem"));
+    }
+
+    /**
+     * Try to connect to SSL server successfully.
+     * @return Client.
+     */
+    void connect_successfully_to_ssl_ca_server() {
+        odbc_connect(get_ssl_ca_connection_string("client.pem", "client.pem", "ca.pem"));
+    }
+};
+
+TEST_F(ssl_test, ssl_connection_success)
+{
+    connect_successfully_to_ssl_server();
+}
+
+TEST_F(ssl_test, ssl_connection_unknown)
+{
+    auto conn_str = get_ssl_connection_string("client_unknown.pem", "client_unknown.pem", "ca.pem");
+    odbc_connect(conn_str);
+}
+
+TEST_F(ssl_test, ssl_connection_unknown_2)
+{
+    EXPECT_THROW(
+        {
+            try {
+                auto conn_str = get_ssl_ca_connection_string("client_unknown.pem", "client_unknown.pem", "ca.pem");
+                odbc_connect_throw(conn_str);
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), AnyOf(testing::HasSubstr("08001: Failed to send handshake request"), testing::HasSubstr("08001: Failed to get handshake response")));;

Review Comment:
   Fixed



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163015164


##########
modules/platforms/cpp/tests/odbc-test/ssl_test.cpp:
##########
@@ -0,0 +1,264 @@
+/*
+* 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.
+*/
+
+
+#include "odbc_suite.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock-matchers.h>
+
+using namespace ignite;
+
+/**
+ * Test suite.
+ */
+class ssl_test : public odbc_suite {
+public:
+    void SetUp() override {
+        odbc_connect(get_basic_connection_string());
+        exec_query("DELETE FROM " + TABLE_NAME_ALL_COLUMNS_SQL);
+        odbc_clean_up();
+    }
+
+    /**
+     * Get a path to a SSL file.
+     * @param file
+     * @return
+     */
+    static std::string get_ssl_file(const std::string &file)
+    {
+        auto test_dir = resolve_test_dir();
+        auto ssl_files_dir = test_dir / "odbc-test" / "ssl";
+        if (!std::filesystem::is_directory(ssl_files_dir))
+            throw ignite_error("Can not find an 'ssl' directory in the current 'tests' directory: " + ssl_files_dir.string());
+
+        return (ssl_files_dir / file).string();
+    }
+
+    /**
+     * Get SSL connection string params.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string_params(std::string key_file, std::string cert_file, std::string ca_file) {
+        std::string conn_str{};
+
+        conn_str += ";ssl_mode=require";
+        conn_str += ";ssl_cert_file=" + get_ssl_file(key_file);
+        conn_str += ";ssl_key_file=" + get_ssl_file(cert_file);

Review Comment:
   Parameters `key_file` and `cert_file` are swapped when building the connection string: `ssl_cert_file` should use `cert_file`, and `ssl_key_file` should use `key_file`.
   ```suggestion
           conn_str += ";ssl_cert_file=" + get_ssl_file(cert_file);
           conn_str += ";ssl_key_file=" + get_ssl_file(key_file);
   ```



##########
modules/platforms/cpp/tests/odbc-test/ssl_test.cpp:
##########
@@ -0,0 +1,264 @@
+/*
+* 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.
+*/
+
+
+#include "odbc_suite.h"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock-matchers.h>
+
+using namespace ignite;
+
+/**
+ * Test suite.
+ */
+class ssl_test : public odbc_suite {
+public:
+    void SetUp() override {
+        odbc_connect(get_basic_connection_string());
+        exec_query("DELETE FROM " + TABLE_NAME_ALL_COLUMNS_SQL);
+        odbc_clean_up();
+    }
+
+    /**
+     * Get a path to a SSL file.
+     * @param file
+     * @return
+     */
+    static std::string get_ssl_file(const std::string &file)
+    {
+        auto test_dir = resolve_test_dir();
+        auto ssl_files_dir = test_dir / "odbc-test" / "ssl";
+        if (!std::filesystem::is_directory(ssl_files_dir))
+            throw ignite_error("Can not find an 'ssl' directory in the current 'tests' directory: " + ssl_files_dir.string());
+
+        return (ssl_files_dir / file).string();
+    }
+
+    /**
+     * Get SSL connection string params.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string_params(std::string key_file, std::string cert_file, std::string ca_file) {
+        std::string conn_str{};
+
+        conn_str += ";ssl_mode=require";
+        conn_str += ";ssl_cert_file=" + get_ssl_file(key_file);
+        conn_str += ";ssl_key_file=" + get_ssl_file(cert_file);
+        conn_str += ";ssl_ca_file=" + get_ssl_file(ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Get SSL connection string.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_connection_string(std::string key_file, std::string cert_file, std::string ca_file) {
+        auto addresses = get_nodes_address(ignite_runner::get_ssl_node_addrs());
+        auto conn_str = get_basic_connection_string(addresses)
+            + get_ssl_connection_string_params(key_file, cert_file, ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Get SSL connection string.
+     *
+     * @param key_file Key file.
+     * @param cert_file Certificate file.
+     * @param ca_file CA file.
+     * @return SSL connection string.
+     */
+    static std::string get_ssl_ca_connection_string(std::string key_file, std::string cert_file, std::string ca_file) {
+        auto addresses = get_nodes_address(ignite_runner::get_ssl_node_ca_addrs());
+        auto conn_str = get_basic_connection_string(addresses)
+            + get_ssl_connection_string_params(key_file, cert_file, ca_file);
+
+        return conn_str;
+    }
+
+    /**
+     * Try to connect to SSL server successfully.
+     * @return Client.
+     */
+    void connect_successfully_to_ssl_server() {
+        odbc_connect(get_ssl_connection_string("client.pem", "client.pem", "ca.pem"));
+    }
+
+    /**
+     * Try to connect to SSL server successfully.
+     * @return Client.
+     */
+    void connect_successfully_to_ssl_ca_server() {
+        odbc_connect(get_ssl_ca_connection_string("client.pem", "client.pem", "ca.pem"));
+    }
+};
+
+TEST_F(ssl_test, ssl_connection_success)
+{
+    connect_successfully_to_ssl_server();
+}
+
+TEST_F(ssl_test, ssl_connection_unknown)
+{
+    auto conn_str = get_ssl_connection_string("client_unknown.pem", "client_unknown.pem", "ca.pem");
+    odbc_connect(conn_str);
+}
+
+TEST_F(ssl_test, ssl_connection_unknown_2)
+{
+    EXPECT_THROW(
+        {
+            try {
+                auto conn_str = get_ssl_ca_connection_string("client_unknown.pem", "client_unknown.pem", "ca.pem");
+                odbc_connect_throw(conn_str);
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), AnyOf(testing::HasSubstr("08001: Failed to send handshake request"), testing::HasSubstr("08001: Failed to get handshake response")));;

Review Comment:
   There is an extra semicolon at the end of this statement which may trigger warnings; please remove the duplicate semicolon.
   ```suggestion
                   EXPECT_THAT(e.what_str(), AnyOf(testing::HasSubstr("08001: Failed to send handshake request"), testing::HasSubstr("08001: Failed to get handshake response")));
   ```



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


Re: [PR] IGNITE-25745 ODBC: Add SSL/TLS support [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #6102:
URL: https://github.com/apache/ignite-3/pull/6102#discussion_r2163336538


##########
modules/platforms/cpp/ignite/odbc/config/configuration.h:
##########
@@ -145,6 +149,34 @@ class configuration {
      */
     [[nodiscard]] const value_with_default<std::string> &get_timezone() const { return m_timezone; };
 
+    /**
+     * Get SSL Mode.

Review Comment:
   Fixed.



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