Beispiel #1
0
 public KeyCreation(KeeChallengeProv parent)
 {
     InitializeComponent();
     Secret   = null;
     Icon     = Icon.FromHandle(Properties.Resources.yubikey.GetHicon());
     m_parent = parent;
 }
Beispiel #2
0
        public override void Terminate()
        {
            if (m_host != null)
            {
                m_host.KeyProviderPool.Remove(m_prov);
                if (m_YubiSlot1.Checked)
                {
                    Properties.Settings.Default.YubikeySlot = 0;
                }
                else if (m_YubiSlot2.Checked)
                {
                    Properties.Settings.Default.YubikeySlot = 1;
                }
                else if (m_YubiSlot3.Checked)
                {
                    Properties.Settings.Default.YubikeySlot = 2;
                }


                Properties.Settings.Default.Save();

                ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
                tsMenu.Remove(m_MenuItem);
                tsMenu.Remove(m_Separator);

                m_prov = null;
                m_host = null;
            }
        }
Beispiel #3
0
        public RecoveryMode(KeeChallengeProv parent)
        {
            InitializeComponent();

            Icon     = Icon.FromHandle(Properties.Resources.yubikey.GetHicon());
            m_parent = parent;
        }
Beispiel #4
0
        public KeyEntry(KeeChallengeProv parent, byte[] challenge)
        {
            InitializeComponent();
            m_parent  = parent;
            success   = false;
            Response  = new byte[YubiWrapper.yubiRespLen];
            Challenge = challenge;
            yubiSlot  = parent.YubikeySlot;

            Icon = Icon.FromHandle(Properties.Resources.yubikey.GetHicon());
        }
        public override bool Initialize(IPluginHost host)
        {
            if (m_host != null)
            {
                Terminate();
            }

            if (host == null)
            {
                return(false);
            }

            m_host = host;

            int      slot     = Properties.Settings.Default.YubikeySlot - 1; //Important: for readability, the slot settings are not zero based. We must account for this during read/save
            YubiSlot yubiSlot = YubiSlot.SLOT2;

            if (Enum.IsDefined(typeof(YubiSlot), slot))
            {
                yubiSlot = (YubiSlot)slot;
            }

            ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;

            m_Separator = new ToolStripSeparator();
            tsMenu.Add(m_Separator);

            m_YubiSlot1              = new ToolStripMenuItem();
            m_YubiSlot1.Name         = "Slot1";
            m_YubiSlot1.Text         = "Slot 1";
            m_YubiSlot1.CheckOnClick = true;
            m_YubiSlot1.Checked      = yubiSlot == YubiSlot.SLOT1;
            m_YubiSlot1.Click       += (s, e) => { m_YubiSlot2.Checked = false; m_prov.YubikeySlot = YubiSlot.SLOT1; };

            m_YubiSlot2              = new ToolStripMenuItem();
            m_YubiSlot2.Name         = "Slot2";
            m_YubiSlot2.Text         = "Slot 2";
            m_YubiSlot2.CheckOnClick = true;
            m_YubiSlot2.Checked      = yubiSlot == YubiSlot.SLOT2;
            m_YubiSlot2.Click       += (s, e) => { m_YubiSlot1.Checked = false; m_prov.YubikeySlot = YubiSlot.SLOT2; };

            m_MenuItem      = new ToolStripMenuItem();
            m_MenuItem.Text = "KeeChallenge Settings";
            m_MenuItem.DropDownItems.AddRange(new ToolStripItem[] { m_YubiSlot1, m_YubiSlot2 });

            tsMenu.Add(m_MenuItem);

            m_prov             = new KeeChallengeProv();
            m_prov.YubikeySlot = yubiSlot;
            m_host.KeyProviderPool.Add(m_prov);

            return(true);
        }
        public KeyEntrySelection(KeeChallengeProv parent)
        {
            InitializeComponent();

            Icon = Icon.FromHandle(Properties.Resources.yubikey.GetHicon());
        }
