Esempio n. 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();
                        }
                }
        }
Esempio n. 2
0
        public async Task <IAdaptedConnection> OnConnectionAsync(ConnectionAdapterContext context)
        {
            var connection       = new StreamPipeConnection(_pipeFactory, context.ConnectionStream);
            var secureConnection = _listener.CreateSecurePipeline(connection);

            try
            {
                await secureConnection.HandshakeComplete;
            }
            catch (Exception ex)
            {
                _logger?.LogInformation(new EventId(10), ex, "Failed to complete a TLS handshake");
                return(new ClosedAdaptedConnection());
            }
            return(new TlsAdaptedConnection(secureConnection));
        }