Beispiel #1
0
        private void AddAutoOpenEntryForDatabase(Database db)
        {
            PwGroup autoOpenGroup = null;
            var     rootGroup     = App.Kp2a.CurrentDb.KpDatabase.RootGroup;

            foreach (PwGroup pgSub in rootGroup.Groups)
            {
                if (pgSub.Name == "AutoOpen")
                {
                    autoOpenGroup = pgSub;
                    break;
                }
            }
            if (autoOpenGroup == null)
            {
                AddGroup addGroupTask = AddGroup.GetInstance(this, App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true);
                addGroupTask.Run();
                autoOpenGroup = addGroupTask.Group;
            }

            PwEntry newEntry = new PwEntry(true, true);

            newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc)));
            newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, db.Ioc)));
            var password = db.KpDatabase.MasterKey.GetUserKey <KcpPassword>();

            newEntry.Strings.Set(PwDefs.PasswordField, password == null ? new ProtectedString(true, "") : password.Password);

            var keyfile = db.KpDatabase.MasterKey.GetUserKey <KcpKeyFile>();

            if ((keyfile != null) && (keyfile.Ioc != null))
            {
                newEntry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, keyfile.Ioc)));
            }

            newEntry.Strings.Set(KeeAutoExecExt._ifDevice,
                                 new ProtectedString(false,
                                                     KeeAutoExecExt.BuildIfDevice(new Dictionary <string, bool>()
            {
                { KeeAutoExecExt.ThisDeviceId, true }
            })));

            var addTask = new AddEntry(this, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update()));

            ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask);

            pt.Run();
        }
Beispiel #2
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (AppTask.TryGetFromActivityResult(data, ref AppTask))
            {
                //make sure the app task is passed to the calling activity
                AppTask.SetActivityResult(this, KeePass.ExitNormal);
            }

            if ((GroupEditActivity.RequestCodeGroupEdit == requestCode) && (resultCode == Result.Ok))
            {
                String groupName         = data.Extras.GetString(GroupEditActivity.KeyName);
                int    groupIconId       = data.Extras.GetInt(GroupEditActivity.KeyIconId);
                PwUuid groupCustomIconId =
                    new PwUuid(MemUtil.HexStringToByteArray(data.Extras.GetString(GroupEditActivity.KeyCustomIconId)));
                String            strGroupUuid = data.Extras.GetString(GroupEditActivity.KeyGroupUuid);
                GroupBaseActivity act          = this;
                Handler           handler      = new Handler();
                RunnableOnFinish  task;
                if (strGroupUuid == null)
                {
                    task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, groupCustomIconId, Group, new RefreshTask(handler, this), false);
                }
                else
                {
                    PwUuid groupUuid = new PwUuid(MemUtil.HexStringToByteArray(strGroupUuid));
                    task = new EditGroup(this, App.Kp2a, groupName, (PwIcon)groupIconId, groupCustomIconId, App.Kp2a.GetDb().Groups[groupUuid],
                                         new RefreshTask(handler, this));
                }
                ProgressTask pt = new ProgressTask(App.Kp2a, act, task);
                pt.Run();
            }

            if (resultCode == KeePass.ExitCloseAfterTaskComplete)
            {
                AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete);
                Finish();
            }

            if (resultCode == KeePass.ExitReloadDb)
            {
                AppTask.SetActivityResult(this, KeePass.ExitReloadDb);
                Finish();
            }
        }
Beispiel #3
0
        public override void Run()
        {
            StatusLogger.UpdateMessage(UiStringKey.progress_create);
            Database db = _app.CreateNewDatabase(_makeCurrent);

            db.KpDatabase = new KeePassLib.PwDatabase();

            if (_key == null)
            {
                _key = new CompositeKey();                 //use a temporary key which should be changed after creation
            }

            db.KpDatabase.New(_ioc, _key, _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc));

            db.KpDatabase.KdfParameters = (new AesKdf()).GetDefaultParameters();
            db.KpDatabase.Name          = "Keepass2Android Password Database";
            //re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages:
            db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc);

            // Set Database state
            db.Root         = db.KpDatabase.RootGroup;
            db.SearchHelper = new SearchDbHelper(_app);

            // Add a couple default groups
            AddGroup internet = AddGroup.GetInstance(_ctx, _app, "Internet", 1, null, db.KpDatabase.RootGroup, null, true);

            internet.Run();
            AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true);

            email.Run();

            List <PwEntry>     addedEntries;
            AddTemplateEntries addTemplates = new AddTemplateEntries(_ctx, _app, null);

            addTemplates.AddTemplates(out addedEntries);

            // Commit changes
            SaveDb save = new SaveDb(_ctx, _app, db, OnFinishToRun, _dontSave);

            save.SetStatusLogger(StatusLogger);
            _onFinishToRun = null;
            save.Run();

            db.UpdateGlobals();
        }
Beispiel #4
0
 public AfterAdd(Activity activity, AddGroup addGroup, OnFinish finish) : base(activity, finish)
 {
     _addGroup = addGroup;
 }
 public AfterAdd(AddGroup addGroup, OnFinish finish) : base(finish)
 {
     _addGroup = addGroup;
 }
Beispiel #6
0
 public AfterAdd(AddGroup addGroup,OnFinish finish)
     : base(finish)
 {
     _addGroup = addGroup;
 }