public async Task CreateVaultExportThenImport() { Vault sourceVault = new Vault(); int count = 5000; for (int i = 0; i < count; i++) { Credential credential = CredentialTests.CreateRandomCredential(_rng); credential.AddToVault(sourceVault, false); } VaultExporter exporter = new VaultExporter( Common.ExportFormat.cachyCSV1_0, Common.ExportWrapping.Raw); byte[] csv = exporter.Export(sourceVault); string csvString = System.Text.Encoding.UTF8.GetString(csv); Vault destVault = new Vault(); CSVImporter importer = new CSVImporter(csvString); await importer.ImportToVault(destVault, VaultExporter.GetFieldMappings()); for (int i = 0; i < count; i++) { Credential sourceCredential = sourceVault.Credentials[i]; Credential destCredential = destVault.Credentials[i]; Assert.IsTrue(sourceCredential.SimpleCompare(destCredential) == 0); } }
public async Task ImportToVault( Vault vault, List <ImportFieldMapping> mappings) { List <Dictionary <string, string> > allRows = await ReadRows(); foreach (Dictionary <string, string> curRow in allRows) { Credential credential = CreateCredentialFromRecord( vault, curRow, mappings); credential.AddToVault(true); } }
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; } } }