Guest User

Untitled

a guest
Apr 13th, 2014
328
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     class Program
  2.     {
  3.         static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  4.         {
  5.             if (sslPolicyErrors == SslPolicyErrors.None) return true;
  6.             Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
  7.             return false;
  8.         }
  9.  
  10.         static void Main()
  11.         {
  12.             var tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080);
  13.             tcpListener.Start();
  14.             var clientAccept = tcpListener.AcceptTcpClient();
  15.             Thread.Sleep(1000);
  16.  
  17.             if (clientAccept.Available > 0)
  18.             {
  19.                 var sslStream = new SslStream(clientAccept.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
  20.                 var certificate = new X509Certificate(@"C:\Users\orlov_000\Desktop\server.pfx");
  21.                 sslStream.AuthenticateAsServer(certificate);
  22.             }
  23.  
  24.             Console.ReadLine();
  25.         }
  26.     }
RAW Paste Data