async void OnAcceptPassphraseAsync(string passphrase) { if (string.IsNullOrEmpty(passphrase)) { ErrorBox.Show("The passphrase is required."); return; } var op = new LongRunningOperation(p => { }, () => { }); try { this.deviceVaultService.TryLoadDecryptAndSetMasterRandomKeyAsync(passphrase, op.Context).ConfigureAwait(false).GetAwaiter().GetResult(); await this.profileViewModel.LoadProfile(); await this.cancellation.StartWorkers(); NavigationService.ShowContactsView(); } catch (Exception ex) { var result = MockLocalization.ReplaceKey(ex.Message); if (result != ex.Message) { MessageBox.Query("Device Vault", "\r\nIncorrect Passphrase.", Strings.Ok); } else { ErrorBox.ShowException(ex); } } }
public override void Create() { this.mainWindow.RemoveAll(); var frameViewInfo = new FrameView("Info") { X = 0, Y = 0, Height = Dim.Percent(100), Width = Dim.Percent(25) }; var labelInfoText = new Label(1, 1, "Now, please choose your device vault passphrase - it will be used to encrypt all your locally stored data."); labelInfoText.LayoutStyle = LayoutStyle.Computed; frameViewInfo.Add(labelInfoText); this.mainWindow.Add(frameViewInfo); var labelPassphrase = new Label("Passphrase:") { X = Pos.Right(frameViewInfo) + 1, Y = 1, }; this.mainWindow.Add(labelPassphrase); var textViewPassphrase = new TextField("") { Secret = true, X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(labelPassphrase), Width = Dim.Fill() }; this.mainWindow.Add(textViewPassphrase); var buttonAcceptPassphrase = new Button("Set passphrase", true) { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(textViewPassphrase) + 1, }; buttonAcceptPassphrase.Clicked = async() => { if (string.IsNullOrWhiteSpace(textViewPassphrase.Text.ToString())) { ErrorBox.Show("The passphrase must not be empty"); } else { this.onboardingViewModel.ValidatedMasterPassphrase = textViewPassphrase.Text.ToString(); var quality = this.deviceVaultService.GetPassphraseQuality(this.onboardingViewModel .ValidatedMasterPassphrase); var labelPassphraseAccepted = new Label( $"Your passphrase was set! Passphrase Quality: {this.deviceVaultService.GetPassphraseQualityText(quality)}.") { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(textViewPassphrase) + 1, }; this.mainWindow.Remove(buttonAcceptPassphrase); this.mainWindow.Add(labelPassphraseAccepted); var progressBar = new ProgressBar { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(labelPassphraseAccepted) + 1, Width = Dim.Fill(), Height = 1, Fraction = 0.0f, ColorScheme = Colors.Error }; this.mainWindow.Add(progressBar); var labelProgressText = new Label(" ") { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(progressBar) + 1, Width = Dim.Fill() }; this.mainWindow.Add(labelProgressText); var op = new LongRunningOperation(encryptionProgress => { progressBar.Fraction = encryptionProgress.Percent / 100f; labelProgressText.Text = $"{encryptionProgress.Percent} % {MockLocalization.ReplaceKey(encryptionProgress.Message)}"; }, () => { }); try { await this.onboardingViewModel.CommitAllAsync(op.Context); labelProgressText.Text = "Cryptographic operations complete!"; this.mainWindow.Add( new Label("That's it! You can now start chatting with your new encrypted identity!") { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(labelProgressText) + 1, Width = Dim.Fill() }); var buttonStartChat = new Button("Start chat") { X = Pos.Right(frameViewInfo) + 1, Y = Pos.Bottom(labelProgressText) + 3, Clicked = () => { App.IsOnboardingRequired = false; NavigationService.ShowLockScreen(); } }; this.mainWindow.Add(buttonStartChat); buttonStartChat.SetFocus(); } catch (Exception e) { ErrorBox.Show($"Could not commit profile: {e}"); } } }; this.mainWindow.Add(buttonAcceptPassphrase); textViewPassphrase.SetFocus(); }