Skip to content

Commit 07808d6

Browse files
committed
made SNI a single string. added setter for client builder. removed unneeded files
1 parent 659485e commit 07808d6

File tree

20 files changed

+57
-782
lines changed

20 files changed

+57
-782
lines changed

clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseClientOption.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,9 @@ public enum ClickHouseClientOption implements ClickHouseOption {
454454
MEASURE_REQUEST_TIME("debug_measure_request_time", false, "Whether to measure request time. If true, the time will be logged in debug mode."),
455455

456456
/**
457-
* Comma separated key-value pairs of IP address/host to SNI mapping.
458-
* Special mapping {@code _default_} - for default SNI when no match found. Without default mapping only matched targets will have SNI parameter.
457+
* SNI SSL parameter that will be set for each outbound SSL socket.
459458
*/
460-
SSL_SNI_MAPPING("ssl_sni_map", "", "Comma separated key-value pairs of IP address/host to SNI mapping. Special mapping _default_ - for default SNI when no match found. Without default mapping only matched targets will have SNI parameter.")
459+
SSL_SOCKET_SNI("ssl_socket_sni", "", " SNI SSL parameter that will be set for each outbound SSL socket.")
461460

462461
;
463462

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ApacheHttpConnectionImpl.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ public static SocketFactory create(ClickHouseConfig config) {
397397

398398
static class SSLSocketFactory extends SSLConnectionSocketFactory {
399399
private final ClickHouseConfig config;
400-
private final Map<String, String> sniMapping;
401-
private final String defaultSNI;
400+
private final SNIHostName defaultSNI;
402401

403402
private SSLSocketFactory(ClickHouseConfig config) throws SSLException {
404403
super(ClickHouseSslContextProvider.getProvider().getSslContext(SSLContext.class, config)
@@ -407,9 +406,8 @@ private SSLSocketFactory(ClickHouseConfig config) throws SSLException {
407406
? new DefaultHostnameVerifier()
408407
: (hostname, session) -> true); // NOSONAR
409408
this.config = config;
410-
String sniMappingStr = config.getStrOption(ClickHouseClientOption.SSL_SNI_MAPPING);
411-
sniMapping = ClickHouseOption.toKeyValuePairs(sniMappingStr);
412-
defaultSNI = sniMapping.get("_default_");
409+
String sni = config.getStrOption(ClickHouseClientOption.SSL_SOCKET_SNI);
410+
defaultSNI = sni == null || sni.trim().isEmpty() ? null : new SNIHostName(sni);
413411
}
414412

415413
@Override
@@ -420,25 +418,10 @@ public Socket createSocket(HttpContext context) throws IOException {
420418
@Override
421419
protected void prepareSocket(SSLSocket socket, HttpContext context) throws IOException {
422420
super.prepareSocket(socket, context);
423-
424-
if (!sniMapping.isEmpty()) {
425-
InetAddress remote = socket.getInetAddress();
426-
if (remote != null) { // actually should be not null here
427-
String sni = sniMapping.get(remote.getHostAddress());
428-
if (sni == null) {
429-
sni = sniMapping.get(remote.getHostName());
430-
if (sni == null) {
431-
sni = defaultSNI;
432-
}
433-
}
434-
if (sni != null && !sni.isEmpty()) {
435-
SSLParameters sslParams = socket.getSSLParameters();
436-
sslParams.setServerNames(Collections.singletonList(new SNIHostName(sni)));
437-
socket.setSSLParameters(sslParams);
438-
}
439-
} else {
440-
log.warn("Failed to apply SNI - remote address is null");
441-
}
421+
if (defaultSNI != null) {
422+
SSLParameters sslParams = socket.getSSLParameters();
423+
sslParams.setServerNames(Collections.singletonList(defaultSNI));
424+
socket.setSSLParameters(sslParams);
442425
}
443426
}
444427

clickhouse-http-client/src/test/java/com/clickhouse/client/http/NetworkTests.java

Lines changed: 0 additions & 269 deletions
This file was deleted.

clickhouse-http-client/src/test/resources/certs/node1.crt

Lines changed: 0 additions & 19 deletions
This file was deleted.

clickhouse-http-client/src/test/resources/certs/node1.key

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)