private void HandleCrypto(Guid connectionToken) { // finalize crypto task if (_cryptoTaskStatus != TaskStatus.None) { _cryptoTask.Wait(); FinalizeCryptoTask(); // !important } // check if last denial was ServerFailed else if (_wasServerFailed) { var responseStr = CommunicationManager.StartCommunication(Program.License.CommunicationID); if (CommunicationManager.IsDenied(responseStr)) { ServerDenied?.Invoke(this, new AccountEventArgs(connectionToken, responseStr)); return; } _wasServerFailed = false; } // check: assure that simetric key is given if (string.IsNullOrEmpty(CryptoContext.CryptedSimKey)) { ServerDenied?.Invoke(this, new AccountEventArgs(connectionToken, GlobalResources.ServerFailedMessage)); return; } }
internal void Authenticate(Guid connectionToken, string email, string password, bool autoconnect) { // Log.LogUse(3); if (ConnectAsRegisteredUser && (email == null || password == null)) { ServerDenied?.Invoke(this, new AccountEventArgs(connectionToken, GlobalResources.LoginFailedMessage)); return; } _connectTaskToken = new CancellationTokenSource(); Task.Factory.StartNew(() => { try { HandleCrypto(connectionToken); if (_connectTaskToken.IsCancellationRequested) { Canceled?.Invoke(this, new AccountEventArgs()); return; } string response; if (Program.Connect.ConnectAsAnonymous) { response = CommunicationManager.ExecuteCommand(Program.License.CommunicationID, Commands.AUTHENTICATE_ANONYMOUS, string.Empty, string.Empty, string.Empty); TryParseFreeTrialEmail(response); } else { response = CommunicationManager.ExecuteCommand(Program.License.CommunicationID, Commands.AUTHENTICATE, email, password, string.Empty); } // check if canceled if (_connectTaskToken.IsCancellationRequested) { Canceled?.Invoke(this, new AccountEventArgs()); return; } //_mainForm.ShowAccountUI(); if (CommunicationManager.IsDenied(response)) { ServerDenied?.Invoke(this, new AccountEventArgs(connectionToken, response)); return; } // success: else { TrySetRegisteredUser(); SaveRegister(email, password, autoconnect); ServerAllowed?.Invoke(this, new AccountEventArgs(connectionToken, response)); } } catch (Exception ex) { ServerDenied?.Invoke(this, new AccountEventArgs(connectionToken, GlobalResources.ServerFailedMessage)); } }, _connectTaskToken.Token); }