ASP.NET 核心。System.Data.SqlClient.SqlException - SSL_ERROR_SSL

ASP.NET Core. System.Data.SqlClient.SqlException - SSL_ERROR_SSL

提问人:Роман Кириллов 提问时间:8/24/2022 最后编辑:MassifoxРоман Кириллов 更新时间:9/9/2022 访问量:1603

问:

我的规格:装有 MS SQL Server 2008 (SP4) 的 PC - 10.0.6535.0;Linux (Debian GNU/Linux) 上的 PC 和我的 ASP.NET Core 5.0 应用程序(用于 sql - System.Data.SqlClient)。 我无法向远程 SQL 服务器发出成功的 sql 请求。

记录:

[2022-08-24 13:41:55.3955] [ERROR] [GPNA.MyApplication.Infrastructure.Modules.DataLoaderModule] System.AggregateException: One or more errors occurred. (A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught))
 ---> System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
 ---> Interop+Crypto+OpenSslCryptographicException: error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
   --- End of inner exception stack trace ---

SSL有什么问题?– 我在 Visual Studio 中关闭了 SSL。并尝试了 SqlConnectionString 中的不同变体,使用 linux config openssl.cnf 播放。问题是由我的应用程序、Linux 还是 SQL Server 引起的?

SqlConnectionString 如下所示:

Data Source=10.20.17.76;Initial Catalog=Runtime; User ID=sa; Password=******; Connect Timeout=300; TrustServerCertificate=True; Encrypt = False

谢谢!

更新: 我尝试在远程 PC Windows Server 2008 上启动我的应用程序,该应用程序使用 MS SQL Server 连接到 PC,它可以正常工作!在 Linux 上 - 不要。因此,问题不在MS SQL Server中。

C# SQL-Server Linux System.Data.SqlClient

评论

1赞 Panagiotis Kanavos 8/24/2022
SQL Server 2008 在几年前就不再受支持了。此外,如果服务器需要身份验证,则客户端将被迫使用加密连接或失败也没关系。通过修改,你增加了问题,而不是解决任何问题Encrypt=Falseopenssl.cnf
1赞 Panagiotis Kanavos 8/24/2022
至于实际错误,这意味着由于已有 14 年历史的 SQL Server 2008 多年来一直不受支持,因此除非对其进行修补,否则它不支持最新的 TLS 版本,如 TLS1.2。ssl_choose_client_version:unsupported protocol
0赞 Роман Кириллов 8/24/2022
好的,谢谢!我不确定我是否可以修补SQL Server。但是我可以配置 Linux 或 .NET 应用程序。
0赞 Panagiotis Kanavos 8/24/2022
如果服务器需要加密,则客户端无法禁用它。虽然可以在 OpenSSL 中重新启用过时的版本,但这将阻止您连接到需要较新版本的受支持的 SQL Server 版本。这包括 Azure SQL 或 AWS RDS
1赞 Panagiotis Kanavos 8/25/2022
你的编辑证明与你刚才声称的完全相反。旧的和不受支持的 Windows Server 2008 使用与旧的和不受支持的 SQL Server 2008 相同的 TLS 版本,这就是您可以连接的原因。您将无法从任何受支持的 Windows 版本进行连接。目前,它是 Windows 10 及更高版本、Windows Server 2016 及更高版本

答:

2赞 Роман Кириллов 9/5/2022 #1

我的错误:我应该写“TLSv1”,但我写了“TLSv1.0”,基于 Debian 的发行版。

openssl.cnf
[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT@SECLEVEL=1