Пример #1
0
        private void ProcessRequestSSL(TcpClient client) => Task.Run(async() =>
        {
            int conId        = id++;
            string rhostname = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
            Debug.WriteLine("{" + conId + "} ssl New connection - " + rhostname);

            SslStream ssl = null;
            try
            {
                ssl = new SslStream(client.GetStream(), false);
                ssl.AuthenticateAsServer(cert.Load(), false, SslProtocols.Tls12, false);

                await _doRequest(conId, rhostname, ssl.AsInputStream(), ssl);
            }
            catch (Exception e)
            {
                Debug.WriteLine("SSL stream error");
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
                return;
            }
            finally
            {
                ssl?.Dispose();
            }

            Debug.WriteLine("{" + conId + "} ssl Connection done - " + rhostname);
        });