【发布时间】:2023-01-14 10:39:22
【问题描述】:
我已获得 SQL Server 的证书,该证书已成功安装和激活。我可以从日志中确认这一点:
The certificate [Cert Hash(sha1) "xxxxxxxxxxxxxxxxxxE5C050F7D75F58E4E2F"] was successfully loaded for encryption.
使用 SSMS 连接到数据库是成功的,只需在不信任服务器证书的情况下对连接进行加密即可。
我想使用 WSL 和后来的 docker 来复制它。
我正在使用一个简单的 .net 6 控制台应用程序对此进行测试:
var con = new SqlConnection("Server=domain.host.eu,50730;Database=databasename;User Id=user;Password='password';");
await con.OpenAsync();
var version = con.ExecuteScalar<string>("SELECT @@VERSION");
Console.WriteLine(version);
这有效,如果我将 Trust Server Certificate=True; 添加到连接字符串。没有它,连接失败:
Unhandled exception. Microsoft.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: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)
at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
我想从 pfx 中提取证书:
openssl pkcs12 -in host.domain.eu.pem.pfx -clcerts -nokeys -out host.domain.eu.crt
sudo cp host.domain.eu.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
不幸的是,这失败并显示相同的错误消息,我不知道我哪里出错了。我只能假设,我在 Linux 上对证书的处理是错误的。
【问题讨论】:
-
@AaronBertrand 我有,但不幸的是他们没有提供可行/有效的解决方案,除了信任服务器证书
-
Cleptus,我知道它正在工作,通过使用 SSMS 从 Windows 机器上测试它并从日志中验证,证书已加载。
-
那么,您采取了哪些步骤将其添加到 Linux 上的 SQL Server?
标签: c# sql-server ubuntu ssl ssl-certificate