Beispiel #7
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            _keepPasswordInOnResume = true;
            Kp2aLog.Log("PasswordActivity.OnActivityResult "+resultCode+"/"+requestCode);

            AppTask.TryGetFromActivityResult(data, ref AppTask);

            //NOTE: original code from k eepassdroid used switch ((Android.App.Result)requestCode) { (but doesn't work here, although k eepassdroid works)
            switch(resultCode) {

                case KeePass.ExitNormal: // Returned to this screen using the Back key
                    if (PreferenceManager.GetDefaultSharedPreferences(this)
                                         .GetBoolean(GetString(Resource.String.LockWhenNavigateBack_key), false))
                    {
                        App.Kp2a.LockDatabase();
                    }
                    //by leaving the app with the back button, the user probably wants to cancel the task
                    //The activity might be resumed (through Android's recent tasks list), then use a NullTask:
                    AppTask = new NullTask();
                    Finish();
                    break;
                case KeePass.ExitLock:
                    // The database has already been locked, and the quick unlock screen will be shown if appropriate

                    _rememberKeyfile = _prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default)); //update value
                    if ((KeyProviderType == KeyProviders.KeyFile) && (_rememberKeyfile))
                    {
                        //check if the keyfile was changed (by importing to internal directory)
                        var newKeyFile = GetKeyFile(_ioConnection.Path);
                        if (newKeyFile != _keyFileOrProvider)
                        {
                            _keyFileOrProvider = newKeyFile;
                            UpdateKeyfileIocView();
                        }
                    }
                    break;
                case KeePass.ExitCloseAfterTaskComplete:
                    // Do not lock the database
                    SetResult(KeePass.ExitCloseAfterTaskComplete);
                    Finish();
                    break;
                case KeePass.ExitClose:
                    SetResult(KeePass.ExitClose);
                    Finish();
                    break;
                case KeePass.ExitReloadDb:

                    if (App.Kp2a.GetDb().Loaded)
                    {
                        //remember the composite key for reloading:
                        var compositeKey = App.Kp2a.GetDb().KpDatabase.MasterKey;

                        //lock the database:
                        App.Kp2a.LockDatabase(false);

                        //reload the database (without most other stuff performed in PerformLoadDatabase.
                        // We're assuming that the db file (and if appropriate also the key file) are still available
                        // and there's no need to re-init the file storage. if it is, loading will fail and the user has
                        // to retry with typing the full password, but that's intended to avoid showing the password to a
                        // a potentially unauthorized user (feature request https://keepass2android.codeplex.com/workitem/274)
                        Handler handler = new Handler();
                        OnFinish onFinish = new AfterLoad(handler, this);
                        _performingLoad = true;
                        LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish);
                        _loadDbTask = null; // prevent accidental re-use
                        new ProgressTask(App.Kp2a, this, task).Run();
                    }

                    break;
                case Result.Ok:
                    if (requestCode == RequestCodeSelectKeyfile)
                    {
                        IOConnectionInfo ioc = new IOConnectionInfo();
                        SetIoConnectionFromIntent(ioc, data);
                        _keyFileOrProvider = IOConnectionInfo.SerializeToString(ioc);
                        UpdateKeyfileIocView();
                    }
                    break;
                case (Result)FileStorageResults.FileUsagePrepared:
                    if (requestCode == RequestCodePrepareDbFile)
                    {
                        if (KeyProviderType == KeyProviders.KeyFile)
                        {
                            var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider);

                            App.Kp2a.GetFileStorage(iocKeyfile)
                                .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile,
                                         RequestCodePrepareKeyFile, false);
                        }
                        else
                            PerformLoadDatabase();
                    }
                    if (requestCode == RequestCodePrepareKeyFile)
                    {
                        PerformLoadDatabase();
                    }
                    if (requestCode == RequestCodePrepareOtpAuxFile)
                    {
                        GetAuxFileLoader().LoadAuxFile(true);
                    }
                    break;
            }
            if (requestCode == RequestCodeSelectAuxFile && resultCode == Result.Ok)
            {
                IOConnectionInfo auxFileIoc = new IOConnectionInfo();
                SetIoConnectionFromIntent(auxFileIoc, data);

                PreferenceManager.GetDefaultSharedPreferences(this).Edit()
                                 .PutString("KP2A.PasswordAct.AuxFileIoc" + IOConnectionInfo.SerializeToString(_ioConnection),
                                            IOConnectionInfo.SerializeToString(auxFileIoc))
                                 .Apply();

                GetAuxFileLoader().LoadAuxFile(false);
            }
            if (requestCode == RequestCodeChallengeYubikey && resultCode == Result.Ok)
            {
                try
                {
                    _challengeProv = new KeeChallengeProv();
                    byte[] challengeResponse = data.GetByteArrayExtra("response");
                    _challengeSecret = _challengeProv.GetSecret(_chalInfo, challengeResponse);
                    Array.Clear(challengeResponse, 0, challengeResponse.Length);
                }
                catch (Exception e)
                {
                    Kp2aLog.Log(e.ToString());
                    Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show();
                    return;
                }

                UpdateOkButtonState();
                FindViewById(Resource.Id.otpInitView).Visibility = ViewStates.Gone;

                if (_challengeSecret != null)
                {
                    new LoadingDialog<object, object, object>(this, true,
                        //doInBackground
                    delegate
                    {
                        //save aux file
                        try
                        {
                            ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret);
                            IFileStorage fileStorage = App.Kp2a.GetOtpAuxFileStorage(_ioConnection);
                            IOConnectionInfo iocAux = fileStorage.GetFilePath(fileStorage.GetParentPath(_ioConnection),
                                fileStorage.GetFilenameWithoutPathAndExt(_ioConnection) + ".xml");
                            if (!temp.Save(iocAux))
                            {
                                Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show();
                                return false;
                            }

                        }
                        catch (Exception e)
                        {
                            Kp2aLog.Log(e.ToString());
                        }
                        return null;
                    }
                    , delegate
                    {

                    }).Execute();

                }
                else
                {
                    Toast.MakeText(this, Resource.String.bad_resp, ToastLength.Long).Show();
                    return;
                }
            }
        }