public bool CanChangePassword(VaultParams vaultParams) { if (!Vault.Exists()) { return(false); } if (null == vaultParams.Password || vaultParams.Password.Length <= 0) { return(false); } if (null == vaultParams.ValidationPassword || vaultParams.ValidationPassword.Length <= 0) { return(false); } if (!SecureStringExtension.Equals(vaultParams.Password, vaultParams.ValidationPassword)) { return(false); } return(true); }
public bool CanCreateVault(VaultParams vaultParams) { if (null == vaultParams) { return(false); } if (string.IsNullOrWhiteSpace(vaultParams.FilePath)) { return(false); } //if (!Uri.IsWellFormedUriString("file:///" + vaultParams.FilePath.Replace("\\", "/"), UriKind.Absolute)) //{ // return false; //} if (string.IsNullOrWhiteSpace(vaultParams.Name)) { return(false); } if (null == vaultParams.Password || null == vaultParams.ValidationPassword) { return(false); } if (!SecureStringExtension.Equals(vaultParams.Password, vaultParams.ValidationPassword)) { return(false); } return(true); }
public MainWindowViewModel() { this.OkCommand.Subscribe(_ => { Debug.WriteLine("OKボタンがクリックされました。"); if (this.Password.Length > 0) { Debug.WriteLine(SecureStringExtension.SecureStringToText(this.Password)); } }); this.ResetCommand.Subscribe(_ => { this.Password.Clear(); }); this.SetPasswordCommand.Subscribe(_ => { this.Password.Clear(); foreach (char c in "ABCDEFG") { this.Password.AppendChar(c); } Messenger.Instance.GetEvent <PubSubEvent <SecureString> >().Publish(Password); }); }
public MainWindow() { InitializeComponent(); Messenger.Instance.GetEvent <PubSubEvent <SecureString> >().Subscribe(x => { this.TestPassword.Password = SecureStringExtension.SecureStringToText(x); Debug.WriteLine(SecureStringExtension.SecureStringToText(x)); }); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (!(value is SecureString)) { return(new ValidationResult(false, "This value is not a SecureString")); } if (null == ValidationPassword || null == value) { return(new ValidationResult(false, "Password is required")); } if (!SecureStringExtension.Equals(value as SecureString, ValidationPassword)) { return(new ValidationResult(false, "Passwords do not match")); } return(ValidationResult.ValidResult); }
static async Task Main(string[] args) { int result = Parser.Default.ParseArguments <Options>(args) .MapResult( (Options opt) => { domainName = opt.SalesForceDomain; groupName = opt.GroupName; entryName = opt.EntryName; pathToKeePassDb = opt.KDBXPath; objectWithAttachments = Enum.GetName(typeof(SFObjectsWithAttachments), opt.SFObject); resultFileName = opt.EcryptedAttachmentsTargetFile == null ? "encrypted_" + objectWithAttachments + ".dat" : opt.EcryptedAttachmentsTargetFile; workingMode = opt.WorkMode; numberOfThreads = opt.NumberOfWorkingThreads; if (opt.LogFilePath != null && !opt.LogFilePath.Equals(String.Empty)) { Trace.Listeners.Add(new TextWriterTraceListener(opt.LogFilePath, "Backup_fileTracer")); Trace.Listeners["Backup_fileTracer"].TraceOutputOptions |= TraceOptions.DateTime; } if (opt.LogToConsole != 0) { Trace.Listeners.Add(consoleTraceListener); } Trace.AutoFlush = true; Trace.Listeners.Remove("Default"); if (workingMode == WorkingModes.Compare && (opt.ComparisonResultsFilePath == null || opt.ComparisonResultsFilePath.Equals(String.Empty))) { Trace.TraceError($"If workmode is set to compare then comparison file must be provided."); WaitExitingCountdown(waittime); Environment.Exit(-1); return(0); } else { pathToComparisonResults = opt.ComparisonResultsFilePath; if (workingMode == WorkingModes.Read) { filter = "+WHERE+" + opt.ReadModeFilter; } } Trace.TraceInformation("Arguments have been successfully parsed"); return(1); }, (IEnumerable <Error> errs) => { WaitExitingCountdown(waittime); Environment.Exit(-1); return(0); }); SecureString securePwd = new SecureString(); Console.Write("Enter password for KeePass: "******"*"); } else { if (securePwd.Length > 0) { securePwd.RemoveAt(securePwd.Length - 1); Console.Write("\b \b"); } } // Exit if Enter key is pressed. } while (key.Key != ConsoleKey.Enter); Console.WriteLine(); Dictionary <string, ProtectedString> credentialsDict = new Dictionary <string, ProtectedString>(OpenKeePassDB(securePwd)); Trace.TraceInformation($"Got {credentialsDict.Count} credentials"); if (credentialsDict.Where(t => t.Key == "IV" || t.Key == "AESPass" || t.Key == "Salt").Count() < 3) { Trace.TraceError("Necessary cryptographic input is absent in the provided entry in the KDBX."); WaitExitingCountdown(waittime); return; } else if (workingMode == WorkingModes.Prepare) { Trace.TraceInformation("Preparation of KDBX has been successfully completed"); WaitExitingCountdown(waittime); return; } Dictionary <string, string> salesForceSID = new Dictionary <string, string>(await GetSalesForceSessionId(credentialsDict)); if (salesForceSID.Count == 0) { Trace.TraceError("Error getting SalesForce session ID. Exiting..."); WaitExitingCountdown(waittime); return; } #region ChecksOfNeededFiles switch (workingMode) { case WorkingModes.Read: listOfIds = (await GetListOfIds(salesForceSID, objectWithAttachments)).ToList(); if (listOfIds.Count != 0) { Trace.TraceInformation($"Got {listOfIds.Count} Ids in the {objectWithAttachments} object"); } else { Trace.TraceError("Nothing to extract. Exiting..."); WaitExitingCountdown(waittime); Environment.Exit(-2); } break; case WorkingModes.Write: case WorkingModes.Compare: if (!File.Exists(resultFileName)) { Trace.TraceError("Source file does not exist. Exiting..."); WaitExitingCountdown(waittime); Environment.Exit(-3); } break;; } #endregion #region CryptographicStuff SymmetricAlgorithm cipher = SymmetricAlgorithm.Create("AesManaged"); cipher.Mode = CipherMode.CBC; cipher.Padding = PaddingMode.PKCS7; cipher.IV = Convert.FromBase64String(credentialsDict["IV"].ReadString()); Byte[] passwordKey = NewPasswordKey(SecureStringExtension.ToSecureString(credentialsDict["AESPass"].ReadString()), credentialsDict["Salt"].ReadString()); #endregion #region StartWorkers List <Task> tasks = new List <Task>(); switch (workingMode) { case WorkingModes.Read: using (TextWriter resultStream = TextWriter.Synchronized(new StreamWriter(resultFileName, false, Encoding.ASCII))) { Trace.TraceInformation($"Initiating {numberOfThreads} workers to read data."); for (int i = 0; i < numberOfThreads; i++) { tasks.Add(Task.Run( () => doWork(listOfIds.ToList(), salesForceSID, objectWithAttachments, cipher.CreateEncryptor(passwordKey, cipher.IV), resultStream))); } Task.WaitAll(tasks.ToArray()); } break; case WorkingModes.Write: minSizeQueue = new MinSizeQueue <KeyValuePair <string, string> >(numberOfThreads); _ = FillQueue(); Trace.TraceInformation($"Initiating {numberOfThreads} workers to write data."); for (int i = 0; i < numberOfThreads; i++) { tasks.Add(Task.Run( () => doWork(minSizeQueue, salesForceSID, objectWithAttachments, cipher.CreateDecryptor(passwordKey, cipher.IV)))); } Task.WaitAll(tasks.ToArray()); break; case WorkingModes.Compare: minSizeQueue = new MinSizeQueue <KeyValuePair <string, string> >(numberOfThreads); _ = FillQueue(); using (TextWriter resultStream = TextWriter.Synchronized(new StreamWriter(pathToComparisonResults, false, Encoding.ASCII))) { Trace.TraceInformation($"Initiating {numberOfThreads} workers to compare data."); for (int i = 0; i < numberOfThreads; i++) { tasks.Add(Task.Run( () => doWork(minSizeQueue, salesForceSID, objectWithAttachments, cipher.CreateDecryptor(passwordKey, cipher.IV), resultStream))); } Task.WaitAll(tasks.ToArray()); } break; } Trace.TraceInformation("All threads complete"); WaitExitingCountdown(waittime); }