diff --git a/example/client-cpp-example/src/CMakeLists.txt b/example/client-cpp-example/src/CMakeLists.txt
index 6d87631ab576..1ee249bfb803 100644
--- a/example/client-cpp-example/src/CMakeLists.txt
+++ b/example/client-cpp-example/src/CMakeLists.txt
@@ -28,12 +28,23 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thrift/include)
# Add cpp-client include directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
FIND_PACKAGE(Boost REQUIRED)
@@ -50,53 +61,91 @@ ADD_EXECUTABLE(TableModelSessionExample TableModelSessionExample.cpp)
ADD_EXECUTABLE(MultiSvrNodeClient MultiSvrNodeClient.cpp)
IF(MSVC)
- TARGET_LINK_LIBRARIES(SessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(TableModelSessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(MultiSvrNodeClient
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ ENDIF()
ELSE()
- TARGET_LINK_LIBRARIES(SessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(TableModelSessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(MultiSvrNodeClient
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
-ENDIF()
\ No newline at end of file
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ pthread
+ )
+ ENDIF()
+ENDIF()
diff --git a/iotdb-client/client-cpp/pom.xml b/iotdb-client/client-cpp/pom.xml
index c307c651fba8..bf0f92204e41 100644
--- a/iotdb-client/client-cpp/pom.xml
+++ b/iotdb-client/client-cpp/pom.xml
@@ -38,6 +38,7 @@
${project.build.directory}/dependency/cmake/
${project.build.directory}/thrift/bin/${thrift.executable}
${ctest.skip.tests}
+ false
@@ -217,6 +218,7 @@
${project.build.directory}/build/main
+
@@ -233,6 +235,7 @@
${project.build.directory}/build/test
+
diff --git a/iotdb-client/client-cpp/src/main/CMakeLists.txt b/iotdb-client/client-cpp/src/main/CMakeLists.txt
index 7945cd887d37..2a6173514d7f 100644
--- a/iotdb-client/client-cpp/src/main/CMakeLists.txt
+++ b/iotdb-client/client-cpp/src/main/CMakeLists.txt
@@ -26,13 +26,23 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g -O2 ")
# Add Thrift include directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../thrift/include)
-# Find OpenSSL Library
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
# Add Boost include path for MacOS
@@ -50,11 +60,6 @@ ELSE()
SET(THRIFT_STATIC_LIB "${CMAKE_SOURCE_DIR}/../../thrift/lib/libthrift.a")
ENDIF()
-IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MSVC)
- add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
- add_link_options(-fsanitize=address)
-ENDIF()
-
# Add the generated source files to the sources for the library.
AUX_SOURCE_DIRECTORY(./generated-sources-cpp SESSION_SRCS)
IF(MSVC)
@@ -63,10 +68,20 @@ ELSE()
ADD_LIBRARY(iotdb_session SHARED ${SESSION_SRCS})
ENDIF()
-# Link with Thrift static library
-target_link_libraries(iotdb_session
- PUBLIC
- OpenSSL::SSL
- OpenSSL::Crypto
- ${THRIFT_STATIC_LIB}
-)
+# =========================
+# Link libraries (SSL optional)
+# =========================
+IF(WITH_SSL)
+ target_link_libraries(iotdb_session
+ PUBLIC
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ ${THRIFT_STATIC_LIB}
+ )
+ELSE()
+ target_link_libraries(iotdb_session
+ PUBLIC
+ ${THRIFT_STATIC_LIB}
+ )
+ENDIF()
+
diff --git a/iotdb-client/client-cpp/src/main/SessionConnection.cpp b/iotdb-client/client-cpp/src/main/SessionConnection.cpp
index 0ab22cc79a60..7ed903d24fb4 100644
--- a/iotdb-client/client-cpp/src/main/SessionConnection.cpp
+++ b/iotdb-client/client-cpp/src/main/SessionConnection.cpp
@@ -100,11 +100,17 @@ SessionConnection::~SessionConnection() {
void SessionConnection::init(const TEndPoint& endpoint, bool useSSL, const std::string& trustCertFilePath) {
if (useSSL) {
+#if WITH_SSL
socketFactory_->loadTrustedCertificates(trustCertFilePath.c_str());
socketFactory_->authenticate(false);
auto sslSocket = socketFactory_->createSocket(endPoint.ip, endPoint.port);
sslSocket->setConnTimeout(connectionTimeoutInMs);
transport = std::make_shared(sslSocket);
+#else
+ throw IoTDBException("SSL/TLS support is not enabled in this build. "
+ "Please rebuild with -DWITH_SSL=ON flag "
+ "or use non-SSL connection.");
+#endif
} else {
auto socket = std::make_shared(endPoint.ip, endPoint.port);
socket->setConnTimeout(connectionTimeoutInMs);
diff --git a/iotdb-client/client-cpp/src/main/SessionConnection.h b/iotdb-client/client-cpp/src/main/SessionConnection.h
index 297898ca9a23..a4ef7a7d64c4 100644
--- a/iotdb-client/client-cpp/src/main/SessionConnection.h
+++ b/iotdb-client/client-cpp/src/main/SessionConnection.h
@@ -23,7 +23,10 @@
#include
#include
#include
+#if WITH_SSL
#include
+#endif
+
#include "IClientRPCService.h"
#include "common_types.h"
#include "NodesSupplier.h"
@@ -179,9 +182,10 @@ class SessionConnection : public std::enable_shared_from_this
TSStatus insertTabletsInternal(TSInsertTabletsReq request);
TSStatus deleteDataInternal(TSDeleteDataReq request);
-
+#if WITH_SSL
std::shared_ptr socketFactory_ =
std::make_shared();
+#endif
std::shared_ptr transport;
std::shared_ptr client;
Session* session;
diff --git a/iotdb-client/client-cpp/src/main/ThriftConnection.cpp b/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
index 2cb52bed6075..3a7989a5e765 100644
--- a/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
+++ b/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
@@ -69,11 +69,17 @@ void ThriftConnection::init(const std::string& username,
const std::string& zoneId,
const std::string& version) {
if (useSSL) {
+#if WITH_SSL
socketFactory_->loadTrustedCertificates(trustCertFilePath.c_str());
socketFactory_->authenticate(false);
auto sslSocket = socketFactory_->createSocket(endPoint_.ip, endPoint_.port);
sslSocket->setConnTimeout(connectionTimeoutInMs_);
transport_ = std::make_shared(sslSocket);
+#else
+ throw IoTDBException("SSL/TLS support is not enabled in this build. "
+ "Please rebuild with -DWITH_SSL=ON flag "
+ "or use non-SSL connection.");
+#endif
} else {
auto socket = std::make_shared(endPoint_.ip, endPoint_.port);
socket->setConnTimeout(connectionTimeoutInMs_);
diff --git a/iotdb-client/client-cpp/src/main/ThriftConnection.h b/iotdb-client/client-cpp/src/main/ThriftConnection.h
index a308c95e3a20..6dae68357fdb 100644
--- a/iotdb-client/client-cpp/src/main/ThriftConnection.h
+++ b/iotdb-client/client-cpp/src/main/ThriftConnection.h
@@ -20,7 +20,9 @@
#define IOTDB_THRIFTCONNECTION_H
#include
+#if WITH_SSL
#include
+#endif
#include "IClientRPCService.h"
class SessionDataSet;
@@ -60,8 +62,10 @@ class ThriftConnection {
int connectionTimeoutInMs_;
int fetchSize_;
+#if WITH_SSL
std::shared_ptr socketFactory_ =
std::make_shared();
+#endif
std::shared_ptr transport_;
std::shared_ptr client_;
int64_t sessionId_{};
diff --git a/iotdb-client/client-cpp/src/test/CMakeLists.txt b/iotdb-client/client-cpp/src/test/CMakeLists.txt
index ab225f8efb9f..0a830b05fcd5 100644
--- a/iotdb-client/client-cpp/src/test/CMakeLists.txt
+++ b/iotdb-client/client-cpp/src/test/CMakeLists.txt
@@ -25,13 +25,23 @@ SET(TARGET_NAME_RELATIONAL session_relational_tests)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g -O2")
ENABLE_TESTING()
-# OpenSSL
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
# Add Boost include path for MacOS
@@ -66,31 +76,53 @@ ADD_EXECUTABLE(${TARGET_NAME_RELATIONAL} main_Relational.cpp cpp/sessionRelation
# Link with shared library iotdb_session and pthread
IF(MSVC)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- iotdb_session
- ${THRIFT_STATIC_LIB}
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
- iotdb_session
- ${THRIFT_STATIC_LIB}
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ )
+ ENDIF()
ELSE()
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ pthread
+ )
+ ENDIF()
ENDIF()
# Add Catch2 include directory