private async Task <Common.SaveResult> Save() { 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; } } Common.SaveResult saveResult = await Vault.Save(parameters.ToArray()); return(saveResult); }
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 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"); }
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(); } }
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"); } }
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; } } }
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."); if (String.IsNullOrEmpty(Name)) { return; } if (String.IsNullOrEmpty(MasterPassphrase)) { return; } Vault vault = new Vault(Name, Description); String appDataPath = String.Empty; Directory.ResolvePath("{AppData}", out appDataPath); if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter)) { appDataPath += DLoggerManager.PathDelimiter; } string fileName = CreateFileName(vault, FileName); String vaultFullPath = String.Format("{0}{1}", appDataPath, String.Format(@"LocalVaults{0}{1}", DLoggerManager.PathDelimiter, fileName)); 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; } } Common.SaveResult result = await vault.SaveAs( new AESEncryptedVaultSerialiser(), vaultFullPath, MasterPassphrase, true, parameters.ToArray()); if (result == Common.SaveResult.Success) { if (SyncModeCloudSync) { VaultIndexFile.Instance.AddVaultToLocalVaultStoreIndex(vault, Common.SyncMode.CloudProvider, SelectedCloudProvider.ID, String.Format("/{0}/{1}", "Vaults", fileName), false); } else { VaultIndexFile.Instance.AddVaultToLocalVaultStoreIndex(vault, Common.SyncMode.LocalOnly, String.Empty, String.Empty, false); } } else { await App.Controller.MainPageInstance.DisplayAlert("Create Vault", "Failed to create vault.", "OK"); } ((App)App.Current).NavigateToVaultsList(); }
public async Task CreateVault() { if (Stage != FirstRun.FirstRunStage.FullSetup) { return; } Vault vault = new Vault(Name, Description); String appDataPath = String.Empty; Directory.ResolvePath("{AppData}", out appDataPath); if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter)) { appDataPath += DLoggerManager.PathDelimiter; } string fileName = CreateFileName(vault, "{Name}-{ddMMyyyy}.vault"); String vaultFullPath = String.Format("{0}{1}", appDataPath, String.Format(@"LocalVaults{0}{1}", DLoggerManager.PathDelimiter, fileName)); 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; } } Common.SaveResult result = await vault.SaveAs( new AESEncryptedVaultSerialiser(), vaultFullPath, MasterPassphrase, true, parameters.ToArray()); if (result == Common.SaveResult.Success) { if (SyncMode == Common.SyncMode.CloudProvider) { VaultIndexFile.Instance.AddVaultToLocalVaultStoreIndex(vault, Common.SyncMode.CloudProvider, CloudProvider.ID, String.Format("/{0}/{1}", "Vaults", fileName), false); } else { VaultIndexFile.Instance.AddVaultToLocalVaultStoreIndex(vault, Common.SyncMode.LocalOnly, String.Empty, String.Empty, false); } } else { await App.Controller.MainPageInstance.DisplayAlert("Create Vault", "Failed to create vault.", "OK"); } }