/// <summary> /// Handles the connection process of clients /// </summary> private void HandleClientComm(object sender) { //This conntects the client //first we need an rescue timer _BootUpTimer = new System.Threading.Timer(new System.Threading.TimerCallback(_BootUpTimer_Elapsed), null, 100, 100); //bool leaveInnerStreamOpen = false; try { // encryption if (_Mode == VaserOptions.ModeKerberos) { QueueSend = QueueSendKerberos; } if (_Mode == VaserOptions.ModeSSL) { QueueSend = QueueSendSSL; } if (_Mode == VaserOptions.ModeNotEncrypted) { QueueSend = QueueSendNotEncrypted; } if (IsServer) { //server if (_Mode == VaserOptions.ModeKerberos) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); link.IsAuthenticated = false; link.IsEncrypted = false; link.IsMutuallyAuthenticated = false; link.IsSigned = false; link.IsServer = false; link.UserName = "******"; } if (_Mode == VaserOptions.ModeSSL) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); link.IsEncrypted = true; link.IsServer = true; } if (_Mode == VaserOptions.ModeNotEncrypted) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); link.IsServer = true; } link.vServer = server; BootupDone = true; server.AddNewLink(link); } else { //client if (_Mode == VaserOptions.ModeKerberos) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); link.IsAuthenticated = false; link.IsEncrypted = false; link.IsMutuallyAuthenticated = false; link.IsSigned = false; link.IsServer = false; } if (_Mode == VaserOptions.ModeSSL) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); link.IsEncrypted = true; } if (_Mode == VaserOptions.ModeNotEncrypted) { //Read line from the remote client. inStream = _SocketTCPClient.InputStream.AsStreamForRead(); //Send the line back to the remote client. outStream = new DataWriter(_SocketTCPClient.OutputStream); } //Thread.Sleep(50); BootupDone = true; IAsyncAction asyncAction = null; _IsAccepted = true; if (_Mode == VaserOptions.ModeNotEncrypted) { asyncAction = ThreadPool.RunAsync(ReceiveNotEncrypted); } if (_Mode == VaserOptions.ModeKerberos) { asyncAction = ThreadPool.RunAsync(ReceiveKerberos); } if (_Mode == VaserOptions.ModeSSL) { asyncAction = ThreadPool.RunAsync(ReceiveSSL); } } if (EnableHeartbeat) { HeartbeatTimer = new System.Threading.Timer(new System.Threading.TimerCallback(OnHeartbeatEvent), null, HeartbeatMilliseconds, HeartbeatMilliseconds); } } catch (Exception e) { Debug.WriteLine("Authentication failed. " + e.ToString()); _BootUpTimer.Dispose(); Stop(); return; } // encryption END _BootUpTimer.Dispose(); _BootUpTimer = null; }
/// <summary> /// Handles the connection process of clients /// </summary> private void HandleClientComm(object sender) { //This conntects the client //first we need an rescue timer _BootUpTimer = new Timer(new TimerCallback(_BootUpTimer_Elapsed), null, 100, 100); bool leaveInnerStreamOpen = false; try { // encryption if (_Mode == VaserOptions.ModeSSL) { QueueSend = QueueSendSSL; _sslStream = new SslStream(new NetworkStream(_SocketTCPClient), leaveInnerStreamOpen); } if (_Mode == VaserOptions.ModeNotEncrypted) { QueueSend = QueueSendNotEncrypted; } if (_Mode == VaserOptions.ModeNamedPipeServerStream) { //QueueSend = QueueSendNotEncrypted; } if (_Mode == VaserOptions.ModeNamedPipeClientStream) { //QueueSend = QueueSendNotEncrypted; } if (IsServer) { //server if (_Mode == VaserOptions.ModeSSL) { if (_vSSLS._enabledSslProtocols == SslProtocols.None) { _sslStream.AuthenticateAsServer(_vSSLS._serverCertificate); } else { _sslStream.AuthenticateAsServer(_vSSLS._serverCertificate, _vSSLS._clientCertificateRequired, _vSSLS._enabledSslProtocols, _vSSLS._checkCertificateRevocation); } link.IsEncrypted = true; link.IsServer = true; } if (_Mode == VaserOptions.ModeNotEncrypted) { link.IsServer = true; } if (_Mode == VaserOptions.ModeNamedPipeServerStream) { link.IsServer = true; } link.vServer = server; BootupDone = true; server.AddNewLink(link); } else { //client if (_Mode == VaserOptions.ModeSSL) { if (_vSSLC._clientCertificates == null) { _sslStream.AuthenticateAsClient(_vSSLC._targetHost); } else { _sslStream.AuthenticateAsClient(_vSSLC._targetHost, _vSSLC._clientCertificates, _vSSLC._enabledSslProtocols, _vSSLC._checkCertificateRevocation); } link.IsEncrypted = true; } if (_Mode == VaserOptions.ModeNamedPipeClientStream) { } //Thread.Sleep(50); BootupDone = true; _IsAccepted = true; if (_Mode == VaserOptions.ModeNotEncrypted) { ThreadPool.QueueUserWorkItem(ReceiveNotEncrypted); } if (_Mode == VaserOptions.ModeSSL) { ThreadPool.QueueUserWorkItem(ReceiveSSL); } } if (EnableHeartbeat) { HeartbeatTimer = new Timer(new TimerCallback(OnHeartbeatEvent), null, HeartbeatMilliseconds, HeartbeatMilliseconds); } } catch (AuthenticationException e) { Debug.WriteLine("Authentication failed. " + e.ToString()); _BootUpTimer.Dispose(); Stop(); return; } catch (Exception e) { Debug.WriteLine("Authentication failed. " + e.ToString()); _BootUpTimer.Dispose(); Stop(); return; } // encryption END _BootUpTimer.Dispose(); _BootUpTimer = null; }
/// <summary> /// Handles the connection process of clients /// </summary> private void HandleClientComm(object sender) { //This conntects the client //first we need an rescue timer _BootUpTimer = new Timer(new TimerCallback(_BootUpTimer_Elapsed), null, 0, 100); bool leaveInnerStreamOpen = false; try { _SocketTCPClient.LingerState = new LingerOption(true, 10); // encryption if (_Mode == VaserOptions.ModeKerberos) { _ConnectionStream = new NetworkStream(_SocketTCPClient); QueueSend = QueueSendKerberos; _AuthStream = new NegotiateStream(_ConnectionStream, leaveInnerStreamOpen); } if (_Mode == VaserOptions.ModeSSL) { _ConnectionStream = new NetworkStream(_SocketTCPClient); QueueSend = QueueSendSSL; _sslStream = new SslStream(_ConnectionStream, leaveInnerStreamOpen); } if (_Mode == VaserOptions.ModeNotEncrypted) { QueueSend = QueueSendNotEncrypted; //_NotEncryptedStream = _ConnectionStream; } if (IsServer) { //server if (_Mode == VaserOptions.ModeKerberos) { if (_vKerberosS._policy == null) { if (_vKerberosS._credential == null) { _AuthStream.AuthenticateAsServerAsync(); } else { _AuthStream.AuthenticateAsServerAsync(_vKerberosS._credential, _vKerberosS._requiredProtectionLevel, _vKerberosS._requiredImpersonationLevel); } } else { if (_vKerberosS._credential == null) { _AuthStream.AuthenticateAsServerAsync(_vKerberosS._policy); } else { _AuthStream.AuthenticateAsServerAsync(_vKerberosS._credential, _vKerberosS._policy, _vKerberosS._requiredProtectionLevel, _vKerberosS._requiredImpersonationLevel); } } link.IsAuthenticated = _AuthStream.IsAuthenticated; link.IsEncrypted = _AuthStream.IsEncrypted; link.IsMutuallyAuthenticated = _AuthStream.IsMutuallyAuthenticated; link.IsSigned = _AuthStream.IsSigned; link.IsServer = _AuthStream.IsServer; IIdentity id = _AuthStream.RemoteIdentity; link.UserName = id.Name; } if (_Mode == VaserOptions.ModeSSL) { if (_vSSLS._enabledSslProtocols == SslProtocols.None) { _sslStream.AuthenticateAsServerAsync(_vSSLS._serverCertificate); } else { _sslStream.AuthenticateAsServerAsync(_vSSLS._serverCertificate, _vSSLS._clientCertificateRequired, _vSSLS._enabledSslProtocols, _vSSLS._checkCertificateRevocation); } link.IsEncrypted = true; link.IsServer = true; } if (_Mode == VaserOptions.ModeNotEncrypted) { link.IsServer = true; } link.vServer = server; BootupDone = true; server.AddNewLink(link); } else { //client if (_Mode == VaserOptions.ModeKerberos) { if (_vKerberosC._binding == null) { if (_vKerberosC._credential == null) { _AuthStream.AuthenticateAsClientAsync(); } else { if (_vKerberosC._requiredProtectionLevel == ProtectionLevel.None && _vKerberosC._requiredImpersonationLevel == TokenImpersonationLevel.None) { _AuthStream.AuthenticateAsClientAsync(_vKerberosC._credential, _vKerberosC._targetName); } else { _AuthStream.AuthenticateAsClientAsync(_vKerberosC._credential, _vKerberosC._targetName, _vKerberosC._requiredProtectionLevel, _vKerberosC._requiredImpersonationLevel); } } } else { if (_vKerberosC._requiredProtectionLevel == ProtectionLevel.None && _vKerberosC._requiredImpersonationLevel == TokenImpersonationLevel.None) { _AuthStream.AuthenticateAsClientAsync(_vKerberosC._credential, _vKerberosC._binding, _vKerberosC._targetName); } else { _AuthStream.AuthenticateAsClientAsync(_vKerberosC._credential, _vKerberosC._binding, _vKerberosC._targetName, _vKerberosC._requiredProtectionLevel, _vKerberosC._requiredImpersonationLevel); } } link.IsAuthenticated = _AuthStream.IsAuthenticated; link.IsEncrypted = _AuthStream.IsEncrypted; link.IsMutuallyAuthenticated = _AuthStream.IsMutuallyAuthenticated; link.IsSigned = _AuthStream.IsSigned; link.IsServer = _AuthStream.IsServer; IIdentity id = _AuthStream.RemoteIdentity; } if (_Mode == VaserOptions.ModeSSL) { if (_vSSLC._clientCertificates == null) { _sslStream.AuthenticateAsClientAsync(_vSSLC._targetHost); } else { _sslStream.AuthenticateAsClientAsync(_vSSLC._targetHost, _vSSLC._clientCertificates, _vSSLC._enabledSslProtocols, _vSSLC._checkCertificateRevocation); } link.IsEncrypted = true; } //Thread.Sleep(50); BootupDone = true; _IsAccepted = true; if (_Mode == VaserOptions.ModeNotEncrypted) { ThreadPool.QueueUserWorkItem(ReceiveNotEncrypted); } if (_Mode == VaserOptions.ModeKerberos) { ThreadPool.QueueUserWorkItem(ReceiveKerberos); } if (_Mode == VaserOptions.ModeSSL) { ThreadPool.QueueUserWorkItem(ReceiveSSL); } } if (EnableHeartbeat) { HeartbeatTimer = new Timer(new TimerCallback(OnHeartbeatEvent), null, HeartbeatMilliseconds, HeartbeatMilliseconds); } } catch (AuthenticationException e) { Debug.WriteLine("Authentication failed. " + e.ToString()); _BootUpTimer.Dispose(); Stop(); return; } catch (Exception e) { Debug.WriteLine("Authentication failed. " + e.ToString()); _BootUpTimer.Dispose(); Stop(); return; } // encryption END _BootUpTimer.Dispose(); _BootUpTimer = null; }