Foros del Web » Programación para mayores de 30 ;) » .NET »

Conexión C# SSL y Npgsql

Estas en el tema de Conexión C# SSL y Npgsql en el foro de .NET en Foros del Web. Buenas tardes, Me encuentro desarrollando una aplicación (Winform en C#) la cual se conecta con PostgreSQL utilizando la librería Npgsql, actualmente requiero una conexión SSL ...
  #1 (permalink)  
Antiguo 06/06/2011, 12:12
 
Fecha de Ingreso: febrero-2010
Mensajes: 3
Antigüedad: 14 años, 2 meses
Puntos: 0
Pregunta Conexión C# SSL y Npgsql

Buenas tardes,

Me encuentro desarrollando una aplicación (Winform en C#) la cual se conecta con PostgreSQL utilizando la librería Npgsql, actualmente requiero una conexión SSL y he implementado el ejemplo como se muestra acá [URL="http://fxjr.blogspot.com/2010/04/using-ssl-client-certificates-with.html"]http://fxjr.blogspot.com/2010/04/using-ssl-client-certificates-with.html[/URL] (El código también lo coloco más abajo) pero recibo un error al momento de abrir la conexión el cual dice:

authentication or decryption failed

Aunque la conexión ya la he probado por línea de comandos (desde windows utilizando el comando psql.exe) con los certificados y funciona bien no logro determinar en donde se encuentra mi fallo..

Código:
String nueva_cadena = "server=192.168.194.219;" +
          "USER ID=usuario1;" +
          "PASSWORD=password1;" +
          "PROTOCOL=3;" +
          "DATABASE=qlocal;" +
          "SSL=true;" +
          "SSLMODE=Require;";
NpgsqlConnection nueva_conexion = new NpgsqlConnection(nueva_cadena);
nueva_conexion.ProvideClientCertificatesCallback += new ProvideClientCertificatesCallback(MyProvideClientCertificates);
nueva_conexion.CertificateSelectionCallback += new CertificateSelectionCallback(MyCertificateSelectionCallback);
nueva_conexion.CertificateValidationCallback += new CertificateValidationCallback(MyCertificateValidationCallback);
nueva_conexion.PrivateKeySelectionCallback += new PrivateKeySelectionCallback(MyPrivateKeySelectionCallback);
nueva_conexion.Open();

static void MyProvideClientCertificates(X509CertificateCollection clienteCertis)
  {
   X509Certificate cert = new X509Certificate(@"D:\postgresql.crt");
   clienteCertis.Add(cert);
  }

  static X509Certificate MyCertificateSelectionCallback(X509CertificateCollection clienteCertis, X509Certificate serverCerti, string hostDestino, X509CertificateCollection serverRequestedCertificates)
  {
   return clienteCertis[0];
  }

  static AsymmetricAlgorithm MyPrivateKeySelectionCallback(X509Certificate certificate, string targetHost)
  {
   PrivateKey key = null;
   try
   {
    key = PrivateKey.CreateFromFile(@"D:\postgresql.key");
   }
   catch (CryptographicException ex)
   {
    Console.WriteLine();
    Console.WriteLine();
    Console.WriteLine(ex);
    Console.WriteLine();
    Console.WriteLine();
   }

   if (key == null)
    return null;

   return key.RSA;
  }
  #endregion

  static bool MyCertificateValidationCallback(X509Certificate certificate, int[] certificateErrors)
  {
   System.Console.WriteLine(certificateErrors[0]);
   return true;
  }
Muchas gracias por la atención.

Etiquetas: c#_y_ssl, conexion, postgresql_y_ssl, ssl
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:03.