/* * Decrypt the private key and start the app */ public void ResumeApp() { //attempt to load the keys if not already loaded if (!m_ln.Loaded) { m_ln.LoadKeys(); } //prompt the user to enter a password to decrypt the private key PasswordPrompt p = new PasswordPrompt() { NegativeButtonVisible = false, PositiveButtonText = "Decrypt" }; p.OnPromptSaved += new Prompt.PromptClosedEventListener(() => { if (p.Password == null || p.Password.Length == 0) { return; } //attempt to decrypt the public key if (!m_ln.DecryptPrivateKey(p.Password)) { //decryption failed, incorrect password was entered NotificationFactory.ShortAlert("Password is incorrect"); p.Show(); return; } //erase the entered password Eraser.SecureErase(p.Password); p.Password = ""; //private key decrypted, start the app normally StartAppFinal(); }); //check if fingerprint auth is enabled if (m_config.UseFingerprint && m_config.EncryptedPassword.Length > 1) { //prompt for fingerprint IFingerprint fp = FingerprintFactory.GetInstance(); fp.InitReader(); if (fp.IsReady()) { Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) => { byte[] data = (byte[])oo; //page returns the decrypted password //go to password entry if skipped if (data == null) { p.Show(); return; } //decrypt the password string pass = Encoding.UTF8.GetString(data); //attempt to decrypt the private key if (!m_ln.DecryptPrivateKey(pass)) { //decryption failed return; } //erase the decrypted password Eraser.SecureErase(pass); p.Password = ""; //private key decrypted, start the app normally StartAppFinal(); }), fp, ""); } } else { p.Show(); } }
public SettingsPage() { InitializeComponent(); m_config = ConfigFactory.GetInstance(); //initialize to the current settings chk_lock_on_suspend.IsToggled = m_config.LockOnSuspend; chk_save_on_suspend.IsToggled = m_config.SaveOnSuspend; chk_fingerprint.IsToggled = m_config.UseFingerprint; //we need to handle the fingerprint enable separately chk_fingerprint.Toggled += new EventHandler <ToggledEventArgs>((o, e) => { if (chk_fingerprint.IsToggled) { IFingerprint fp = FingerprintFactory.GetInstance(); fp.InitReader(); if (fp.IsReady()) { PasswordPrompt pmt = new PasswordPrompt() { IsNavPage = true, PromptTitle = "Verify your Password", PositiveButtonText = "Verify", RestorePage = true }; pmt.OnPromptSaved += new Prompt.PromptClosedEventListener(() => { if (pmt.Password == null || pmt.Password.Length == 0) { return; } //attempt to decrypt the private key, just as a verification method if (!LocknoteMgr.GetInstance().DecryptPrivateKey(pmt.Password)) { //decryption failed, incorrect password was entered NotificationFactory.ShortAlert("Password is incorrect"); pmt.Show(((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail)); return; } //we verified the password is correct, now we can prompt the user to scan a fingerprint Page back = Application.Current.MainPage; Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) => { byte[] data = (byte[])oo; //page returns the encrypted password if (data != null) { //only if was not skipped //encrypt the password and save it ConfigFactory.GetInstance().EncryptedPassword = data; ConfigFactory.GetInstance().UseFingerprint = true; NotificationFactory.ShortAlert("Fingerprint unlock enabled"); } else { ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 }; ConfigFactory.GetInstance().UseFingerprint = false; chk_fingerprint.IsToggled = false; } Application.Current.MainPage = back; }), fp, pmt.Password); }); pmt.OnPromptDismissed += new Prompt.PromptClosedEventListener(() => { chk_fingerprint.IsToggled = false; }); pmt.Show(((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail)); } } else { ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 }; ConfigFactory.GetInstance().UseFingerprint = false; } }); //set the button handlers btn_save.Clicked += new EventHandler((o, e) => { m_config.LockOnSuspend = chk_lock_on_suspend.IsToggled; m_config.SaveOnSuspend = chk_save_on_suspend.IsToggled; NotificationFactory.ShortAlert("Settings Saved!"); }); btn_change_password.Clicked += new EventHandler((o, e) => { PasswordEntryView pep = new PasswordEntryView(); pep.OnSave += new EventHandler((oo, ee) => { LocknoteMgr.GetInstance().ReencryptPrivateKey(pep.Text); ((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail).PopAsync(); NotificationFactory.ShortAlert("Password changed"); }); Xamarin.Forms.ContentPage pg = new ContentPage(); pg.Content = pep; ((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail).PushAsync(pg); }); }