You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2025/02/11 02:11:22 UTC
(iotdb) branch insecure_client created (now e40e2d94dc7)
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a change to branch insecure_client
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at e40e2d94dc7 add insecure transport for security test
This branch includes the following new commits:
new e40e2d94dc7 add insecure transport for security test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iotdb) 01/01: add insecure transport for security test
Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch insecure_client
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit e40e2d94dc71594cdccc8145b9c009f9c3b64113
Author: Tian Jiang <jt...@163.com>
AuthorDate: Tue Feb 11 10:11:09 2025 +0800
add insecure transport for security test
---
.../org/apache/iotdb/jdbc/IoTDBConnection.java | 19 ++++++++-----
.../apache/iotdb/rpc/BaseRpcTransportFactory.java | 32 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index f0949429270..1e5692ec0d3 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -491,13 +491,18 @@ public class IoTDBConnection implements Connection {
DeepCopyRpcTransportFactory.setThriftMaxFrameSize(params.getThriftMaxFrameSize());
if (params.isUseSSL()) {
- transport =
- DeepCopyRpcTransportFactory.INSTANCE.getTransport(
- params.getHost(),
- params.getPort(),
- getNetworkTimeout(),
- params.getTrustStore(),
- params.getTrustStorePwd());
+// transport =
+// DeepCopyRpcTransportFactory.INSTANCE.getTransport(
+// params.getHost(),
+// params.getPort(),
+// getNetworkTimeout(),
+// params.getTrustStore(),
+// params.getTrustStorePwd());
+ try {
+ transport = DeepCopyRpcTransportFactory.INSTANCE.getInsecureTransport(params.getHost(), params.getPort());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
} else {
transport =
DeepCopyRpcTransportFactory.INSTANCE.getTransport(
diff --git a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/BaseRpcTransportFactory.java b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/BaseRpcTransportFactory.java
index 61fcf52671f..85cfb501f11 100644
--- a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/BaseRpcTransportFactory.java
+++ b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/BaseRpcTransportFactory.java
@@ -19,6 +19,12 @@
package org.apache.iotdb.rpc;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
import org.apache.thrift.transport.TMemoryInputTransport;
import org.apache.thrift.transport.TSSLTransportFactory;
import org.apache.thrift.transport.TSocket;
@@ -84,6 +90,32 @@ public class BaseRpcTransportFactory extends TTransportFactory {
return inner.getTransport(transport);
}
+ public static class CustomX509TrustManager implements X509TrustManager {
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {
+ // 空实现,接受任何客户端证书
+ }
+
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {
+ // 空实现,接受任何服务器证书
+ }
+
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[]{};
+ }
+ }
+
+ public static SSLSocket createSSLSocket(String host, int port) throws Exception {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ TrustManager[] trustManagers = new TrustManager[]{new CustomX509TrustManager()};
+ sslContext.init(null, trustManagers, new java.security.SecureRandom());
+ SSLSocketFactory factory = sslContext.getSocketFactory();
+ return (SSLSocket) factory.createSocket(host, port);
+ }
+
+ public TTransport getInsecureTransport(String ip, int port) throws Exception {
+ return inner.getTransport(new TSocket(createSSLSocket(ip, port)));
+ }
+
public TTransport getTransport(String ip, int port, int timeout) throws TTransportException {
return inner.getTransport(
new TSocket(TConfigurationConst.defaultTConfiguration, ip, port, timeout));