Skip to content

Instantly share code, notes, and snippets.

@franciscojunior
Last active December 19, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franciscojunior/5930034 to your computer and use it in GitHub Desktop.
Save franciscojunior/5930034 to your computer and use it in GitHub Desktop.
Npgsql SSL Test program
hostssl npgsql_tests all 127.0.0.1/32 trust clientcert=1
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Npgsql;
using Mono.Security.Protocol.Tls;
using Mono.Security.Authenticode;
namespace my
{
class Program
{
public static string CONNSTRING = "server=127.0.0.1;userid=npgsql_tests;database=npgsql_tests;ssl=true;sslmode=require;";
public static void Main(string[] args)
{
NpgsqlConnection conn = new NpgsqlConnection(CONNSTRING);
conn.ProvideClientCertificatesCallback += new ProvideClientCertificatesCallback(
MyProvideClientCertificates
);
conn.ValidateRemoteCertificateCallback += (a, b, c) => { return true; };
try
{
conn.Open();
System.Console.WriteLine("Verbindung aufgebaut");
}
catch (Exception e)
{
System.Console.WriteLine(e);
}
finally
{
conn.Close();
System.Console.ReadLine();
}
}
static void MyProvideClientCertificates(X509CertificateCollection clienteCertis)
{
X509Certificate cert = new X509Certificate("postgresql.pfx");
clienteCertis.Add(cert);
}
}
}
System.IO.IOException: Não é possível ler os dados da conexão de transporte: Foi
forçado o cancelamento de uma conexão existente pelo host remoto. ---> System.N
et.Sockets.SocketException: Foi forçado o cancelamento de uma conexão existente
pelo host remoto
em System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)
em System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
em System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 c
ount)
em System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offse
t, Int32 count, AsyncProtocolRequest asyncRequest)
em System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, I
nt32 count, AsyncProtocolRequest asyncRequest)
em System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, In
t32 count, AsyncProtocolRequest asyncRequest)
em System.Net.Security.SslStream.Read(Byte[] buffer, Int32 offset, Int32 coun
t)
em System.IO.BufferedStream.ReadByte()
em Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__b.MoveNext() na C:\Us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment