Ejemplo n.º 1
0
        private async Task <bool> TestVaultPassphrase(
            VaultIndex vaultIndex,
            string masterPassphrase)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("KeyDerivationFunction", AppConfig.Instance.KeyDerivationFunction);
            switch (AppConfig.Instance.KeyDerivationFunction)
            {
            case AppConfig.CACHY_KEYDERIVATIONFUNCTION_PBKDF2:
            {
                parameters.Add("IterationCount", AppConfig.Instance.PBKDF2IterationCount.ToString());
                break;
            }

            case AppConfig.CACHY_KEYDERIVATIONFUNCTION_SCRYPT:
            {
                parameters.Add("IterationCount", AppConfig.Instance.SCryptIterationCount.ToString());
                parameters.Add("BlockSize", AppConfig.Instance.SCryptBlockSize.ToString());
                parameters.Add("ThreadCount", AppConfig.Instance.SCryptThreadCount.ToString());
                break;
            }
            }

            AESEncryptedVaultSerialiser serialiser = new AESEncryptedVaultSerialiser();

            try
            {
                GenericResult <Common.LoadResult, Vault> loadResult = await vaultIndex.Load(serialiser, masterPassphrase, parameters.ToArray());

                return(loadResult.Result == Common.LoadResult.Success);
            }
            catch (Exception ex)
            {
                App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Exception,
                                         "Failed to unlock the vault at '{0}'.\r\n'{1}'.",
                                         vaultIndex.FullPath,
                                         ex.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
        private async Task <Boolean> UnlockVault()
        {
            if (VaultIndex != null && !String.IsNullOrEmpty(MasterPassphrase))
            {
                try
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    parameters.Add("KeyDerivationFunction", AppConfig.Instance.KeyDerivationFunction);
                    switch (AppConfig.Instance.KeyDerivationFunction)
                    {
                    case AppConfig.CACHY_KEYDERIVATIONFUNCTION_PBKDF2:
                    {
                        parameters.Add("IterationCount", AppConfig.Instance.PBKDF2IterationCount.ToString());
                        break;
                    }

                    case AppConfig.CACHY_KEYDERIVATIONFUNCTION_SCRYPT:
                    {
                        parameters.Add("IterationCount", AppConfig.Instance.SCryptIterationCount.ToString());
                        parameters.Add("BlockSize", AppConfig.Instance.SCryptBlockSize.ToString());
                        parameters.Add("ThreadCount", AppConfig.Instance.SCryptThreadCount.ToString());
                        break;
                    }
                    }

                    AESEncryptedVaultSerialiser serialiser = new AESEncryptedVaultSerialiser();
                    GenericResult <Common.LoadResult, Vault> loadResult = await _vaultIndex.Load(serialiser, MasterPassphrase, parameters.ToArray());

                    _masterPassphrase = String.Empty;
                    if (loadResult.Result == Common.LoadResult.Success)
                    {
                        Vault = loadResult.Value;
                        Vault.PropertyChanged += _vault_PropertyChanged;
                        if (!_vaultIndex.IsInLocalVaultStore && !VaultIndexFile.Instance.VaultIsIndexed(_vault))
                        {
                            if (VaultIndex.SyncMode == Common.SyncMode.CloudProvider)
                            {
                                throw new NotImplementedException("Adding existing cloud provider vaults is not currently supported.");
                            }

                            VaultIndexFile.Instance.AddVaultToLocalVaultStoreIndex(_vault,
                                                                                   VaultIndex.SyncMode,
                                                                                   VaultIndex.Provider,
                                                                                   String.Empty,
                                                                                   false);
                        }

                        NotifyPropertyChanged("Vault");
                        NotifyPropertyChanged("FilteredCredentials");
                        UpdatePageTitle();
                        ResetIdleTime();

                        if (_vaultIndex.Unopened)
                        {
                            //Mark it as opened and update the name and description
                            _vaultIndex.MarkAsOpened(
                                _vault.Name,
                                _vault.Description);
                            VaultIndexFile.Instance.Save();
                        }
                        _vaultIndex = null;

                        if (AppConfig.Instance.AutoCloseVault)
                        {
                            _autoLockTimer.Start();
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    await App.Controller.MainPageInstance.DisplayAlert("Unlock Vault",
                                                                       String.Format("Failed to unlock the vault, {0}.", ex.Message),
                                                                       "OK");

                    ((App)App.Current).NavigateToVaultsList();
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }