From 13879f749107bd946fc4b038f1128de40f471104 Mon Sep 17 00:00:00 2001 From: proller Date: Tue, 13 Mar 2018 22:49:21 +0300 Subject: [PATCH] Test client-server ssl --- dbms/src/Server/Server.cpp | 4 ++-- dbms/src/Server/TCPHandlerFactory.h | 4 ++-- dbms/tests/clickhouse-test-server | 8 ++++++-- dbms/tests/client-test.xml | 1 + dbms/tests/server-test.xml | 30 ++++++++++++++++++++++++++++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/dbms/src/Server/Server.cpp b/dbms/src/Server/Server.cpp index db20c194573..9f09ffd549b 100644 --- a/dbms/src/Server/Server.cpp +++ b/dbms/src/Server/Server.cpp @@ -387,7 +387,7 @@ int Server::main(const std::vector & /*args*/) http_socket.setSendTimeout(settings.http_send_timeout); servers.emplace_back(new Poco::Net::HTTPServer( - new HTTPHandlerFactory(*this, "HTTPHandler-factory"), + new HTTPHandlerFactory(*this, "HTTPSHandler-factory"), server_pool, http_socket, http_params)); @@ -425,7 +425,7 @@ int Server::main(const std::vector & /*args*/) tcp_socket.setReceiveTimeout(settings.receive_timeout); tcp_socket.setSendTimeout(settings.send_timeout); servers.emplace_back(new Poco::Net::TCPServer( - new TCPHandlerFactory(*this), + new TCPHandlerFactory(*this, /* secure= */ true ), server_pool, tcp_socket, new Poco::Net::TCPServerParams)); diff --git a/dbms/src/Server/TCPHandlerFactory.h b/dbms/src/Server/TCPHandlerFactory.h index 1f454b35a8f..99cc23a45da 100644 --- a/dbms/src/Server/TCPHandlerFactory.h +++ b/dbms/src/Server/TCPHandlerFactory.h @@ -17,9 +17,9 @@ private: Poco::Logger * log; public: - explicit TCPHandlerFactory(IServer & server_) + explicit TCPHandlerFactory(IServer & server_, bool secure_ = false) : server(server_) - , log(&Logger::get("TCPHandlerFactory")) + , log(&Logger::get("TCP" + (secure_ ? "S" : "") + "HandlerFactory")) { } diff --git a/dbms/tests/clickhouse-test-server b/dbms/tests/clickhouse-test-server index 82d254017bf..7fb6918bfe5 100755 --- a/dbms/tests/clickhouse-test-server +++ b/dbms/tests/clickhouse-test-server @@ -22,8 +22,10 @@ export CLICKHOUSE_CONFIG=${CLICKHOUSE_CONFIG:=${CONFIG_SERVER_DIR}server-test.xm [ ! -d "$QUERIES_DIR" ] && QUERIES_DIR=${QUERIES_DIR=/usr/share/clickhouse-test/queries} rm -rf $DATA_DIR -mkdir -p $LOG_DIR +mkdir -p $LOG_DIR $DATA_DIR +openssl dhparam -out `clickhouse-extract-from-config --config=$CLICKHOUSE_CONFIG --key=openSSL.server.dhParamsFile` 256 +openssl req -subj "/CN=localhost" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout `clickhouse-extract-from-config --config=$CLICKHOUSE_CONFIG --key=openSSL.server.privateKeyFile` -out `clickhouse-extract-from-config --config=$CLICKHOUSE_CONFIG --key=openSSL.server.certificateFile` # Start a local clickhouse server which will be used to run tests #PATH=$PATH:$BIN_DIR \ @@ -31,6 +33,8 @@ ${BIN_DIR}clickhouse-server --config-file=${CLICKHOUSE_CONFIG} > $LOG_DIR/stdout CH_PID=$! sleep 3 +tail -n50 $LOG_DIR/* + # Define needed stuff to kill test clickhouse server after tests completion function finish { kill $CH_PID || true @@ -38,7 +42,7 @@ function finish { tail -n 50 $LOG_DIR/stdout rm -rf $DATA_DIR } -trap finish EXIT +trap finish EXIT SIGINT SIGQUIT SIGTERM # Do tests if [ -n "$*" ]; then diff --git a/dbms/tests/client-test.xml b/dbms/tests/client-test.xml index 0cd3bdd5dc0..c5478dcb80d 100644 --- a/dbms/tests/client-test.xml +++ b/dbms/tests/client-test.xml @@ -1,4 +1,5 @@ 59000 + 59440 diff --git a/dbms/tests/server-test.xml b/dbms/tests/server-test.xml index cdb8e9caf5d..57f3f8ad9ea 100644 --- a/dbms/tests/server-test.xml +++ b/dbms/tests/server-test.xml @@ -13,8 +13,36 @@ 1 58123 59000 - 0.0.0.0 + 58443 + 59440 59009 + + + + /tmp/clickhouse/server.crt + /tmp/clickhouse/server.key + + /tmp/clickhouse/dhparam.pem + none + true + true + sslv2,sslv3 + true + + + + true + true + sslv2,sslv3 + true + + + + RejectCertificateHandler + + + + 3 /tmp/clickhouse/data/ /tmp/clickhouse/tmp/