Beispiel #1
0
        public async void DuplicateCredentialCommandAction(Object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Duplicate credential command invoked.");

            Credential credential       = (Credential)parameter;
            string     offsetNamePrefix = credential.Name;
            int        offset           = 1;
            string     offsetNameSuffix = String.Format("({0})", offset);
            string     offsetName       = String.Format("{0} {1}", offsetNamePrefix, offsetNameSuffix);

            while (Vault.CredentialExists(offsetName))
            {
                offset          += 1;
                offsetNameSuffix = String.Format("({0})", offset);
                offsetName       = String.Format("{0} {1}", offsetNamePrefix, offsetNameSuffix);
            }
            Credential copy = credential.Clone(false);

            copy.Name = offsetName;
            Vault.AddCredential(copy, true);

            if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDuplicatingCred)
            {
                Common.SaveResult saveResult = await Save();

                if (saveResult == Common.SaveResult.Success)
                {
                    VaultIndexFile.Invalidate();
                }
            }

            NotifyPropertyChanged("FilteredCredentials");
        }
        public async void RemoveCommandAction(object parameter)
        {
            CloudProvider provider = parameter as CloudProvider;

            if (provider != null && AllowRemoveProvider)
            {
                bool remove = true;
                if (provider.CheckIsInUse())
                {
                    remove = await App.Controller.MainPageInstance.DisplayAlert("Remove Provider",
                                                                                "This provider is currently in use by one of your vaults, removing the provider will also remove the local copy of the vault. Are you sure you want to remove it?",
                                                                                "Yes", "No");
                }
                if (remove)
                {
                    List <VaultIndex> matches = VaultIndexFile.Instance.Indexes.Where(vi => vi.Provider == provider.ID).ToList();
                    while (matches.Count > 0)
                    {
                        VaultIndexFile.Instance.RemoveFromVault(matches[0]);
                        matches.RemoveAt(0);
                    }
                    CloudProviders.Instance.RemoveProvider(provider.ID);

                    //Reload the vault index file
                    VaultIndexFile.Invalidate();
                    VaultIndexFile instance = VaultIndexFile.Instance;
                }
            }
        }
Beispiel #3
0
        public async void RemoveCredentialCommandAction(Object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Remove credential command invoked.");

            ResetIdleTime();
            Credential credential = (Credential)parameter;

            credential.RemoveFromVault();

            if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDeletingCred)
            {
                Common.SaveResult saveResult = await Save();

                if (saveResult == Common.SaveResult.Success)
                {
                    VaultIndexFile.Invalidate();
                }
            }

            NotifyPropertyChanged("FilteredCredentials");
        }
Beispiel #4
0
        public async void Lock(Object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Lock command invoked.");

            if (Vault.IsDirty)
            {
                Common.SaveResult saveResult = Common.SaveResult.None;
                if (await App.Controller.MainPageInstance.DisplayAlert("Lock Vault",
                                                                       "This vault has unsaved changes, would you like to save the changes before locking the vault?  Changes will be lost of not saved.",
                                                                       "Yes", "No"))
                {
                    saveResult = await Save();
                }
                if (saveResult == Common.SaveResult.Success)
                {
                    VaultIndexFile.Invalidate();
                }
                ((App)App.Current).NavigateToVaultsList();
            }
            else
            {
                ((App)App.Current).NavigateToVaultsList();
            }
        }
Beispiel #5
0
        public async Task ExportCSV(object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Export CSV.");

            VaultExporter exporter = new VaultExporter(
                Common.ExportFormat.cachyCSV1_0,
                Common.ExportWrapping.PasswordProtectedZip);

            string extension = exporter.ExportWrapping == Common.ExportWrapping.PasswordProtectedZip ? "zip" : "csv";
            string name      = String.Format("{0}_{1}", Vault.Name, DateTime.Now.ToString("ddMMyyyy"));
            string fileName  = String.Format("{0}.{1}", name, extension);

            string passsword = SimpleRandomGenerator.QuickGetRandomString(
                SimpleRandomGenerator.CharSelection.All,
                16,
                true);

            byte[] exportData = exporter.Export(
                Vault,
                new KeyValuePair <string, string>("password", passsword));   //auto generate the password and display it in a popup after

            String fullExportPath = String.Empty;
            bool   success        = false;

            try
            {
                switch (Device.RuntimePlatform)
                {
                case Device.UWP:
                {
                    KeyValuePair <string, string[]> extensions = new KeyValuePair <string, string[]>(extension.ToUpper(), new string[] { String.Format(".{0}", extension) });
                    KeyValuePair <string, Stream>?  output     = await devoctomy.cachy.Framework.Native.Native.FileHandler.PickFileForSave(
                        fileName,
                        extensions);

                    if (output.HasValue)
                    {
                        fullExportPath = output.Value.Key;
                        await output.Value.Value.WriteAsync(exportData, 0, exportData.Length);

                        await output.Value.Value.FlushAsync();

                        output.Value.Value.Close();
                        success = true;
                    }

                    break;
                }

                default:
                {
                    String appDataPath = String.Empty;
                    devoctomy.DFramework.Core.IO.Directory.ResolvePath("{AppData}", out appDataPath);
                    if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter))
                    {
                        appDataPath += DLoggerManager.PathDelimiter;
                    }
                    String vaultExportsPath = String.Format("{0}{1}", appDataPath, "Exports");
                    fullExportPath = String.Format("{0}\\{1}", vaultExportsPath, fileName);
                    try
                    {
                        await devoctomy.cachy.Framework.Native.Native.FileHandler.WriteAsync(fullExportPath, exportData);

                        success = true;
                    }
                    catch (Exception)
                    { }
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Exception, "Failed to export credentials. {0}", ex.ToString());
            }

            if (success)
            {
                Credential credential = Vault.CreateCredential();
                credential.GlyphKey    = Fonts.CachyFont.Glyph.Export.ToString();
                credential.GlyphColour = "Red";
                credential.Name        = name;
                credential.Description = "Password protected ZIP export.";
                credential.Notes       = fullExportPath;
                credential.Password    = passsword;
                credential.AddToVault(true);

                if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDuplicatingCred)
                {
                    Common.SaveResult saveResult = await Save();

                    if (saveResult == Common.SaveResult.Success)
                    {
                        VaultIndexFile.Invalidate();
                    }
                }

                NotifyPropertyChanged("FilteredCredentials");

                await App.Controller.MainPageInstance.DisplayAlert("Export Credentials",
                                                                   String.Format("Export was successful, the password for the export ZIP file has been placed in your vault, under the name '{0}'. Please remember to lock your vault to save the credential if you do not have aut-save enabled.", name),
                                                                   "OK");
            }
        }
