.Net SqlConnection, server authentication and certificate binding

How to connect a certificate when using s SqlConnection ? From SqlConnection Connection String Parameter Keywords and values , I know that I can set Encrypted to true to force (encourage?) The use of SSL / TLS.

However, to bind the certificate, I believe that we need to use the ServerCertificateValidationCallback from the ServicePointManager (the sample code suggested by Arne Vajhøj for HTTP / HTTPS). I do not understand how to connect in PinCertificate (from ServicePointManager ) to SqlConnection .

UPDATE: When chatting with Arne Wajhai at microsoft.public.dotnet.languages.csharp, it seems that he may not have the desired control over the connection. Vajhøj offered a link to Encrypt connections to SQL Server .

 public static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback = PinCertificate; WebRequest wr = WebRequest.Create("https://www.google.com/"); wr.GetResponse(); } public static bool PinCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { byte[] chash = certificate.GetCertHash(); StringBuilder sb = new StringBuilder(chash.Length * 2); foreach (byte b in chash) sb.AppendFormat("{0:X2}", b); // Verify against known SHA1 thumb print of the certificate String hash = sb.ToString(); if (hash != "C1956DC8A7DFB2A5A56934DA09778E3A11023358") return false; return true; } 
+6
source share
1 answer

what about something like:

 System.Net.ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate) Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean 'Return True to force the certificate to be accepted. Return True End Function 
0
source

Source: https://habr.com/ru/post/904828/


All Articles