private void BinPoolAdd(ProtectedBinaryDictionary dict) { foreach (KeyValuePair <string, ProtectedBinary> kvp in dict) { BinPoolAdd(kvp.Value); } }
public void Save(ProtectedBinaryDictionary dict) { using (var sw = new StringWriter()) using (JsonWriter writer = new JsonTextWriter(sw)) { Serializer.Serialize(writer, this); var data = new ProtectedBinary(false, Encoding.Unicode.GetBytes(sw.ToString())); dict.Set(Namespace, data); } }
public static ISshKey GetSshKey(this EntrySettings settings, ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries, SprContext sprContext) { if (!settings.AllowUseOfSshKey) { return(null); } KeyFormatter.GetPassphraseCallback getPassphraseCallback = delegate(string comment) { var securePassphrase = new SecureString(); var passphrase = SprEngine.Compile(strings.ReadSafe( PwDefs.PasswordField), sprContext); foreach (var c in passphrase) { securePassphrase.AppendChar(c); } return(securePassphrase); }; Func <Stream> getPrivateKeyStream; Func <Stream> getPublicKeyStream = null; switch (settings.Location.SelectedType) { case EntrySettings.LocationType.Attachment: if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) { throw new NoAttachmentException(); } var privateKeyData = binaries.Get(settings.Location.AttachmentName); var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub"); getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData()); if (publicKeyData != null) { getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData()); } return(GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback)); case EntrySettings.LocationType.File: var filename = settings.Location.FileName.ExpandEnvironmentVariables(); getPrivateKeyStream = () => File.OpenRead(filename); var publicKeyFile = filename + ".pub"; if (File.Exists(publicKeyFile)) { getPublicKeyStream = () => File.OpenRead(publicKeyFile); } return(GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback)); default: return(null); } }
/// <summary> /// Assign properties to the current entry based on a template entry. /// </summary> /// <param name="peTemplate">Template entry. Must not be <c>null</c>.</param> /// <param name="bOnlyIfNewer">Only set the properties of the template entry /// if it is newer than the current one.</param> /// <param name="bIncludeHistory">If <c>true</c>, the history will be /// copied, too.</param> /// <param name="bAssignLocationChanged">If <c>true</c>, the /// <c>LocationChanged</c> property is copied, otherwise not.</param> public void AssignProperties(PwEntry peTemplate, bool bOnlyIfNewer, bool bIncludeHistory, bool bAssignLocationChanged) { if (peTemplate == null) { Debug.Assert(false); throw new ArgumentNullException("peTemplate"); } if (bOnlyIfNewer && (TimeUtil.Compare(peTemplate.m_tLastMod, m_tLastMod, true) < 0)) { return; } // Template UUID should be the same as the current one Debug.Assert(m_uuid.Equals(peTemplate.m_uuid)); m_uuid = peTemplate.m_uuid; if (bAssignLocationChanged) { m_tParentGroupLastMod = peTemplate.m_tParentGroupLastMod; m_puPrevParentGroup = peTemplate.m_puPrevParentGroup; } m_dStrings = peTemplate.m_dStrings.CloneDeep(); m_dBinaries = peTemplate.m_dBinaries.CloneDeep(); m_cfgAutoType = peTemplate.m_cfgAutoType.CloneDeep(); if (bIncludeHistory) { m_lHistory = peTemplate.m_lHistory.CloneDeep(); } m_pwIcon = peTemplate.m_pwIcon; m_puCustomIcon = peTemplate.m_puCustomIcon; // Immutable m_clrForeground = peTemplate.m_clrForeground; m_clrBackground = peTemplate.m_clrBackground; m_tCreation = peTemplate.m_tCreation; m_tLastMod = peTemplate.m_tLastMod; m_tLastAccess = peTemplate.m_tLastAccess; m_tExpire = peTemplate.m_tExpire; m_bExpires = peTemplate.m_bExpires; m_uUsageCount = peTemplate.m_uUsageCount; m_strOverrideUrl = peTemplate.m_strOverrideUrl; m_bQualityCheck = peTemplate.m_bQualityCheck; m_lTags = new List <string>(peTemplate.m_lTags); m_dCustomData = peTemplate.m_dCustomData.CloneDeep(); }
private void WriteList(ProtectedBinaryDictionary dictBinaries) { Debug.Assert(dictBinaries != null); if (dictBinaries == null) { throw new ArgumentNullException("dictBinaries"); } foreach (KeyValuePair <string, ProtectedBinary> kvp in dictBinaries) { WriteObject(kvp.Key, kvp.Value, true); } }
internal void ReadProtectedBinaryEx(XmlNode xmlNode, ProtectedBinaryDictionary dictStorage) { ProcessNode(xmlNode); string strKey = string.Empty; XorredBuffer xbValue = null; byte[] pbValue = null; foreach (XmlNode xmlChild in xmlNode.ChildNodes) { if (xmlChild.Name == ElemKey) { ProcessNode(xmlChild); strKey = xmlChild.InnerText; } else if (xmlChild.Name == ElemValue) { xbValue = ProcessNode(xmlChild); if (xbValue == null) { string strInner = xmlChild.InnerText; if (strInner.Length > 0) { pbValue = Convert.FromBase64String(strInner); } else { pbValue = new byte[0]; } } } else { ReadUnknown(xmlChild); } } if (xbValue != null) { Debug.Assert(pbValue == null); dictStorage.Set(strKey, new ProtectedBinary(true, xbValue)); } else { Debug.Assert(pbValue != null); dictStorage.Set(strKey, new ProtectedBinary(false, pbValue)); } }
/// <summary> /// Assign properties to the current entry based on a template entry. /// </summary> /// <param name="peTemplate">Template entry. Must not be <c>null</c>.</param> /// <param name="bOnlyIfNewer">Only set the properties of the template entry /// if it is newer than the current one.</param> /// <param name="bIncludeHistory">If <c>true</c>, the history will be /// copied, too.</param> /// <param name="bAssignLocationChanged">If <c>true</c>, the /// <c>LocationChanged</c> property is copied, otherwise not.</param> public void AssignProperties(PwEntry peTemplate, bool bOnlyIfNewer, bool bIncludeHistory, bool bAssignLocationChanged) { Debug.Assert(peTemplate != null); if (peTemplate == null) { throw new ArgumentNullException("peTemplate"); } if (bOnlyIfNewer && (peTemplate.m_tLastMod < m_tLastMod)) { return; } // Template UUID should be the same as the current one Debug.Assert(m_uuid.EqualsValue(peTemplate.m_uuid)); m_uuid = peTemplate.m_uuid; if (bAssignLocationChanged) { m_tParentGroupLastMod = peTemplate.m_tParentGroupLastMod; } m_listStrings = peTemplate.m_listStrings; m_listBinaries = peTemplate.m_listBinaries; m_listAutoType = peTemplate.m_listAutoType; if (bIncludeHistory) { m_listHistory = peTemplate.m_listHistory; } m_pwIcon = peTemplate.m_pwIcon; m_pwCustomIconID = peTemplate.m_pwCustomIconID; // Immutable m_clrForeground = peTemplate.m_clrForeground; m_clrBackground = peTemplate.m_clrBackground; m_tCreation = peTemplate.m_tCreation; m_tLastMod = peTemplate.m_tLastMod; m_tLastAccess = peTemplate.m_tLastAccess; m_tExpire = peTemplate.m_tExpire; m_bExpires = peTemplate.m_bExpires; m_uUsageCount = peTemplate.m_uUsageCount; m_strOverrideUrl = peTemplate.m_strOverrideUrl; m_vTags = new List <string>(peTemplate.m_vTags); }
public static void SetKeeAgentSettings(this ProtectedBinaryDictionary binaries, EntrySettings settings) { // only save if there is an existing entry or AllowUseOfSshKey is checked // this way we don't pollute entries that don't have SSH keys if (binaries.Get(settingsBinaryId) != null || settings.AllowUseOfSshKey) { using (var writer = new StringWriter()) { EntrySettingsSerializer.Serialize(writer, settings); // string is protected just to make UI look cleaner binaries.Set(settingsBinaryId, new ProtectedBinary(false, Encoding.Unicode.GetBytes(writer.ToString()))); } } }
private void ReadProtectedBinaryEx(XmlNode xmlNode, ProtectedBinaryDictionary dictStorage) { ProcessNode(xmlNode); string strKey = string.Empty; XorredBuffer xbValue = null; byte[] pbValue = null; foreach(XmlNode xmlChild in xmlNode.ChildNodes) { if(xmlChild.Name == ElemKey) { ProcessNode(xmlChild); strKey = xmlChild.InnerText; } else if(xmlChild.Name == ElemValue) { xbValue = ProcessNode(xmlChild); if(xbValue == null) { string strInner = xmlChild.InnerText; if(strInner.Length > 0) pbValue = Convert.FromBase64String(strInner); else pbValue = new byte[0]; } } else ReadUnknown(xmlChild); } if(xbValue != null) { Debug.Assert(pbValue == null); dictStorage.Set(strKey, new ProtectedBinary(true, xbValue)); } else { Debug.Assert(pbValue != null); dictStorage.Set(strKey, new ProtectedBinary(false, pbValue)); } }
public static ISshKey GetSshKey(this EntrySettings settings, ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries, SprContext sprContext) { if (!settings.AllowUseOfSshKey) { return null; } KeyFormatter.GetPassphraseCallback getPassphraseCallback = delegate(string comment) { var securePassphrase = new SecureString(); var passphrase = SprEngine.Compile(strings.ReadSafe( PwDefs.PasswordField), sprContext); foreach (var c in passphrase) { securePassphrase.AppendChar(c); } return securePassphrase; }; Func<Stream> getPrivateKeyStream; Func<Stream> getPublicKeyStream = null; switch (settings.Location.SelectedType) { case EntrySettings.LocationType.Attachment: if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) { throw new NoAttachmentException(); } var privateKeyData = binaries.Get(settings.Location.AttachmentName); var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub"); getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData()); if (publicKeyData != null) getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData()); return GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback); case EntrySettings.LocationType.File: getPrivateKeyStream = () => File.OpenRead(settings.Location.FileName); var publicKeyFile = settings.Location.FileName + ".pub"; if (File.Exists(publicKeyFile)) getPublicKeyStream = () => File.OpenRead(publicKeyFile); return GetSshKey(getPrivateKeyStream, getPublicKeyStream, settings.Location.AttachmentName, getPassphraseCallback); default: return null; } }
public void InitEx(PwEntry pwEntry, PwEditMode pwMode, PwDatabase pwDatabase, ImageList ilIcons, bool bShowAdvancedByDefault, bool bSelectFullTitle) { Debug.Assert(pwEntry != null); if(pwEntry == null) throw new ArgumentNullException("pwEntry"); Debug.Assert(pwMode != PwEditMode.Invalid); if(pwMode == PwEditMode.Invalid) throw new ArgumentException(); Debug.Assert(ilIcons != null); if(ilIcons == null) throw new ArgumentNullException("ilIcons"); m_pwEntry = pwEntry; m_pwEditMode = pwMode; m_pwDatabase = pwDatabase; m_ilIcons = ilIcons; m_bShowAdvancedByDefault = bShowAdvancedByDefault; m_bSelectFullTitle = bSelectFullTitle; m_vStrings = m_pwEntry.Strings.CloneDeep(); m_vBinaries = m_pwEntry.Binaries.CloneDeep(); m_atConfig = m_pwEntry.AutoType.CloneDeep(); m_vHistory = m_pwEntry.History.CloneDeep(); }
private void BinPoolAdd(ProtectedBinaryDictionary dict) { foreach(KeyValuePair<string, ProtectedBinary> kvp in dict) { BinPoolAdd(kvp.Value); } }
public NamedProtectedBinaryListBuffer(ProtectedBinaryDictionary binaryDictionary) { mBinaryDictionary = binaryDictionary; }
private void WriteList(ProtectedBinaryDictionary dictBinaries) { Debug.Assert(dictBinaries != null); if(dictBinaries == null) throw new ArgumentNullException("dictBinaries"); foreach(KeyValuePair<string, ProtectedBinary> kvp in dictBinaries) WriteObject(kvp.Key, kvp.Value, true); }