Beispiel #1
0
        private void SetDBLockTimeout()
        {
            if (pbData == null)
            {
                return;
            }
            var autoLockMinutesString = pbData.GetPrivateSetting(DefaultProperties.Settings_Security_PasswordAutoLock);

            if (string.IsNullOrWhiteSpace(autoLockMinutesString))
            {
                pbData.PasswordTimeout = TimeSpan.FromMinutes(1440);
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Security_PasswordAutoLock, "1440");
            }
            else
            {
                int timeOut = 0;
                var ok      = int.TryParse(autoLockMinutesString, out timeOut);

                if (ok)
                {
                    pbData.PasswordTimeout = timeOut <= 0 ? TimeSpan.FromMilliseconds(-1) : TimeSpan.FromMinutes(timeOut);
                }
                else
                {
                    pbData.PasswordTimeout = TimeSpan.FromMinutes(1440);
                    pbData.ChangePrivateSetting(DefaultProperties.Settings_Security_PasswordAutoLock, "1440");
                }
            }
        }
        void sync_OnSyncFinished(bool status)
        {
            try
            {
                IPBSync sync = resolver.GetInstanceOf <IPBSync>();
                sync.OnSyncFinished -= sync_OnSyncFinished;
                var browserImporters = resolver.GetAllInstancesOf <BrowserImportStrategyBase>();

                var results = browserImporters.Select(s => s.Import());

                var importedSitesNum       = results.Sum(r => r.Imported);
                var alredyImportedSitesNum = 0;

                List <SecureItem> userSites = pbData.GetSecureItemsByItemType(PasswordBoss.Helpers.DefaultProperties.SecurityItemType_PasswordVault).Where(x => x.Site.IsRecommendedSite == false).ToList();

                if (userSites.Count == 0)
                {
                    alredyImportedSitesNum = 0; //we didn't have anything previous. alredyImportedSitesNum can also mean overlapping between browsers
                }
                else
                {
                    alredyImportedSitesNum = results.Sum(r => r.AlreadyImported);
                }

                var inAppAnalyitics = resolver.GetInstanceOf <IInAppAnalytics>();
                if (inAppAnalyitics != null)
                {
                    ImportPasswordsItem item = new ImportPasswordsItem(importedSitesNum, ImportPasswordsTrigger.Installer, null);
                    var analytics            = inAppAnalyitics.Get <Events.ImportPasswords, ImportPasswordsItem>();
                    analytics.Log(item);
                }

                pbData.ChangePrivateSetting("setup_wizard_imported_passwords_number", importedSitesNum.ToString());
                pbData.ChangePrivateSetting("setup_wizard_already_passwords_number", alredyImportedSitesNum.ToString());

                AddEmailToPI();

                logger.Debug("sync images");
                SyncImagesHelper syncImages = new SyncImagesHelper(pbData, webApi);
                //syncImages.SyncImagesAsync();
                syncImages.SyncImages();

                logger.Debug("Finished");
            }
            finally
            {
                evDone.Set();
            }
        }
        internal void SubmitCodeVerification(object element)
        {
            ErrorMessage = String.Empty;

            if (ConfirmCode())
            {
                bool profileExists   = false;
                var  isAuthenticated = pbData.AuthenticateUser(UserEmail, _masterPass, out profileExists);

                if (!isAuthenticated)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        ErrorMessage = (string)System.Windows.Application.Current.FindResource("IncorrectMailOrPasswordMessage");
                    });
                    return;
                }

                pbData.OpenProfile(UserEmail, _masterPass, out profileExists);
                _masterPass      = string.Empty;
                VerificationCode = "";
                CodeVerificationErrorMessageCode = "";
                //installationDate.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Device_IsDeviceTrustedLastChecked, DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
                if (IsThisComputerTrusted)
                {
                    pbData.ChangePrivateSetting(DefaultProperties.Settings_Device_IsDeviceTrusted, IsThisComputerTrusted.ToString());
                }
                //IsTwoStepVerificationPassed = true;

                ShowMainWindow();

                CodeVerificationGridVisibility = false;
                advertisingGrid.Visibility     = Visibility.Visible;
            }
            else
            {
                CodeVerificationErrorMessageCode = "Invalid confirmation code, please try again";
            }
        }
        private void SetDefaultCountry(SecureItemWithCountryViewModel item)
        {
            string country = pbData.GetPrivateSetting(DefaultProperties.Settings_Country);

            if (String.IsNullOrEmpty(country))
            {
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Country, DefaultProperties.Settings_DefaultCountryCode);
                country = DefaultProperties.Settings_DefaultCountryCode;
            }
            if (item != null && item.Countries != null)
            {
                item.SelectedCountry = item.Countries.FirstOrDefault(x => x.Code == country);
            }
        }
        public static void SetDefaultSettings(IPBData pbData)
        {
            string tmpCloudEnabled = pbData.GetPrivateSetting(DefaultProperties.Settings_CloudStorage);

            if (tmpCloudEnabled == null)
            {
                pbData.ChangePrivateSetting(DefaultProperties.Settings_CloudStorage, bool.TrueString);
            }

            var rememberLoginEmail = pbData.GetConfigurationByAccountAndKey(pbData.ActiveUser, DefaultProperties.Configuration_Key_RememberEmail);

            if (rememberLoginEmail == null)
            {
                rememberLoginEmail = new Configuration()
                {
                    AccountEmail = pbData.ActiveUser,
                    Key          = DefaultProperties.Configuration_Key_RememberEmail,
                    Value        = true.ToString()
                };
                pbData.AddOrUpdateConfiguration(rememberLoginEmail);
            }
            bool isEnabledRememberLoginEmail = false;

            if (bool.TryParse(rememberLoginEmail.Value, out isEnabledRememberLoginEmail) && isEnabledRememberLoginEmail)
            {
                var lastLogin = new Configuration()
                {
                    AccountEmail = DefaultProperties.Configuration_DefaultAccount,
                    Key          = DefaultProperties.Configuration_Key_LastLoginEmail,
                    Value        = pbData.ActiveUser
                };
                pbData.AddOrUpdateConfiguration(lastLogin);
            }

            string autoLogin = pbData.GetPrivateSetting(DefaultProperties.Settings_Advanced_AutoLogin);

            if (autoLogin == null)
            {
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Advanced_AutoLogin, bool.TrueString);
            }

            string passwordSavingInBrowser = pbData.GetPrivateSetting(DefaultProperties.Settings_Advanced_TurnOffPassSaving);

            if (passwordSavingInBrowser == null)
            {
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Advanced_TurnOffPassSaving, bool.TrueString);
            }

            string autoStoreData = pbData.GetPrivateSetting(DefaultProperties.Settings_Advanced_AutoStoreData);

            if (autoStoreData == null)
            {
                pbData.ChangePrivateSetting(DefaultProperties.Settings_Advanced_AutoStoreData, bool.TrueString);
            }

            var userInfo = pbData.GetUserInfo(pbData.ActiveUser);

            if (userInfo != null && userInfo.StorageRegionUUID == null)
            {
                var region = pbData.GetStorageRegions().FirstOrDefault();

                if (region != null)
                {
                    pbData.UpdateCurrentStorageRegion(region.UUID);
                }
            }
        }
