.NET 5 + Microsoft.Data.SqlClient - 从传输流中收到意外的 EOF 或 0 字节
.NET 5 + Microsoft.Data.SqlClient - Received an unexpected EOF or 0 bytes from the transport stream
我将我的应用程序从 .NET Core 3.1 更新到 .NET 5,现在我无法打开与我的 SQL 服务器数据库的连接。最里面的异常错误信息是
Received an unexpected EOF or 0 bytes from the transport stream.
顶级错误信息是
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)
除了 .NET 5 的版本,我只更新了基础镜像,从 3.1-bionic
到 5.0.3-focal-amd64
还有什么我应该做的吗?
编辑 1:
我发现 this article 似乎与我的经历密切相关。但是在将我的 CipherString
更改为建议的值后,错误没有任何变化。一样。也许有 CipherString = ANY
?
NOTE
The Microsoft-recommended action is to improve security by upgrading your SQL Servers to support TLS v1.2
参考文献:
- SqlClient troubleshooting guide
- How to enable TLS 1.2
- KB3135244 - TLS 1.2 support for Microsoft SQL Server
但是,如果您无法升级 SQL 服务器以支持 TLS v1.2,您可以通过编辑 [=14] 影响可用的密码套件来降级协商的客户端协议=] 文件.
因为 Alpine 容器是最基本的,所以从安装您最喜欢的编辑器开始,例如:
apt-get update
apt-get install nano
编辑您的 /etc/ssl/openssl.cnf
以将以下行放在文件的开头:
openssl_conf = default_conf
以及文件末尾的以下行:
########## Override default settings to enable TLS v1.0 and 1.1 ##########
[ default_conf ]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
CipherString = DEFAULT:@SECLEVEL=1
#It really should be:
#CipherString = DEFAULT:@SECLEVEL=2
这将影响容器中所有启用 openssl 的进程。您可以使用以下命令测试更改前后的连接性:
# Test TLS v1.0 connectivity
openssl s_client -host google.com -port 443 -tls1
# Test TLS v1.1 connectivity
openssl s_client -host google.com -port 443 -tls1_1
我将我的应用程序从 .NET Core 3.1 更新到 .NET 5,现在我无法打开与我的 SQL 服务器数据库的连接。最里面的异常错误信息是
Received an unexpected EOF or 0 bytes from the transport stream.
顶级错误信息是
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)
除了 .NET 5 的版本,我只更新了基础镜像,从 3.1-bionic
到 5.0.3-focal-amd64
还有什么我应该做的吗?
编辑 1:
我发现 this article 似乎与我的经历密切相关。但是在将我的 CipherString
更改为建议的值后,错误没有任何变化。一样。也许有 CipherString = ANY
?
NOTE
The Microsoft-recommended action is to improve security by upgrading your SQL Servers to support TLS v1.2
参考文献:
- SqlClient troubleshooting guide
- How to enable TLS 1.2
- KB3135244 - TLS 1.2 support for Microsoft SQL Server
但是,如果您无法升级 SQL 服务器以支持 TLS v1.2,您可以通过编辑 [=14] 影响可用的密码套件来降级协商的客户端协议=] 文件.
因为 Alpine 容器是最基本的,所以从安装您最喜欢的编辑器开始,例如:
apt-get update
apt-get install nano
编辑您的 /etc/ssl/openssl.cnf
以将以下行放在文件的开头:
openssl_conf = default_conf
以及文件末尾的以下行:
########## Override default settings to enable TLS v1.0 and 1.1 ##########
[ default_conf ]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
CipherString = DEFAULT:@SECLEVEL=1
#It really should be:
#CipherString = DEFAULT:@SECLEVEL=2
这将影响容器中所有启用 openssl 的进程。您可以使用以下命令测试更改前后的连接性:
# Test TLS v1.0 connectivity
openssl s_client -host google.com -port 443 -tls1
# Test TLS v1.1 connectivity
openssl s_client -host google.com -port 443 -tls1_1