Beispiel #6
0
        public async void Accept(Object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Accept command invoked.");

            PasswordEntryView passwordEntry = View.FindByName <PasswordEntryView>("PasswordEntry");

            if (passwordEntry != null)
            {
                switch (passwordEntry.StrengthCheck)
                {
                case PasswordEntryView.StrengthCheckResult.InWeakDictionary:
                {
                    bool?agree = await App.Controller.MainPageInstance.DisplayAlert("Security Alert",
                                                                                    "The current password has been found in the internal known weak password database. You are advised to enter another password or use the 'Password Generator'.",
                                                                                    "OK",
                                                                                    "No, I understand the risk");

                    if (agree.HasValue && agree.Value)
                    {
                        return;
                    }
                    break;
                }

                case PasswordEntryView.StrengthCheckResult.FailComplexityCheck:
                {
                    bool?agree = await App.Controller.MainPageInstance.DisplayAlert("Security Alert",
                                                                                    "The current password has failed the complexity test. You are advised to enter another password or use the 'Password Generator'.",
                                                                                    "OK",
                                                                                    "No, I understand the risk");

                    if (agree.HasValue && agree.Value)
                    {
                        return;
                    }
                    break;
                }

                case PasswordEntryView.StrengthCheckResult.OK:
                {
                    bool duplicate = false;
                    switch (_mode)
                    {
                    case EditorMode.Create:
                    {
                        duplicate = Credential.Vault.Credentials.Any(cred => cred.Password == Credential.Password);
                        break;
                    }

                    case EditorMode.Edit:
                    {
                        duplicate = Credential.Vault.Credentials.Where(cred => cred.ID != Credential.ID).Any(cred => cred.Password == Credential.Password);
                        break;
                    }
                    }
                    if (duplicate)
                    {
                        bool?agree = await App.Controller.MainPageInstance.DisplayAlert("Security Alert",
                                                                                        "The current password is already in use by another credential in your vault. You are advised to enter another password or use the 'Password Generator'.",
                                                                                        "OK",
                                                                                        "No, I understand the risk");

                        if (agree.HasValue && agree.Value)
                        {
                            return;
                        }
                    }
                    //Check vault for duplicate usage
                    break;
                }
                }
            }

            //Add the credential to the vault that it was created for
            switch (_mode)
            {
            case EditorMode.Create:
            {
                //This is a temporary fix for now as when typing into the tag
                //it can create a whole bunch of additional tags erroneously
                TagEditor tagEditor = View.FindByName <TagEditor>("CredentialTags");
                if (tagEditor != null)
                {
                    tagEditor.Recreate();
                }

                Credential.AddToVault(true);

                if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDuplicatingCred)
                {
                    Common.SaveResult saveResult = await Save();

                    if (saveResult == Common.SaveResult.Success)
                    {
                        VaultIndexFile.Invalidate();
                    }
                }

                App.Controller.NavigateTo("vault",
                                          new KeyValuePair <String, Object>("Vault", Credential.Vault));
                break;
            }

            case EditorMode.Edit:
            {
                //This is a temporary fix for now as when typing into the tag
                //it can create a whole bunch of additional tags erroneously
                TagEditor tagEditor = View.FindByName <TagEditor>("CredentialTags");
                if (tagEditor != null)
                {
                    tagEditor.Recreate();
                }

                Credential originalCredential = Credential.Vault.Credentials.Where(cred => cred.ID == Credential.ID).First();
                Credential.CopyTo(originalCredential);

                if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDuplicatingCred)
                {
                    Common.SaveResult saveResult = await Save();

                    if (saveResult == Common.SaveResult.Success)
                    {
                        VaultIndexFile.Invalidate();
                    }
                }

                App.Controller.NavigateTo("vault",
                                          new KeyValuePair <String, Object>("Vault", Credential.Vault));
                break;
            }
            }
        }