Beispiel #6
0
        public void SyncImages()
        {
            logger.Debug("Sync Images start");
            try
            {
                lock (lck)
                {
                    if (pbData.Locked)
                    {
                        logger.Debug("Sync Images quits - database locked");
                        return;                         //don't do anything
                    }
                    //Debugger.Launch();
                    DateTime lastImageSyncDate    = DateTime.MinValue;
                    string   lastImageSyncDateStr = pbData.GetPrivateSetting(DefaultProperties.LastImageSyncDate);
                    DateTime.TryParse(lastImageSyncDateStr, out lastImageSyncDate);

                    var recommendedSites = pbData.GetRecommendedSites();
                    Parallel.ForEach(recommendedSites, (recommendedSite) =>
                    {
                        try
                        {
                            bool forceDownload = false;
                            if (recommendedSite.Image != null && recommendedSite.Image.LastModifiedDate > lastImageSyncDate)
                            {
                                forceDownload = true;
                            }
                            if (recommendedSite.Image != null)
                            {
                                InsertImageIfNeeded(recommendedSite.Id, recommendedSite.UUID, recommendedSite.Image.Url, forceDownload);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Insert recommendedSites item failed {0}", ex.ToString());
                        }
                    });
                    logger.Debug("Got {0} Recommented sites", recommendedSites.Count);

                    var secureItems = pbData.GetSecureItemsByItemType(SecurityItemsDefaultProperties.SecurityItemType_PasswordVault);
                    if (secureItems == null)
                    {
                        return;
                    }

                    logger.Debug("Got {0} secure items", secureItems.Count);

                    Parallel.ForEach(secureItems, (secureItem) =>
                    {
                        try
                        {
                            if (secureItem.Site != null && secureItem.Site.Image != null)
                            {
                                bool forceDownload = false;
                                if (secureItem.ImageLastModifiedDate.GetValueOrDefault(secureItem.LastModifiedDate) >= lastImageSyncDate)
                                {
                                    forceDownload = true;
                                }
                                InsertImageIfNeeded(secureItem.Site.Id, secureItem.Site.UUID, secureItem.Site.Image.Url, forceDownload);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Insert secure item failed {0}", ex.ToString());
                        }
                    });

                    logger.Debug("Images inserted");

                    pbData.ChangePrivateSetting(DefaultProperties.LastImageSyncDate, DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            finally
            {
                logger.Debug("Sync images done");
            }
        }
Beispiel #7
0
        void sync_OnSyncFinished(bool status)
        {
            try
            {
                IPBSync sync = resolver.GetInstanceOf <IPBSync>();
                sync.OnSyncFinished -= sync_OnSyncFinished;
                List <LoginInfo> chromeLoginInfo = new List <LoginInfo>();
                List <LoginInfo> ieLoginInfo     = new List <LoginInfo>();
                List <LoginInfo> ffLoginInfo     = new List <LoginInfo>();

                Parallel.Invoke(() =>
                {
                    //loading chrome items parallel
                    if (Browsers.BrowserVersionGetter.GetChromeVersion() != null)
                    {
                        //if (!BrowserHelper.IsChromeOpened)
                        //{
                        var tmploginInfo = pbData.GetChromeAccounts();
                        chromeLoginInfo.AddRange(tmploginInfo);
                        //}
                    }
                }
                                , () =>
                {
                    if (Browsers.BrowserVersionGetter.GetIEVersion() != null)
                    {
                        //if (!BrowserHelper.IsIEOpened)
                        //{
                        var tmploginInfo = pbData.GetIEAccounts();
                        ieLoginInfo.AddRange(tmploginInfo);
                        //}
                    }
                }
                                , () =>
                {
                    if (Browsers.BrowserVersionGetter.GetFFVersion() != null)
                    {
                        //if (!BrowserHelper.IsFFOpened)
                        //{
                        var tmploginInfo = pbData.GetFFAccounts(() => { return(null); });
                        ffLoginInfo.AddRange(tmploginInfo);
                        //}
                    }
                });

                SecureItemHelper siHelper        = new SecureItemHelper(pbData, sync);
                int ieImportedSitesNum           = 0;
                int ffImportedSitesNum           = 0;
                int chromeImportedSitesNum       = 0;
                int ieAlredyImportedSitesNum     = 0;
                int ffAlredyImportedSitesNum     = 0;
                int chromeAlredyImportedSitesNum = 0;
                int alredyImportedSitesNum       = 0;

                List <SecureItem> userSites = pbData.GetSecureItemsByItemType(PasswordBoss.Helpers.DefaultProperties.SecurityItemType_PasswordVault).Where(x => x.Site.IsRecommendedSite == false).ToList();
                logger.Debug("Importing sites from browsers - Start");

                siHelper.ImportLoginInfoList(chromeLoginInfo.Where(x => !string.IsNullOrWhiteSpace(x.UserName)).Distinct().ToList(), ref chromeImportedSitesNum, ref chromeAlredyImportedSitesNum);
                siHelper.ImportLoginInfoList(ieLoginInfo.Where(x => !string.IsNullOrWhiteSpace(x.UserName)).Distinct().ToList(), ref ieImportedSitesNum, ref ieAlredyImportedSitesNum);
                siHelper.ImportLoginInfoList(ffLoginInfo.Where(x => !string.IsNullOrWhiteSpace(x.UserName)).Distinct().ToList(), ref ffImportedSitesNum, ref ffAlredyImportedSitesNum);

                logger.Debug("Importing sites from browsers - Finish");

                var importedSitesNum = ieImportedSitesNum + ffImportedSitesNum + chromeImportedSitesNum;

                if (userSites.Count == 0)
                {
                    alredyImportedSitesNum = 0;                     //we didn't have anything previous. alredyImportedSitesNum can also mean overlapping between browsers
                }
                else
                {
                    alredyImportedSitesNum = ieAlredyImportedSitesNum + ffAlredyImportedSitesNum + chromeAlredyImportedSitesNum;
                }

                var inAppAnalyitics = resolver.GetInstanceOf <IInAppAnalytics>();
                if (inAppAnalyitics != null)
                {
                    ImportPasswordsItem item = new ImportPasswordsItem(importedSitesNum, ImportPasswordsTrigger.Installer, null);
                    var analytics            = inAppAnalyitics.Get <Events.ImportPasswords, ImportPasswordsItem>();
                    analytics.Log(item);
                }

                pbData.ChangePrivateSetting("setup_wizard_imported_passwords_number", importedSitesNum.ToString());
                pbData.ChangePrivateSetting("setup_wizard_already_passwords_number", alredyImportedSitesNum.ToString());

                logger.Debug("private settings modified");
                AddEmailToPI();
                logger.Debug("added email to PI");

                SyncImagesHelper syncImages = new SyncImagesHelper(pbData, webApi);
                syncImages.SyncImages();

                logger.Debug("Finished");
            }
            finally
            {
                evDone.Set();
            }
        }
        private void StoreInput()
        {
            if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName))
            {
                var siName = new SecureItem()
                {
                    SecureItemTypeName = DefaultProperties.SecurityItemType_PersonalInfo,
                    Type = DefaultProperties.SecurityItemSubType_PI_Names
                };

                try
                {
                    if (siName.Data == null)
                    {
                        siName.Data = new SecureItemData();
                    }
                    siName.Data.firstName = firstName;
                    siName.Data.lastName  = lastName;
                    siName.Name           = String.Format("{0} {1}", firstName, lastName);
                    //siName.Category = new Category() { Id = DefaultCategories.CategoryNames };

                    siName = pbData.AddOrUpdateSecureItem(siName);
                    pbData.ChangePrivateSetting(PI_NAME_KEY, JsonConvert.SerializeObject(siName, Formatting.None, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }));

                    UserInfo ui = pbData.GetUserInfo(pbData.ActiveUser);
                    ui.FirstName = firstName;
                    ui.LastName  = lastName;
                    pbData.UpdateUserInfo(ui);

                    api.UpdateAccount(pbData.ActiveUser + "|" + pbData.DeviceUUID, new PasswordBoss.WEBApiJSON.AccountRequest {
                        first_name = firstName, last_name = lastName
                    });
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                }
            }

            if (!string.IsNullOrEmpty(address))
            {
                var siAddress = new SecureItem()
                {
                    SecureItemTypeName = DefaultProperties.SecurityItemType_PersonalInfo, Type = DefaultProperties.SecurityItemSubType_PI_Address
                };
                try
                {
                    siAddress.SecureItemTypeName = DefaultProperties.SecurityItemType_PersonalInfo;
                    siAddress.Type = DefaultProperties.SecurityItemSubType_PI_Address;
                    siAddress.Name = address;
                    if (siAddress.Data == null)
                    {
                        siAddress.Data = new SecureItemData();
                    }

                    siAddress.Data.address1 = address;
                    siAddress.Data.city     = city;
                    siAddress.Data.zipCode  = zip;
                    siAddress.Data.state    = state;

                    // TODO: are we need it?
                    //siAddress.Data.country = PIAddressCountry.Value.Key;
                    siAddress = pbData.AddOrUpdateSecureItem(siAddress);
                    pbData.ChangePrivateSetting(PI_ADDRESS_KEY, JsonConvert.SerializeObject(siAddress, Formatting.None, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }));
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                }
            }
        }