Skip to content

Commit 61923c1

Browse files
committed
Fixed non-functional issues from PR review
minor renaming, comments and other grooming
1 parent 9cb9ce4 commit 61923c1

10 files changed

+35
-46
lines changed

clickhouse/base/sslsocket.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ SSL_CTX * SSLContext::getContext() {
120120
}
121121

122122
// Allows caller to use returned value of `statement` if there was no error, throws exception otherwise.
123-
#define HANDLE_SSL_ERROR(statement) [&] { \
123+
#define HANDLE_SSL_ERROR(SSL_PTR, statement) [&] { \
124124
if (const auto ret_code = (statement); ret_code <= 0) { \
125-
throwSSLError(ssl_, SSL_get_error(ssl_, ret_code), LOCATION, #statement); \
125+
throwSSLError(SSL_PTR, SSL_get_error(SSL_PTR, ret_code), LOCATION, #statement); \
126126
return static_cast<decltype(ret_code)>(0); \
127127
} \
128128
else \
@@ -137,25 +137,25 @@ SSL_CTX * SSLContext::getContext() {
137137
*/
138138
SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, SSLContext& context)
139139
: Socket(addr)
140-
, ssl_ptr_(SSL_new(context.getContext()), &SSL_free)
141-
, ssl_(ssl_ptr_.get())
140+
, ssl_(SSL_new(context.getContext()), &SSL_free)
142141
{
143-
if (!ssl_)
142+
auto ssl = ssl_.get();
143+
if (!ssl)
144144
throw std::runtime_error("Failed to create SSL instance");
145145

146-
HANDLE_SSL_ERROR(SSL_set_fd(ssl_, handle_));
146+
HANDLE_SSL_ERROR(ssl, SSL_set_fd(ssl, handle_));
147147
if (ssl_params.use_SNI)
148-
HANDLE_SSL_ERROR(SSL_set_tlsext_host_name(ssl_, addr.Host().c_str()));
148+
HANDLE_SSL_ERROR(ssl, SSL_set_tlsext_host_name(ssl, addr.Host().c_str()));
149149

150-
SSL_set_connect_state(ssl_);
151-
HANDLE_SSL_ERROR(SSL_connect(ssl_));
152-
HANDLE_SSL_ERROR(SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY));
153-
auto peer_certificate = SSL_get_peer_certificate(ssl_);
150+
SSL_set_connect_state(ssl);
151+
HANDLE_SSL_ERROR(ssl, SSL_connect(ssl));
152+
HANDLE_SSL_ERROR(ssl, SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY));
153+
auto peer_certificate = SSL_get_peer_certificate(ssl);
154154

155155
if (!peer_certificate)
156156
throw std::runtime_error("Failed to verify SSL connection: server provided no ceritificate.");
157157

158-
if (const auto verify_result = SSL_get_verify_result(ssl_); verify_result != X509_V_OK) {
158+
if (const auto verify_result = SSL_get_verify_result(ssl); verify_result != X509_V_OK) {
159159
auto error_message = X509_verify_cert_error_string(verify_result);
160160
throw std::runtime_error("Failed to verify SSL connection, X509_v error: "
161161
+ std::to_string(verify_result)
@@ -170,23 +170,23 @@ SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, S
170170
std::unique_ptr<ASN1_OCTET_STRING, decltype(&ASN1_OCTET_STRING_free)> addr(a2i_IPADDRESS(hostname.c_str()), &ASN1_OCTET_STRING_free);
171171
if (addr) {
172172
// if hostname is actually an IP address
173-
HANDLE_SSL_ERROR(X509_check_ip(
173+
HANDLE_SSL_ERROR(ssl, X509_check_ip(
174174
peer_certificate,
175175
ASN1_STRING_get0_data(addr.get()),
176176
ASN1_STRING_length(addr.get()),
177177
0));
178178
} else {
179-
HANDLE_SSL_ERROR(X509_check_host(peer_certificate, hostname.c_str(), hostname.length(), 0, &out_name));
179+
HANDLE_SSL_ERROR(ssl, X509_check_host(peer_certificate, hostname.c_str(), hostname.length(), 0, &out_name));
180180
}
181181
}
182182
}
183183

184184
std::unique_ptr<InputStream> SSLSocket::makeInputStream() const {
185-
return std::make_unique<SSLSocketInput>(ssl_);
185+
return std::make_unique<SSLSocketInput>(ssl_.get());
186186
}
187187

188188
std::unique_ptr<OutputStream> SSLSocket::makeOutputStream() const {
189-
return std::make_unique<SSLSocketOutput>(ssl_);
189+
return std::make_unique<SSLSocketOutput>(ssl_.get());
190190
}
191191

192192
SSLSocketInput::SSLSocketInput(SSL *ssl)
@@ -195,7 +195,7 @@ SSLSocketInput::SSLSocketInput(SSL *ssl)
195195

196196
size_t SSLSocketInput::DoRead(void* buf, size_t len) {
197197
size_t actually_read;
198-
HANDLE_SSL_ERROR(SSL_read_ex(ssl_, buf, len, &actually_read));
198+
HANDLE_SSL_ERROR(ssl_, SSL_read_ex(ssl_, buf, len, &actually_read));
199199
return actually_read;
200200
}
201201

@@ -204,7 +204,9 @@ SSLSocketOutput::SSLSocketOutput(SSL *ssl)
204204
{}
205205

206206
void SSLSocketOutput::DoWrite(const void* data, size_t len) {
207-
HANDLE_SSL_ERROR(SSL_write(ssl_, data, len));
207+
HANDLE_SSL_ERROR(ssl_, SSL_write(ssl_, data, len));
208208
}
209209

210+
#undef HANDLE_SSL_ERROR
211+
210212
}

clickhouse/base/sslsocket.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class SSLSocket : public Socket {
5353
std::unique_ptr<OutputStream> makeOutputStream() const override;
5454

5555
private:
56-
std::unique_ptr<SSL, void (*)(SSL *s)> ssl_ptr_;
57-
SSL *ssl_; // for convinience with SSL API
56+
std::unique_ptr<SSL, void (*)(SSL *s)> ssl_;
5857
};
5958

6059
class SSLSocketInput : public InputStream {

clickhouse/client.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ struct ClientOptions {
9595
*/
9696
DECLARE_FIELD(backward_compatibility_lowcardinality_as_wrapped_column, bool, SetBakcwardCompatibilityFeatureLowCardinalityAsWrappedColumn, true);
9797

98-
/** Set max size data to compress if compression enabled.
99-
*
100-
* Allows choosing tradeoff betwen RAM\CPU:
101-
* - Lower value reduces RAM usage, but slightly increases CPU usage.
102-
* - Higher value increases RAM usage but slightly decreases CPU usage.
103-
*
104-
* Default is 0, use natural implementation-defined chunk size.
105-
*/
106-
DECLARE_FIELD(max_compression_chunk_size, unsigned int, SetMaxCompressionChunkSize, 65535);
107-
10898
#if defined(WITH_OPENSSL)
10999
struct SSLOptions {
110100
bool use_ssl = true; // not expected to be set manually.

ut/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ SET ( clickhouse-cpp-ut-src
1212
performance_tests.cpp
1313
tcp_server.cpp
1414
utils.cpp
15-
readonly_client_ut.cpp
16-
connection_failed_client_ut.cpp
15+
readonly_client_test.cpp
16+
connection_failed_client_test.cpp
1717
)
1818

1919
IF (WITH_OPENSSL)

ut/client_ut.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <contrib/gtest/gtest.h>
33

44
#include <cmath>
5-
#include <initializer_list>
65

76
using namespace clickhouse;
87

ut/connection_failed_client_ut.cpp renamed to ut/connection_failed_client_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "connection_failed_client_ut.h"
1+
#include "connection_failed_client_test.h"
22
#include "utils.h"
33

44
#include <clickhouse/columns/column.h>
File renamed without changes.

ut/readonly_client_ut.cpp renamed to ut/readonly_client_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "readonly_client_ut.h"
1+
#include "readonly_client_test.h"
22
#include "utils.h"
33

44
#include <clickhouse/columns/column.h>
File renamed without changes.

ut/ssl_ut.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** Collection of integration tests that validate TLS-connectivity to a CH server
22
*/
3-
#include "readonly_client_ut.h"
4-
#include "connection_failed_client_ut.h"
3+
#include "readonly_client_test.h"
4+
#include "connection_failed_client_test.h"
55

66
#include <openssl/tls1.h>
77
#include <openssl/ssl2.h>
@@ -20,6 +20,13 @@ namespace {
2020
};
2121
}
2222

23+
#if defined(__linux__)
24+
// On Ubuntu 20.04 /etc/ssl/certs is a default directory with the CA files
25+
const auto DEAFULT_CA_DIRECTORY_PATH = "/etc/ssl/certs";
26+
#elif defined(__APPLE__)
27+
#elif defined(_win_)
28+
#endif
29+
2330
INSTANTIATE_TEST_CASE_P(
2431
RemoteTLS, ReadonlyClientTest,
2532
::testing::Values(ReadonlyClientTest::ParamType {
@@ -31,21 +38,13 @@ INSTANTIATE_TEST_CASE_P(
3138
.SetDefaultDatabase("default")
3239
.SetSendRetries(1)
3340
.SetPingBeforeQuery(true)
34-
// On Ubuntu 20.04 /etc/ssl/certs is a default directory with the CA files
3541
.SetCompressionMethod(CompressionMethod::None)
3642
.SetSSLOptions(ClientOptions::SSLOptions()
37-
.SetPathToCADirectory("/etc/ssl/certs")),
43+
.SetPathToCADirectory(DEAFULT_CA_DIRECTORY_PATH)),
3844
QUERIES
3945
}
4046
));
4147

42-
#if defined(__linux__)
43-
// On Ubuntu 20.04 /etc/ssl/certs is a default directory with the CA files
44-
const auto DEAFULT_CA_DIRECTORY_PATH = "/etc/ssl/certs";
45-
#elif defined(__APPLE__)
46-
#elif defined(_win_)
47-
#endif
48-
4948
INSTANTIATE_TEST_CASE_P(
5049
Remote_GH_API_TLS, ReadonlyClientTest,
5150
::testing::Values(ReadonlyClientTest::ParamType {

0 commit comments

Comments
 (0)