diff --git a/DesktopEdge/MainWindow.xaml.cs b/DesktopEdge/MainWindow.xaml.cs index 7f9aaf98..d4784c6e 100644 --- a/DesktopEdge/MainWindow.xaml.cs +++ b/DesktopEdge/MainWindow.xaml.cs @@ -123,6 +123,7 @@ namespace ZitiDesktopEdge { ShowBlurb("Unexpected error when processing MFA", ""); logger.Error("unexpected action: " + mfa.Action); } + LoadIdentities(true); }); } @@ -276,7 +277,6 @@ namespace ZitiDesktopEdge { logger.Info("========================================================================"); App.Current.MainWindow.WindowState = WindowState.Normal; - App.Current.MainWindow.Closing += MainWindow_Closing; App.Current.MainWindow.Deactivated += MainWindow_Deactivated; App.Current.MainWindow.Activated += MainWindow_Activated; @@ -864,6 +864,7 @@ namespace ZitiDesktopEdge { } else { idItem.ToggleStatus.Content = "DISABLED"; } + idItem.Authenticate += IdItem_Authenticate; idItem.OnStatusChanged += Id_OnStatusChanged; idItem.Identity = id; IdList.Children.Add(idItem); @@ -884,6 +885,10 @@ namespace ZitiDesktopEdge { }); } + private void IdItem_Authenticate(ZitiIdentity identity) { + ShowAuthenticate(identity); + } + private void Id_OnStatusChanged(bool attached) { for (int i = 0; i < IdList.Children.Count; i++) { IdentityItem item = IdList.Children[i] as IdentityItem; diff --git a/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml b/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml index 21daaf40..fdef3fd4 100644 --- a/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml +++ b/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml @@ -8,7 +8,7 @@ d:DesignHeight="64" d:DesignWidth="375" Height="64"> - + @@ -25,7 +25,7 @@ - + diff --git a/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml.cs b/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml.cs index f7710000..fb7ef1a9 100644 --- a/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml.cs +++ b/DesktopEdge/Views/ItemRenderers/IdentityItem.xaml.cs @@ -40,18 +40,17 @@ namespace ZitiDesktopEdge { public void RefreshUI () { ToggleSwitch.Enabled = _identity.IsEnabled; if (_identity.IsMFAEnabled) { - // Clint I need a sign - // if (_identity.IsMFAAuthentcated) { - ServiceCountArea.Visibility = Visibility.Visible; - MfaRequired.Visibility = Visibility.Collapsed; - ServiceCountAreaLabel.Content = "services"; - MainArea.Opacity = 1.0; - // } else { - ServiceCountArea.Visibility = Visibility.Collapsed; - MfaRequired.Visibility = Visibility.Visible; - ServiceCountAreaLabel.Content = "authorize"; - MainArea.Opacity = 0.6; - // } + if (_identity.MFAInfo.IsAuthenticated) { + ServiceCountArea.Visibility = Visibility.Visible; + MfaRequired.Visibility = Visibility.Collapsed; + ServiceCountAreaLabel.Content = "services"; + MainArea.Opacity = 1.0; + } else { + ServiceCountArea.Visibility = Visibility.Collapsed; + MfaRequired.Visibility = Visibility.Visible; + ServiceCountAreaLabel.Content = "authorize"; + MainArea.Opacity = 0.6; + } } else { ServiceCountArea.Visibility = Visibility.Visible; MfaRequired.Visibility = Visibility.Collapsed; diff --git a/DesktopEdge/Views/Screens/IdentityDetails.xaml.cs b/DesktopEdge/Views/Screens/IdentityDetails.xaml.cs index 6f884ab4..f991283a 100644 --- a/DesktopEdge/Views/Screens/IdentityDetails.xaml.cs +++ b/DesktopEdge/Views/Screens/IdentityDetails.xaml.cs @@ -56,22 +56,6 @@ namespace ZitiDesktopEdge { UpdateView(); IdentityArea.Opacity = 1.0; IdentityArea.Visibility = Visibility.Visible; - IdentityMFA.IsOn = _identity.IsMFAEnabled; - if (_identity.IsMFAEnabled) { - if (_identity.MFAInfo.IsAuthenticated) { - IdentityMFA.AuthOn.Visibility = Visibility.Visible; - IdentityMFA.AuthOff.Visibility = Visibility.Collapsed; - IdentityMFA.RecoveryButton.Visibility = Visibility.Visible; - } else { - IdentityMFA.AuthOn.Visibility = Visibility.Collapsed; - IdentityMFA.AuthOff.Visibility = Visibility.Visible; - IdentityMFA.RecoveryButton.Visibility = Visibility.Collapsed; - } - } else { - IdentityMFA.AuthOn.Visibility = Visibility.Collapsed; - IdentityMFA.AuthOff.Visibility = Visibility.Collapsed; - IdentityMFA.RecoveryButton.Visibility = Visibility.Collapsed; - } this.Visibility = Visibility.Visible; } } @@ -104,11 +88,6 @@ namespace ZitiDesktopEdge { } public void UpdateView() { - if(_identity.IsMFAEnabled && !_identity.MFAInfo.IsAuthenticated) { - //verify mfa here - MainWindow.MFAAuthenticate(_identity); - } - IdDetailName.Text = _identity.Name; IdDetailName.ToolTip = _identity.Name; IdDetailToggle.Enabled = _identity.IsEnabled; @@ -117,12 +96,16 @@ namespace ZitiDesktopEdge { IdentityEnrollment.Value = _identity.EnrollmentStatus; IdentityStatus.Value = _identity.IsEnabled ? "active" : "disabled"; IdentityMFA.IsOn = _identity.IsMFAEnabled; + IdentityMFA.ToggleField.Opacity = 1; if (_identity.IsMFAEnabled) { if (_identity.MFAInfo.IsAuthenticated) { + IdentityMFA.ToggleField.IsEnabled = true; IdentityMFA.AuthOn.Visibility = Visibility.Visible; IdentityMFA.AuthOff.Visibility = Visibility.Collapsed; IdentityMFA.RecoveryButton.Visibility = Visibility.Visible; } else { + IdentityMFA.ToggleField.Opacity = 0.2; + IdentityMFA.ToggleField.IsEnabled = false; IdentityMFA.AuthOn.Visibility = Visibility.Collapsed; IdentityMFA.AuthOff.Visibility = Visibility.Visible; IdentityMFA.RecoveryButton.Visibility = Visibility.Collapsed; diff --git a/DesktopEdge/Views/Screens/MFAScreen.xaml b/DesktopEdge/Views/Screens/MFAScreen.xaml index 0286b4f9..83607a32 100644 --- a/DesktopEdge/Views/Screens/MFAScreen.xaml +++ b/DesktopEdge/Views/Screens/MFAScreen.xaml @@ -50,63 +50,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -151,60 +101,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/DesktopEdge/Views/Screens/MFAScreen.xaml.cs b/DesktopEdge/Views/Screens/MFAScreen.xaml.cs index 0c6dc80b..032bfe19 100644 --- a/DesktopEdge/Views/Screens/MFAScreen.xaml.cs +++ b/DesktopEdge/Views/Screens/MFAScreen.xaml.cs @@ -67,6 +67,7 @@ namespace ZitiDesktopEdge { } public void ShowSetup(ZitiIdentity identity, string url, string secret) { + SetupCode.Text = ""; this._identity = identity; MFAImage.Visibility = Visibility.Visible; SecretCode.Visibility = Visibility.Collapsed; @@ -84,7 +85,7 @@ namespace ZitiDesktopEdge { MFARecoveryArea.Visibility = Visibility.Collapsed; SeperationColor.Visibility = Visibility.Visible; for (int i = 1; i <= 6; i++) (this.FindName("SetupAuth" + i) as TextBox).Text = ""; - SetupAuth1.Focus(); + SetupCode.Focus(); } public void ShowRecovery(string[] codes, ZitiIdentity identity) { @@ -111,15 +112,14 @@ namespace ZitiDesktopEdge { } public void ShowMFA(ZitiIdentity identity) { + AuthCode.Text = ""; this._identity = identity; MFASetupArea.Visibility = Visibility.Collapsed; MFARecoveryArea.Visibility = Visibility.Collapsed; SeperationColor.Visibility = Visibility.Collapsed; MFAAuthArea.Visibility = Visibility.Visible; MFAArea.Height = 220; - for (int i = 1; i <= 6; i++) (this.FindName("Auth" + i) as TextBox).Text = ""; - for (int i = 1; i <= 8; i++) (this.FindName("Rec" + i) as TextBox).Text = ""; - Auth1.Focus(); + AuthCode.Focus(); } private BitmapImage LoadImage(string url) { @@ -136,77 +136,24 @@ namespace ZitiDesktopEdge { Process.Start(new ProcessStartInfo(_url) { UseShellExecute = true }); } - private void GoNextSetup(object sender, KeyEventArgs e) { - TextBox sentFrom = sender as TextBox; - string name = sentFrom.Name; - int index = 1; - if (name == "SetupAuth1") index = 2; - else if (name == "SetupAuth2") index = 3; - else if (name == "SetupAuth3") index = 4; - else if (name == "SetupAuth4") index = 5; - else if (name == "SetupAuth5") index = 6; - - TextBox entry = this.FindName("SetupAuth" + index) as TextBox; - if (sentFrom.Text.Length > 0) { - entry.Focus(); - entry.Select(0, entry.Text.Length); - } - } - - private void GoNext(object sender, KeyEventArgs e) { - TextBox sentFrom = sender as TextBox; - string name = sentFrom.Name; - int index = 1; - if (name == "Auth1") index = 2; - else if (name == "Auth2") index = 3; - else if (name == "Auth3") index = 4; - else if (name == "Auth4") index = 5; - else if (name == "Auth5") index = 6; - - TextBox entry = this.FindName("Auth"+index) as TextBox; - if (sentFrom.Text.Length>0) { - entry.Focus(); - } - } - - private void GoNextRecovery(object sender, KeyEventArgs e) { - TextBox sentFrom = sender as TextBox; - string name = sentFrom.Name; - int index = 1; - if (name == "Rec1") index = 2; - else if (name == "Rec2") index = 3; - else if (name == "Rec3") index = 4; - else if (name == "Rec4") index = 5; - else if (name == "Rec5") index = 6; - else if (name == "Rec6") index = 7; - else if (name == "Rec7") index = 8; - - TextBox entry = this.FindName("Rec" + index) as TextBox; - if (sentFrom.Text.Length > 0) { - entry.Focus(); - } - } - - async private void ToggleRecovery(object sender, MouseButtonEventArgs e) { - if (AuthRecoveryArea.Visibility==Visibility.Visible) { + private void ToggleRecovery(object sender, MouseButtonEventArgs e) { + AuthCode.Text = ""; + if (AuthCode.MaxLength==6) { GenerateMFACodes(null, null); - AuthRecoveryArea.Visibility = Visibility.Collapsed; - AuthCodeArea.Visibility = Visibility.Visible; - ToggleType.Content = "Use Recovery Code"; - AuthSubTitle.Content = "Enter your authorization code"; - Auth1.Focus(); - } else { - ReturnMFACodes(null, null); - AuthRecoveryArea.Visibility = Visibility.Visible; - AuthCodeArea.Visibility = Visibility.Collapsed; + AuthCode.MaxLength = 8; ToggleType.Content = "Use Auth Code"; AuthSubTitle.Content = "Enter a recovery code"; - Rec1.Focus(); + AuthCode.Focus(); + } else { + AuthCode.MaxLength = 6; + ToggleType.Content = "Use Recovery Code"; + AuthSubTitle.Content = "Enter your authorization code"; + AuthCode.Focus(); } } async private void ReturnMFACodes(object sender, MouseButtonEventArgs e) { DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; - string code = Auth1.Text + Auth2.Text + Auth3.Text + Auth4.Text + Auth5.Text + Auth6.Text; //jeremyfix + string code = AuthCode.Text; Logger.Debug("AuthMFA successful."); MfaRecoveryCodesResponse getcodes = await serviceClient.ReturnMFACodes(this._identity.Fingerprint, code); if (getcodes.Code != 0) { @@ -216,7 +163,7 @@ namespace ZitiDesktopEdge { } async private void GenerateMFACodes(object sender, MouseButtonEventArgs e) { DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; - string code = Rec1.Text + Rec2.Text + Rec3.Text + Rec4.Text + Rec5.Text + Rec6.Text; //jeremyfix + string code = AuthCode.Text; MfaRecoveryCodesResponse gencodes = await serviceClient.GenerateMFACodes(this._identity.Fingerprint, code); if (gencodes.Code != 0) { Logger.Error("AuthMFA failed. " + gencodes.Message); @@ -240,7 +187,7 @@ namespace ZitiDesktopEdge { async private void DoSetupAuthenticate(object sender, MouseButtonEventArgs e) { AuthBgColor.Color = Color.FromRgb(0, 104, 249); - string code = SetupAuth1.Text + SetupAuth2.Text + SetupAuth3.Text + SetupAuth4.Text + SetupAuth5.Text + SetupAuth6.Text; + string code = SetupCode.Text; DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; SvcResponse resp = await serviceClient.VerifyMFA(this._identity.Fingerprint, code); @@ -252,43 +199,21 @@ namespace ZitiDesktopEdge { } async private void DoAuthenticate(object sender, MouseButtonEventArgs e) { - string code = ""; - if (AuthRecoveryArea.Visibility == Visibility.Visible) { - code = Rec1.Text + Rec2.Text + Rec3.Text + Rec4.Text + Rec5.Text + Rec6.Text + Rec7.Text + Rec8.Text; - if (code.Length != 8) this.ShowError("You must enter a valid code"); + string code = AuthCode.Text; + if (AuthCode.MaxLength==8) { + if (code.Length != 8) this.ShowError("You must enter a valid recovery code"); } else { - code = Auth1.Text + Auth2.Text + Auth3.Text + Auth4.Text + Auth5.Text + Auth6.Text; if (code.Length != 6) this.ShowError("You must enter a valid code"); - - - DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; - SvcResponse authResult = await serviceClient.AuthMFA(this._identity.Fingerprint, code); - if (authResult?.Code != 0) { - Logger.Error("AuthMFA failed. " + authResult.Message); - this.OnClose?.Invoke(false); - } else { - this.OnClose?.Invoke(true); - } } - } - async private void DoAuthenticateb(object sender, MouseButtonEventArgs e) { - string code = ""; - if (AuthRecoveryArea.Visibility == Visibility.Visible) { - code = Rec1.Text + Rec2.Text + Rec3.Text + Rec4.Text + Rec5.Text + Rec6.Text + Rec7.Text + Rec8.Text; - if (code.Length != 8) this.ShowError("You must enter a valid code"); + + DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; + SvcResponse authResult = await serviceClient.AuthMFA(this._identity.Fingerprint, code); + if (authResult?.Code != 0) { + Logger.Error("AuthMFA failed. " + authResult.Message); + this.OnClose?.Invoke(false); } else { - code = Auth1.Text + Auth2.Text + Auth3.Text + Auth4.Text + Auth5.Text + Auth6.Text; - if (code.Length != 6) this.ShowError("You must enter a valid code"); - - - DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"]; - SvcResponse authResult = await serviceClient.VerifyMFA(this._identity.Fingerprint, code); - if (authResult?.Code != 0) { - Logger.Error("VerifyMFA failed. " + authResult.Message); - } else { - //success - hide the screen Jeremy - } + this.OnClose?.Invoke(true); } } @@ -332,5 +257,17 @@ namespace ZitiDesktopEdge { SecretButton.Content = "Show QR Code"; } } + + private void HandleKey(object sender, KeyEventArgs e) { + if (e.Key == Key.Return) { + DoSetupAuthenticate(sender, null); + } + } + + private void AuthCode_KeyUp(object sender, KeyEventArgs e) { + if (e.Key == Key.Return) { + DoAuthenticate(sender, null); + } + } } }