public static void SetKeeAgentSettings(this PwEntry entry, EntrySettings settings) { entry.Binaries.SetKeeAgentSettings(settings); // remove old settings string if (entry.Strings.GetKeys().Contains(settingsStringId)) { entry.Strings.Remove(settingsStringId); } }
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); } }
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()))); } } }