private void OnEnableCopy(AutoExecItem item) { //disable this device for the cloned entry KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, false); //remember the original device settings ProtectedString ifDeviceOrig = item.Entry.Strings.GetSafe(KeeAutoExecExt._ifDevice); //reset device settings so only the current device is enabled item.Entry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, "")); KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, true); //now clone var newEntry = item.Entry.CloneDeep(); //reset device settings item.Entry.Strings.Set(KeeAutoExecExt._ifDevice, ifDeviceOrig); newEntry.SetUuid(new PwUuid(true), true); // Create new UUID string strTitle = newEntry.Strings.ReadSafe(PwDefs.TitleField); newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, strTitle + " (" + Android.OS.Build.Model + ")")); var addTask = new AddEntry(this, App.Kp2a, newEntry, item.Entry.ParentGroup, new ActionOnFinish(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); pt.Run(); }
private void Save(AutoExecItem item) { var addTask = new SaveDb(this, App.Kp2a, App.Kp2a.FindDatabaseForElement(item.Entry), new ActionOnFinish(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update())); ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); pt.Run(); }
private static int PrioritySort(AutoExecItem x, AutoExecItem y) { if (x == null) { Debug.Assert(false); return((y == null) ? 0 : -1); } if (y == null) { Debug.Assert(false); return(1); } return(x.Priority.CompareTo(y.Priority)); }
public static void SetDeviceEnabled(AutoExecItem a, string strDevice, bool enabled = true) { if (string.IsNullOrEmpty(strDevice)) { return; } var devices = GetIfDevice(a); devices[strDevice] = enabled; string result = BuildIfDevice(devices); a.Entry.Strings.Set(_ifDevice, new ProtectedString(false, result)); }
public static Dictionary <string, bool> GetIfDevice(AutoExecItem item) { Dictionary <string, bool> result = new Dictionary <string, bool>(); string strList = item.IfDevice; if (string.IsNullOrEmpty(strList)) { return(result); } CsvOptions opt = new CsvOptions { BackslashIsEscape = false, TrimFields = true }; CsvStreamReaderEx csv = new CsvStreamReaderEx(strList, opt); string[] vFlt = csv.ReadLine(); if (vFlt == null) { Debug.Assert(false); return(result); } foreach (string strFlt in vFlt) { if (string.IsNullOrEmpty(strFlt)) { continue; } if (strFlt[0] == '!') // Exclusion { result[strFlt.Substring(1).TrimStart()] = false; } else // Inclusion { result[strFlt] = true; } } return(result); }
private static bool IsValidIoc(AutoExecItem item) { IOConnectionInfo itemIoc; if (!KeeAutoExecExt.TryGetDatabaseIoc(item, out itemIoc)) { return(false); } try { //see if we have a file storage for the given protocol App.Kp2a.GetFileStorage(itemIoc); } catch (Exception e) { return(false); } return(true); }
public static AutoExecItem MakeAutoExecItem(PwDatabase pd, PwEntry pe, long lPriStd) { string str = pe.Strings.ReadSafe(PwDefs.UrlField); AutoExecItem a = new AutoExecItem(pe, pd); SprContext ctx = new SprContext(pe, pd, SprCompileFlags.All); if (pe.Expires && (pe.ExpiryTime <= DateTime.UtcNow)) { a.Enabled = false; } bool?ob = GetBoolEx(pe, "Enabled", ctx); if (ob.HasValue) { a.Enabled = ob.Value; } ob = GetBoolEx(pe, "Visible", ctx); if (ob.HasValue) { a.Visible = ob.Value; } long lItemPri = lPriStd; if (GetString(pe, "Priority", ctx, true, out str)) { long.TryParse(str, out lItemPri); } a.Priority = lItemPri; if (GetString(pe, _ifDevice, ctx, true, out str)) { a.IfDevice = str; } return(a); }
public static bool IsDeviceEnabled(AutoExecItem a, string strDevice, out bool isExplicit) { isExplicit = false; var ifDevices = GetIfDevice(a); if (!ifDevices.Any() || string.IsNullOrEmpty(strDevice)) { return(true); } bool bHasIncl = false, bHasExcl = false; foreach (var kvp in ifDevices) { if (string.IsNullOrEmpty(kvp.Key)) { continue; } if (strDevice.Equals(kvp.Key, StrUtil.CaseIgnoreCmp)) { isExplicit = true; return(kvp.Value); } if (kvp.Value == false) { bHasExcl = true; } else { bHasIncl = true; } } return(bHasExcl || !bHasIncl); }
private void AutoOpenEntryPriv(AutoExecItem a, bool bManual) { PwEntry pe = a.Entry; PwDatabase pdContext = a.Database; SprContext ctxNoEsc = new SprContext(pe, pdContext, SprCompileFlags.All); SprContext ctxEsc = new SprContext(pe, pdContext, SprCompileFlags.All, false, true); string strDb; if (!GetString(pe, PwDefs.UrlField, ctxEsc, true, out strDb)) { return; } IOConnectionInfo ioc = IOConnectionInfo.FromPath(strDb); //TODO /*if (ioc.IsLocalFile() && !UrlUtil.IsAbsolutePath(strDb)) * ioc = IOConnectionInfo.FromPath(UrlUtil.MakeAbsolutePath( * WinUtil.GetExecutable(), strDb));*/ if (ioc.Path.Length == 0) { return; } string strIocUserName; if (GetString(pe, "IocUserName", ctxNoEsc, true, out strIocUserName)) { ioc.UserName = strIocUserName; } string strIocPassword; if (GetString(pe, "IocPassword", ctxNoEsc, true, out strIocPassword)) { ioc.Password = strIocPassword; } if ((strIocUserName.Length != 0) && (strIocPassword.Length != 0)) { ioc.IsComplete = true; } string str; if (GetString(pe, "IocTimeout", ctxNoEsc, true, out str)) { long l; if (long.TryParse(str, out l)) { ioc.Properties.SetLong(IocKnownProperties.Timeout, l); } } bool?ob = GetBoolEx(pe, "IocPreAuth", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.PreAuth, ob.Value); } if (GetString(pe, "IocUserAgent", ctxNoEsc, true, out str)) { ioc.Properties.Set(IocKnownProperties.UserAgent, str); } ob = GetBoolEx(pe, "IocExpect100Continue", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.Expect100Continue, ob.Value); } ob = GetBoolEx(pe, "IocPassive", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.Passive, ob.Value); } ob = GetBoolEx(pe, "SkipIfNotExists", ctxNoEsc); if (!ob.HasValue) // Backw. compat. { ob = GetBoolEx(pe, "Skip if not exists", ctxNoEsc); } if (ob.HasValue && ob.Value) { if (!IOConnection.FileExists(ioc)) { return; } } CompositeKey ck = new CompositeKey(); if (GetString(pe, PwDefs.PasswordField, ctxNoEsc, false, out str)) { ck.AddUserKey(new KcpPassword(str)); } if (GetString(pe, PwDefs.UserNameField, ctxNoEsc, false, out str)) { string strAbs = str; IOConnectionInfo iocKey = IOConnectionInfo.FromPath(strAbs); if (iocKey.IsLocalFile() && !UrlUtil.IsAbsolutePath(strAbs)) { //TODO /* strAbs = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strAbs);*/ } ob = GetBoolEx(pe, "SkipIfKeyFileNotExists", ctxNoEsc); if (ob.HasValue && ob.Value) { IOConnectionInfo iocKeyAbs = IOConnectionInfo.FromPath(strAbs); if (!IOConnection.FileExists(iocKeyAbs)) { return; } } try { ck.AddUserKey(new KcpKeyFile(strAbs)); } catch (InvalidOperationException) { //TODO throw new Exception("TODO"); //throw new Exception(strAbs + MessageService.NewParagraph + KPRes.KeyFileError); } catch (Exception) { throw; } } else // Try getting key file from attachments { ProtectedBinary pBin = pe.Binaries.Get("KeyFile.bin"); if (pBin != null) { ck.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromPath( StrUtil.DataToDataUri(pBin.ReadData(), null)))); } } if (GetString(pe, "KeyProvider", ctxNoEsc, true, out str)) { /*TODO KeyProvider kp = m_host.KeyProviderPool.Get(str); * if (kp == null) * throw new Exception(@"Unknown key provider: '" + str + @"'!"); * * KeyProviderQueryContext ctxKP = new KeyProviderQueryContext( * ioc, false, false); * * bool bPerformHash = !kp.DirectKey; * byte[] pbProvKey = kp.GetKey(ctxKP); * if ((pbProvKey != null) && (pbProvKey.Length != 0)) * { * ck.AddUserKey(new KcpCustomKey(str, pbProvKey, bPerformHash)); * MemUtil.ZeroByteArray(pbProvKey); * } * else return; // Provider has shown error message*/ throw new Exception("KeyProvider not supported"); } ob = GetBoolEx(pe, "UserAccount", ctxNoEsc); if (ob.HasValue && ob.Value) { ck.AddUserKey(new KcpUserAccount()); } if (ck.UserKeyCount == 0) { return; } GetString(pe, "Focus", ctxNoEsc, true, out str); bool bRestoreFocus = str.Equals("Restore", StrUtil.CaseIgnoreCmp); /*TODO * PwDatabase pdPrev = m_host.MainWindow.ActiveDatabase; * * m_host.MainWindow.OpenDatabase(ioc, ck, true); * * if (bRestoreFocus && (pdPrev != null) && !bManual) * { * PwDocument docPrev = m_host.MainWindow.DocumentManager.FindDocument( * pdPrev); * if (docPrev != null) m_host.MainWindow.MakeDocumentActive(docPrev); * else { Debug.Assert(false); } * }*/ }
public static bool TryGetDatabaseIoc(AutoExecItem a, out IOConnectionInfo ioc) { PwEntry pe = a.Entry; PwDatabase pdContext = a.Database; SprContext ctxNoEsc = new SprContext(pe, pdContext, SprCompileFlags.All); SprContext ctxEsc = new SprContext(pe, pdContext, SprCompileFlags.All, false, true); ioc = null; string strDb; if (!GetString(pe, PwDefs.UrlField, ctxEsc, true, out strDb)) { return(false); } ioc = IOConnectionInfo.FromPath(strDb); //TODO /*if (ioc.IsLocalFile() && !UrlUtil.IsAbsolutePath(strDb)) * ioc = IOConnectionInfo.FromPath(UrlUtil.MakeAbsolutePath( * WinUtil.GetExecutable(), strDb));*/ if (ioc.Path.Length == 0) { return(false); } string strIocUserName; if (GetString(pe, "IocUserName", ctxNoEsc, true, out strIocUserName)) { ioc.UserName = strIocUserName; } string strIocPassword; if (GetString(pe, "IocPassword", ctxNoEsc, true, out strIocPassword)) { ioc.Password = strIocPassword; } if ((strIocUserName.Length != 0) && (strIocPassword.Length != 0)) { ioc.IsComplete = true; } string str; if (GetString(pe, "IocTimeout", ctxNoEsc, true, out str)) { long l; if (long.TryParse(str, out l)) { ioc.Properties.SetLong(IocKnownProperties.Timeout, l); } } bool?ob = GetBoolEx(pe, "IocPreAuth", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.PreAuth, ob.Value); } if (GetString(pe, "IocUserAgent", ctxNoEsc, true, out str)) { ioc.Properties.Set(IocKnownProperties.UserAgent, str); } ob = GetBoolEx(pe, "IocExpect100Continue", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.Expect100Continue, ob.Value); } ob = GetBoolEx(pe, "IocPassive", ctxNoEsc); if (ob.HasValue) { ioc.Properties.SetBool(IocKnownProperties.Passive, ob.Value); } return(true); }
public static bool AutoOpenEntry(Activity activity, AutoExecItem item, bool bManual, ActivityLaunchMode launchMode) { string str; PwEntry pe = item.Entry; SprContext ctxNoEsc = new SprContext(pe, item.Database, SprCompileFlags.All); IOConnectionInfo ioc; if (!TryGetDatabaseIoc(item, out ioc)) { return(false); } var ob = GetBoolEx(pe, "SkipIfNotExists", ctxNoEsc); if (!ob.HasValue) // Backw. compat. { ob = GetBoolEx(pe, "Skip if not exists", ctxNoEsc); } if (ob.HasValue && ob.Value) { if (!CheckFileExsts(ioc)) { return(false); } } CompositeKey ck = new CompositeKey(); if (GetString(pe, PwDefs.PasswordField, ctxNoEsc, false, out str)) { ck.AddUserKey(new KcpPassword(str)); } if (GetString(pe, PwDefs.UserNameField, ctxNoEsc, false, out str)) { string strAbs = str; IOConnectionInfo iocKey = IOConnectionInfo.FromPath(strAbs); if (iocKey.IsLocalFile() && !UrlUtil.IsAbsolutePath(strAbs)) { //local relative paths not supported on Android return(false); } ob = GetBoolEx(pe, "SkipIfKeyFileNotExists", ctxNoEsc); if (ob.HasValue && ob.Value) { IOConnectionInfo iocKeyAbs = IOConnectionInfo.FromPath(strAbs); if (!CheckFileExsts(iocKeyAbs)) { return(false); } } try { ck.AddUserKey(new KcpKeyFile(strAbs)); } catch (InvalidOperationException) { Toast.MakeText(Application.Context, Resource.String.error_adding_keyfile, ToastLength.Long).Show(); return(false); } catch (Exception) { throw; } } else // Try getting key file from attachments { ProtectedBinary pBin = pe.Binaries.Get("KeyFile.bin"); if (pBin != null) { ck.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromPath( StrUtil.DataToDataUri(pBin.ReadData(), null)))); } } GetString(pe, "Focus", ctxNoEsc, true, out str); bool bRestoreFocus = str.Equals("Restore", StrUtil.CaseIgnoreCmp); PasswordActivity.Launch(activity, ioc, ck, launchMode, ! bRestoreFocus); App.Kp2a.RegisterChildDatabase(ioc); return(true); }
private void OnOpen(AutoExecItem item) { KeeAutoExecExt.AutoOpenEntry(this, item, true); }
private void OnAutoExecItemSelected(AutoExecItem autoExecItem) { KeeAutoExecExt.AutoOpenEntry(this, autoExecItem, true); }
private void OnAutoExecItemSelected(AutoExecItem autoExecItem) { KeeAutoExecExt.AutoOpenEntry(this, autoExecItem, true, new ActivityLaunchModeSimple()); }
private void OnEnable(AutoExecItem item) { KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, true); Save(item); }
private void OnEdit(AutoExecItem item) { EntryEditActivity.Launch(this, item.Entry, new NullTask()); }
private static List <AutoExecItem> GetAutoExecItems(PwDatabase pd) { List <AutoExecItem> l = new List <AutoExecItem>(); if (pd == null) { Debug.Assert(false); return(l); } if (!pd.IsOpen) { return(l); } PwGroup pgRoot = pd.RootGroup; if (pgRoot == null) { Debug.Assert(false); return(l); } List <PwEntry> lAutoEntries = new List <PwEntry>(); AddAutoExecEntries(lAutoEntries, pgRoot); long lPriStd = 0; foreach (PwEntry pe in lAutoEntries) { string str = pe.Strings.ReadSafe(PwDefs.UrlField); if (str.Length == 0) { continue; } AutoExecItem a = new AutoExecItem(pe, pd); l.Add(a); SprContext ctx = new SprContext(pe, pd, SprCompileFlags.All); if (pe.Expires && (pe.ExpiryTime <= DateTime.UtcNow)) { a.Enabled = false; } bool?ob = GetBoolEx(pe, "Enabled", ctx); if (ob.HasValue) { a.Enabled = ob.Value; } ob = GetBoolEx(pe, "Visible", ctx); if (ob.HasValue) { a.Visible = ob.Value; } long lItemPri = lPriStd; if (GetString(pe, "Priority", ctx, true, out str)) { long.TryParse(str, out lItemPri); } a.Priority = lItemPri; ++lPriStd; } l.Sort(KeeAutoExecExt.PrioritySort); return(l); }
private void OnOpen(AutoExecItem item) { KeeAutoExecExt.AutoOpenEntry(this, item, true, new ActivityLaunchModeSimple()); }