private void OnVerificationRequired()
 {
     Application.Current.Dispatcher.Invoke((Action) delegate
     {
         var verificationScreen = new VerificationRequired(resolver, UserEmailId, UserPasswordWrapper.Password);                // resolver.GetInstanceOf<VerificationRequired>();
         Navigator.NavigationService.Navigate(verificationScreen);
     });
 }
Exemplo n.º 2
0
        private bool TryToGetDeviceID(string userEmailId, string masterPassword, bool profileExists, bool hasDeviceID)
        {
            logger.Debug("TryToGetDeviceId started. profileExists - {0}, hasDeviceId - {1}", profileExists, hasDeviceID);
            var canProceed = !profileExists || !hasDeviceID;

            if (!canProceed)
            {
                return(false);                // refactoring complexity of conditions.
            }
            if (!webApi.HasInetConn)
            {
                logger.Error("TryToGetDeviceID - No internet connection - exit");
                return(false);
            }

            IPBWebAPI webAPI = resolver.GetInstanceOf <IPBWebAPI>();


            // try to register device
            dynamic deviceRegistrationResponse = webAPI.RegisterDevice(
                new WEBApiJSON.DeviceRegistrationRequest()
            {
                installation     = pbData.InstallationUUID,
                nickname         = System.Windows.Forms.SystemInformation.ComputerName,
                software_version = Assembly.GetAssembly(typeof(PasswordBoss.PBApp)).GetName().Version.ToString()
            }, userEmailId);


            if (deviceRegistrationResponse == null)
            {
                logger.Error("deviceRegistrationResponse is empty");
                //MessageBox.Show("Error in device registration");
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    string _message = System.Windows.Application.Current.FindResource("ErrorInDeviceRegistrationLoginMessage") as string;
                    CustomInformationMessageBoxWindow c = new CustomInformationMessageBoxWindow(_message);
                    c.ShowDialog();
                });
                //return false;
                return(true);
            }
            else
            {
                if (deviceRegistrationResponse.error != null)
                {
                    logger.Debug("DeviceRegistrationResponse.error = {0}", deviceRegistrationResponse.error);

                    //MessageBox.Show(deviceRegistrationResponse.error.message.ToString());
                    if (deviceRegistrationResponse.error.code.ToString() == "412")
                    {
                        //Before information label on login
                        //var createAccountScreen = new CreateAccount(resolver, userEmailId);
                        //Navigator.NavigationService.Navigate(createAccountScreen);

                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            ErrorMessage = (string)System.Windows.Application.Current.FindResource("AccountDoesNotExists");
                        });


                        // createAccountScreen.EmailTextBox.Text = UserEmail; // resolver.GetInstanceOf<CreateAccount>();
                    }
                    else if (deviceRegistrationResponse.error.code.ToString() == "403")
                    {
                        logger.Debug("Calling requestVerificationCode");
                        webAPI.RequestVerificationCode(userEmailId);
                        logger.Debug("Called requestVerificationCode");

                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            var verificationScreen = new VerificationRequired(resolver, userEmailId, masterPassword);                            // resolver.GetInstanceOf<VerificationRequired>();
                            Navigator.NavigationService.Navigate(verificationScreen);
                        });
                    }

                    return(true);
                }
                else
                {
                    logger.Error("deviceRegistrationResponse didnt return error code");
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        string _message = System.Windows.Application.Current.FindResource("ServerErrorLoginMessage") as string;
                        CustomInformationMessageBoxWindow c = new CustomInformationMessageBoxWindow(_message);
                        c.ShowDialog();
                    });
                }
                return(true);
            }

            //pbData.DeviceUUID = deviceRegistrationResponse.devices[0].uuid.ToString();
            //todo write device uuid into device table

            //ServerErrorLoginMessage
            //MessageBox.Show("Local profile does not exist. Create new account or register device with existing account!");
            return(true);
        }
        private void NextButtonClick(object element)
        {
            try
            {
                logger.Debug("Started account request and creating rsaKeys");
                if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(masterPassword))
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error retreiving account information");
                    return;
                }

                if (this.masterPassword != UserPassword)
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Master password not matching");
                    return;
                }
                UserPassword = string.Empty;
                //Generate a public/private key pair

                /*RSA rsaBase = new RSA();
                 * rsaBase.GenerateKeys(1024, 65537, null, null);
                 * string privateKeyPem = rsaBase.PrivateKeyAsPEM;
                 * string publicKeyPem = rsaBase.PublicKeyAsPEM;
                 *
                 * logger.Debug("Call webAPI.RequestAccount");
                 * string publicKeyPem = rsaBase.PublicKeyAsPEM;*/
                byte[]             publicKeyPem  = null;
                ProtectedDataBlock privateKeyPem = null;
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048))
                {
                    privateKeyPem = new ProtectedDataBlock(Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPrivateKeyToPEM(rsa)));
                    publicKeyPem  = Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPublicKeyToPEM(rsa));
                }

                IPBWebAPI webAPI          = resolver.GetInstanceOf <IPBWebAPI>();
                dynamic   accountResponse = webAPI.RequestAccount(new WEBApiJSON.AccountRequest()
                {
                    email = email, language = "English", installation = pbData.InstallationUUID, public_key = Convert.ToBase64String(publicKeyPem)
                });
                if (accountResponse == null)
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error in account registration");
                    return;
                }
                else
                {
                    if (accountResponse.error != null)
                    {
                        //MessageBox.Show(accountResponse.error.details[0].ToString());
                        if (accountResponse.error.code == "400")
                        {
                            //try to register device
                            dynamic deviceRegistrationResponse = webAPI.RegisterDevice(new WEBApiJSON.DeviceRegistrationRequest()
                            {
                                installation     = pbData.InstallationUUID,
                                nickname         = Environment.MachineName,
                                software_version = Assembly.GetExecutingAssembly().GetName().Version.ToString()
                            }, email);
                            if (deviceRegistrationResponse == null)
                            {
                                // To - Do Change style of Dialog
                                MessageBox.Show("Error in device registration");
                                return;
                            }
                            else
                            {
                                if (deviceRegistrationResponse.error != null)
                                {
                                    //MessageBox.Show(deviceRegistrationResponse.error.message.ToString());
                                    if (deviceRegistrationResponse.error.code.ToString() == "403")
                                    {
                                        //send verification code for new device
                                        dynamic verificationRequestResponse = webAPI.RequestVerificationCode(email);
                                        Application.Current.Dispatcher.Invoke((Action) delegate
                                        {
                                            var verificationScreen = new VerificationRequired(resolver, email, masterPassword);// resolver.GetInstanceOf<VerificationRequired>();

                                            Navigator.NavigationService.Navigate(verificationScreen);
                                        });
                                    }

                                    return;
                                }
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    Login login             = resolver.GetInstanceOf <Login>();
                                    login.EmailTextBox.Text = email;
                                    Navigator.NavigationService.Navigate(login);
                                });
                            }
                        }
                    }
                }
                logger.Debug("Creating profile");
                if (!pbData.CreateProfile(email, masterPassword))
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error while creating secure database");
                }
                pbData.AddUserInfo(new DTO.UserInfo()
                {
                    Email = email, RSAPrivateKey = privateKeyPem, PublicKey = publicKeyPem
                });
                logger.Debug("Performing initial sync");
                PerformInitialSync();
                SetDefaultSettings(pbData);

                inAppAnalyitics.Get <Events.AccountCreationFlow, AccountCreationFlowItem>().Log(new AccountCreationFlowItem(3, AccountCreationFlowSteps.ConfirmMP, string.Empty, MarketingActionType.Continue));

                // Added dispatcher because background worker can't create new UI elements
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    var nextScreen = new SetupComplete(resolver);// resolver.GetInstanceOf<SetupComplete>();

                    Navigator.NavigationService.Navigate(nextScreen);
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }