Пример #1
0
        public static void Main(string[] args)
        {
            var logFactory = new LoggerFactory();

            logFactory.AddConsole(LogLevel.Trace);

            using (var factory = new PipeFactory())
                using (var list = new CertificateList())
                {
                    var thumb = "48026c976caaf7f3a72d38c17d16ce69d04a6053".ToUpper();
                    //var provider = new Leto.Tls13.Certificates.Windows.CertificateProvider();
                    //list.AddCertificate(provider.LoadCertificate(new X509Certificate2(_rsaCertPath, _certificatePassword)));
                    //list.AddCertificate(provider.LoadCertificateFromStore(thumb,true));
                    var provider = new Leto.Tls13.Certificates.OpenSsl11.CertificateProvider();
                    list.AddCertificate(provider.LoadPfx12(_ecdsaCertPath, _certificatePassword));
                    using (var serverContext = new SecurePipeListener(factory, list, logFactory))
                        using (var socketClient = new System.IO.Pipelines.Networking.Sockets.SocketListener(factory))
                        {
                            var ip         = IPAddress.Loopback;
                            int port       = 443;
                            var ipEndPoint = new IPEndPoint(ip, port);
                            socketClient.OnConnection(s =>
                            {
                                Console.WriteLine("Connected");
                                var sp = serverContext.CreateSecurePipeline(s);
                                Console.WriteLine("Secure Connection Created");
                                return(ServerLoop.HandleConnection(sp, logFactory));
                            });
                            socketClient.Start(ipEndPoint);
                            Console.ReadLine();
                        }
                }
        }
Пример #2
0
        public async Task Pipe2PipeTest()
        {
            var readData  = string.Empty;
            var wait      = new System.Threading.ManualResetEvent(false);
            var ipAddress = new IPEndPoint(IPAddress.Loopback, 27777);

            using (var securePipeOptions = new System.IO.Pipelines.Networking.Sockets.SocketListener())
                using (var secureListener = new OpenSslSecurePipeListener(Data.Certificates.RSACertificate))
                {
                    //secureListener.CryptoProvider = new TestingCryptoProvider();
                    secureListener.CryptoProvider.CipherSuites.SetCipherSuites(new CipherSuites.CipherSuite[] { CipherSuites.PredefinedCipherSuites.GetSuiteByName(CipherSuites.PredefinedCipherSuites.PredefinedSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) });
                    securePipeOptions.OnConnection(async(conn) =>
                    {
                        var pipe = await secureListener.CreateConnection(conn);
                        Console.WriteLine("Handshake Done");
                        var reader = await pipe.Input.ReadAsync();
                        readData   = Encoding.UTF8.GetString(reader.Buffer.ToArray());
                        var writer = pipe.Output.Alloc();
                        writer.Append(reader.Buffer);
                        await writer.FlushAsync();
                        wait.Set();
                    });
                    securePipeOptions.Start(ipAddress);

                    var client = await secureListener.CreateClientConnection(await System.IO.Pipelines.Networking.Sockets.SocketConnection.ConnectAsync(ipAddress));


                    //        wait.WaitOne();
                    //        Assert.Equal("", readData);
                }
        }
Пример #3
0
 public static void Main(string[] args)
 {
     using (var factory = new PipelineFactory())
         using (var list = new CertificateList())
         {
             var thumb    = "48026c976caaf7f3a72d38c17d16ce69d04a6053".ToUpper();
             var provider = new Leto.Tls13.Certificates.Windows.CertificateProvider();
             list.AddCertificate(provider.LoadCertificateFromStore(thumb, true));
             using (var serverContext = new SecurePipelineListener(factory, list))
                 using (var socketClient = new System.IO.Pipelines.Networking.Sockets.SocketListener(factory))
                 {
                     var ip         = IPAddress.Any;
                     int port       = 443;
                     var ipEndPoint = new IPEndPoint(ip, port);
                     socketClient.OnConnection(async s =>
                     {
                         Console.WriteLine("Connected");
                         var sp = serverContext.CreateSecurePipeline(s);
                         Console.WriteLine("Secure Connection Created");
                         await ServerLoop.HandleConnection(sp);
                     });
                     socketClient.Start(ipEndPoint);
                     Console.ReadLine();
                 }
         }
 }