¿Cómo se puede anclar un certificado cuando se usa s SqlConnection
? Desde SqlConnection Connection String Parameter Keywords & Values, sé que puedo configurar Encrypted
en true
para forzar (¿alentar?) El uso de SSL/TLS..Net SqlConnection, Server Authentication y Certificate Pinning
Sin embargo, para anclar un certificado, creo que necesitamos usar ServerCertificateValidationCallback
de ServicePointManager
(el código de ejemplo siguiente fue ofrecido por Arne Vajhøj para HTTP/HTTPS). No tengo claro cómo cablear en PinCertificate
(de ServicePointManager
) a SqlConnection
.
ACTUALIZACIÓN: Hablando con Arne Vajhøj en microsoft.public.dotnet.languages.csharp, parece que no es posible tener el control deseado sobre la conexión. Vajhøj ofreció un enlace al Encrypting 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;
}
Un ejemplo de validación de certificados en VB.NET: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/ 5f5af31c-74f2-4147-8b70-e9e8ec03c76a. Debería ser lo suficientemente fácil de convertir. –
El ejemplo de MSDN utiliza 'ServicePointManager' y' ServerCertificateValidationCallback' (llamando a 'MyCertValidationCb'). No es diferente de la muestra que publiqué. Todavía no tengo claro cómo se conecta 'ServerCertificateValidationCallback' en' SqlConnection'. – jww
http://support.microsoft.com/default.aspx?scid=276553 ¿Esto ayuda? – King