Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
add mTLS support#60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
add mTLS support #60
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -63,6 +63,52 @@ Users can quickly get started by referring to the use cases under the Apache-IoT | ||
| For those who wish to delve deeper into the client's usage and explore more advanced features, the samples directory contains additional code samples. | ||
| ## TLS and mTLS | ||
| Enable TLS by calling `SetUseSsl(true)`. The C# client uses the .NET certificate model and does not read Java truststores directly. If your certificates were generated with the JDK 17 Java/keytool workflow, `client.keystore` is PKCS#12 by default and can be used directly as the client certificate file; use `ca.crt` directly as the trusted root. | ||
| | keytool artifact | C# client usage | | ||
| | --- | --- | | ||
| | `ca.crt` | Pass to `SetRootCertificatePath` / `RootCertificatePath` to trust the server certificate | | ||
| | `client.keystore` | Contains the client private key and client certificate; JDK 17 creates PKCS#12 by default, so pass it directly to `SetClientCertificatePath` | | ||
| | `client.truststore` | Java client truststore; the C# client uses `ca.crt` instead | | ||
| | `server.truststore` | Server-side truststore for trusting client certificates; not a C# client option | | ||
| When `RootCertificatePath` is set, `Host` / `DataSource` must match the server certificate SAN. If you connect by IP address, the server certificate must include the corresponding IP SAN. | ||
| Only convert the keystore first if you are reusing an older JKS file, or if it was explicitly generated with `-storetype JKS`: | ||
| ```bash | ||
| $KT -importkeystore \ | ||
| -srckeystore client.keystore \ | ||
| -srcstorepass $PWD \ | ||
| -srcalias client \ | ||
| -destkeystore client.p12 \ | ||
| -deststoretype PKCS12 \ | ||
| -deststorepass $PWD \ | ||
| -destkeypass $PWD \ | ||
| -destalias client | ||
| ``` | ||
| C# builder example: | ||
| ```csharp | ||
| var sessionPool = new SessionPool.Builder() | ||
| .SetHost("127.0.0.1") | ||
| .SetPort(6667) | ||
| .SetUseSsl(true) | ||
| .SetRootCertificatePath("tls-certs/ca.crt") | ||
| .SetClientCertificatePath("tls-certs/client.keystore") | ||
| .SetClientCertificatePassword("IoTDB") | ||
| .Build(); | ||
| ``` | ||
| The ADO.NET connection string supports the same options: | ||
| ```text | ||
| DataSource=127.0.0.1;Port=6667;UseSsl=True;RootCertificatePath=tls-certs/ca.crt;ClientCertificatePath=tls-certs/client.keystore;ClientCertificatePassword=IoTDB | ||
HTHou marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ``` | ||
| ## Developer environment requirements for iotdb-client-csharp | ||
| ``` | ||
| @@ -101,4 +147,4 @@ dotnet format | ||
| The CI pipeline will automatically check code formatting on all pull requests. Please ensure your code is properly formatted before submitting a PR. | ||
| ## Publish your own client on nuget.org | ||
| You can find out how to publish from this [doc](./PUBLISH.md). | ||
| You can find out how to publish from this [doc](./PUBLISH.md). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -61,6 +61,51 @@ dotnet add package Apache.IoTDB | ||
| 对于希望深入了解客户端用法并探索更高级特性的用户,samples目录包含了额外的代码示例。 | ||
| ## TLS 和 mTLS | ||
| 通过 `SetUseSsl(true)` 开启 TLS。C# 客户端使用 .NET 的证书模型,不直接读取 Java truststore;如果证书按 JDK 17 的 Java/keytool 文档生成,`client.keystore` 默认就是 PKCS#12,可以直接作为客户端证书文件使用,并直接使用 `ca.crt` 作为信任根。 | ||
| | keytool 产物 | C# 客户端用法 | | ||
| | --- | --- | | ||
| | `ca.crt` | 传给 `SetRootCertificatePath` / `RootCertificatePath`,用于信任服务端证书 | | ||
| | `client.keystore` | 包含客户端私钥和客户端证书;JDK 17 默认是 PKCS#12,直接传给 `SetClientCertificatePath` | | ||
| | `client.truststore` | Java 客户端的 truststore;C# 侧用 `ca.crt`,不需要这个文件 | | ||
| | `server.truststore` | 服务端用于信任客户端证书,不是 C# 客户端参数 | | ||
| 配置 `RootCertificatePath` 后,`Host` / `DataSource` 必须匹配服务端证书 SAN。如果使用 IP 地址连接,服务端证书需要包含对应的 IP SAN。 | ||
| 只有在复用旧版 JDK 生成的 JKS 文件,或显式使用 `-storetype JKS` 生成 keystore 时,才需要先转换为 PKCS#12: | ||
| ```bash | ||
| $KT -importkeystore \ | ||
| -srckeystore client.keystore \ | ||
| -srcstorepass $PWD \ | ||
| -srcalias client \ | ||
| -destkeystore client.p12 \ | ||
| -deststoretype PKCS12 \ | ||
| -deststorepass $PWD \ | ||
| -destkeypass $PWD \ | ||
| -destalias client | ||
| ``` | ||
| C# builder 示例: | ||
| ```csharp | ||
| var sessionPool = new SessionPool.Builder() | ||
| .SetHost("127.0.0.1") | ||
HTHou marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .SetPort(6667) | ||
| .SetUseSsl(true) | ||
| .SetRootCertificatePath("tls-certs/ca.crt") | ||
| .SetClientCertificatePath("tls-certs/client.keystore") | ||
| .SetClientCertificatePassword("IoTDB") | ||
| .Build(); | ||
| ``` | ||
| ADO.NET 连接字符串也支持相同配置: | ||
| ```text | ||
| DataSource=127.0.0.1;Port=6667;UseSsl=True;RootCertificatePath=tls-certs/ca.crt;ClientCertificatePath=tls-certs/client.keystore;ClientCertificatePassword=IoTDB | ||
HTHou marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ``` | ||
| ## iotdb-client-csharp的开发者环境要求 | ||
| @@ -100,4 +145,4 @@ dotnet format | ||
| CI 流水线会在所有 Pull Request 上自动检查代码格式。请确保在提交 PR 之前代码格式正确。 | ||
| ## 在 nuget.org 上发布你自己的客户端 | ||
| 你可以在这个[文档](./PUBLISH.md)中找到如何发布 | ||
| 你可以在这个[文档](./PUBLISH.md)中找到如何发布 | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.