Exemplo n.º 1
0
 private void HandleKeyblock(IAsyncResult res)
 {
     Logger.Info("start handling keyblock request");
     StartAccept(_vks, HandleKeyblock); //listen for new connections again
     try
     {
         var client = _vks.EndAcceptTcpClient(res);
         //proceed
         var vks = new KeyblockCall();
         vks.Handle(client.GetStream(), true);
         client.Close();
     }
     catch (Exception ex)
     {
         if (!_stopping)
         {
             Logger.Warn($"Failed to handle Keyblock: {ex.Message}");
         }
     }
 }
Exemplo n.º 2
0
        public bool ProcessClient(TcpClient client)
        {
            Logger.Debug("Handle a client...");
            // A client has connected. Create the
            // SslStream using the client's network stream.
            SslStream sslStream = new SslStream(client.GetStream(), false);

            // Authenticate the server but don't require the client to authenticate.
            try
            {
                var vcas = new KeyblockCall();
                sslStream.AuthenticateAsServer(_serverCertificate, false, SslProtocols.Tls, false);
                // Read a message from the client.
                return(vcas.Handle(sslStream, false));
            }
            catch (Exception e)
            {
                Logger.Info($"Exception: {e.Message}");
                if (e.InnerException != null)
                {
                    Logger.Info($"Inner exception: {e.InnerException.Message}");
                }
                Logger.Info("Authentication failed - closing the connection.");
                sslStream.Close();
                client.Close();
            }
            finally
            {
                // The client stream will be closed with the sslStream
                // because we specified this behavior when creating
                // the sslStream.
                sslStream.Close();
                client.Close();
            }
            return(false);
        }