public QuicListener(System.Net.Quic.Implementations.QuicImplementationProvider implementationProvider, IPEndPoint listenEndPoint, System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions)
 {
 }
 public QuicListener(System.Net.IPEndPoint listenEndPoint, System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions)
 {
 }
Beispiel #3
0
 public System.Threading.Tasks.Task AuthenticateAsServerAsync(System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions, System.Threading.CancellationToken cancellationToken)
 {
     throw null;
 }
Beispiel #4
0
 public System.Threading.Tasks.Task AuthenticateAsServerAsync(System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions, System.Threading.CancellationToken cancellationToken)
 {
     throw new PlatformNotSupportedException();
 }
Beispiel #5
0
        public static async void RunServer(object server)
        {
            System.Net.Sockets.TcpListener tcp = (System.Net.Sockets.TcpListener)server;
            tcp.Start();
            System.Console.WriteLine("Listening");
            while (true)
            {
                using (System.Net.Sockets.TcpClient socket = await tcp.AcceptTcpClientAsync())
                {
                    System.Console.WriteLine("Client connected");
                    // SslStream stream = new SslStream(socket.GetStream());
                    // NoValidateServerCertificate
                    // https://stackoverflow.com/questions/57399520/set-sni-in-a-client-for-a-streamsocket-or-sslstream
                    // https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
                    // SslStream stream = new SslStream(socket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate))
                    // SslStream stream = new SslStream(socket.GetStream(), false, new RemoteCertificateValidationCallback(NoValidateServerCertificate) ,new LocalCertificateSelectionCallback(My))


                    // ((System.Net.IPEndPoint)socket.Client.RemoteEndPoint).Address.ToString();

#if false
                    StreamExtended.DefaultBufferPool bufferPool = new StreamExtended.DefaultBufferPool();

                    StreamExtended.Network.CustomBufferedStream yourClientStream =
                        new StreamExtended.Network.CustomBufferedStream(socket.GetStream(), bufferPool, 4096);

                    StreamExtended.ClientHelloInfo clientSslHelloInfo =
                        await StreamExtended.SslTools.PeekClientHello(yourClientStream, bufferPool);

                    //will be null if no client hello was received (not a SSL connection)
                    if (clientSslHelloInfo != null)
                    {
                        string sniHostName = clientSslHelloInfo.Extensions?.FirstOrDefault(x => x.Key == "server_name").Value?.Data;
                        System.Console.WriteLine(sniHostName);
                    }
                    else
                    {
                        System.Console.WriteLine("ciao");
                    }
#else
                    System.Net.Sockets.NetworkStream yourClientStream = socket.GetStream();
#endif

                    System.Net.Security.SslStream stream = new System.Net.Security.SslStream(yourClientStream, false
                                                                                             , new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate))
                    {
                        ReadTimeout  = IOTimeout,
                        WriteTimeout = IOTimeout
                    };

                    // System.Net.Security.SslStream stream;
                    // .NET 5.0 only stream.TargetHostName

                    // Specifying a delegate instead of directly providing the certificate works
                    System.Net.Security.SslServerAuthenticationOptions sslOptions =
                        new System.Net.Security.SslServerAuthenticationOptions
                    {
                        // ServerCertificate = certificate,
                        ServerCertificateSelectionCallback = (sender, name) => cert,
                        CertificateRevocationCheckMode     = System.Security.Cryptography.X509Certificates.X509RevocationMode.Offline,
                        EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12
                    };
                    stream.AuthenticateAsServer(sslOptions);

                    // new System.Net.Security.SslStream(null, true, null,null, )


                    // https://docs.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-5.0
                    // System.Net.Security.ServerCertificateSelectionCallback
                    // System.Net.Security.SslServerAuthenticationOptions
                    System.Console.WriteLine(stream.TargetHostName);
                    // await stream.AuthenticateAsServerAsync(cert);
                    // await stream.AuthenticateAsServerAsync(cert, false, System.Security.Authentication.SslProtocols.Tls13, true);

                    // System.Console.WriteLine(stream.TargetHostName);

                    while (true)
                    {
                        //NetworkStream stream= socket.GetStream();
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        System.IO.MemoryStream    ms = new System.IO.MemoryStream();
                        int len = -1;
                        do
                        {
                            byte[] buff = new byte[1000];
                            len = await stream.ReadAsync(buff, 0, buff.Length);

                            await ms.WriteAsync(buff, 0, len);

                            string line = new string(System.Text.Encoding.UTF8.GetChars(buff, 0, len));
                            if (line.EndsWith("<EOF>"))
                            {
                                break;
                            }
                        } while (len != 0);

                        //string echo=Encoding.UTF8.GetString(buff).Trim('\0');
                        string echo = System.Text.Encoding.UTF8.GetString(ms.ToArray());
                        ms.Close();
                        System.Console.WriteLine(echo);
                        if (echo.Equals("q"))
                        {
                            break;
                        }
                    } // Whend

                    socket.Close();
                } // End Using socket
            }     // Whend
        }         // End Task RunServer
Beispiel #6
0
 public QuicListener(IPEndPoint listenEndPoint, System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions, bool mock = false)
 {
 }