Esempio n. 1
0
        protected override void RefreshBTDeviceLists(object sender, EventArgs e)
        {
            // Backup user's already selected devices
            BluetoothDevice selected1 = (BluetoothDevice)cbxBTSelect1.SelectedItem;
            BluetoothDevice selected2 = (BluetoothDevice)cbxBTSelect2.SelectedItem;

            // Refresh combo box lists
            cbxBTSelect1.Items.Clear();
            cbxBTSelect2.Items.Clear();
            var inRange = getBTDevicesInRange();

            foreach (BluetoothDevice bt in inRange)
            {
                // Only add device to list if not in database
                if (AuthenticationSequence.Start(bt) == null)
                {
                    cbxBTSelect1.Items.Add(bt);
                    cbxBTSelect2.Items.Add(bt);
                    if (bt.Equals(selected1))
                    {
                        cbxBTSelect1.SelectedItem = selected1;
                    }
                    if (bt.Equals(selected2))
                    {
                        cbxBTSelect2.SelectedItem = selected2;
                    }
                }
            }
        }
Esempio n. 2
0
        private void btnConfirmBTDevices_Click(object sender, EventArgs e)
        {
            BluetoothDevice selectedBTDevice = (BluetoothDevice)listIdleBTDevices.SelectedItem;

            _currentAuthSequence = AuthenticationSequence.Start(selectedBTDevice);
            bool bluetoothRecognized = (_currentAuthSequence != null);

            if (!bluetoothRecognized)
            {
                // this is a new BT device
                _globalState = State.Initializing;
            }
            else if (_currentAuthSequence.User.PermissionLevel == User.PermissionLevels.NONE)
            {
                // user does not have door unlocking permission
                _globalState = State.AccessDenied;
            }
            else
            {
                // request second factor authentication
                _globalState             = State.SecondFactor;
                numTriesLeftSecondFactor = NUM_TRIES;
            }
            UpdateComponents();
        }
Esempio n. 3
0
        private void FormOptions_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Console.WriteLine("Form Start Key Pressed");
            //Console.WriteLine("Pressed: " + e.KeyChar);
            //Console.WriteLine("Shift: " + shift);
            //Console.WriteLine("New Card Entry: " + newCardEntry);

            RestartTimer();

            // Disallow unwanted mag stripe interference in other states
            if (!acceptMagStripeInput)
            {
                return;
            }

            // Check KeyPressed to see if it's the beginning of a new card entry
            if (e.KeyChar == ';' || (e.KeyChar == '%'))
            {
                newCardEntry = true;
            }

            if (newCardEntry)
            {
                // Stop adding to card input string when "Return" is entered
                if (e.KeyChar == '\r') //|| e.KeyChar == '\n')
                {
                    // Check for invalid read before anything else
                    if (cardInput.Contains(";E?") || cardInput.Contains("%E?") || cardInput.Contains("+E?"))
                    {
                        // Invalid read. Swipe again.
                        newCardEntry = false;
                        cardInput    = "";
                        Console.WriteLine("Invalid read. Swipe again.");
                        return;
                    }

                    if (_globalState == State.UserOptions_EditAuth)
                    {
                        // Don't allow duplicate cards in the database
                        AuthenticationSequence authSeq = AuthenticationSequence.Start(new Card(cardInput));
                        bool cardNotAlreadyInDatabase  = authSeq == null;
                        if (cardNotAlreadyInDatabase)
                        {
                            tbxCard.Text = cardInput;
                        }
                    }
                    newCardEntry = false;
                    // Reset cardInput to allow for a new card swipe to be registered
                    cardInput = "";
                    return;
                }
                else
                {
                    cardInput   += e.KeyChar;
                    newCardEntry = true;
                }
            }
        }
Esempio n. 4
0
        internal PasswordsV2Update(Func <bool, AuthenticationPrompt> knowsUserPassword)
        {
            // we cant use PersistenceSecurity, because it already works on new PasswordFunctions2 methods
            var authentication = new AuthenticationSequence(this.IsMasterPasswordValid, knowsUserPassword);

            this.isAuthenticated = authentication.AuthenticateIfRequired();
            if (!this.isAuthenticated)
            {
                const string MESSAGE = "Application was not able to upgrade your passwords to version 2, because your master password isn't valid.";
                throw new SecurityAccessDeniedException(MESSAGE);
            }

            this.CheckEmptyMasterPassword();
        }
Esempio n. 5
0
        protected override void RefreshBTDeviceLists(object sender, EventArgs e)
        {
            switch (_globalState)
            {
            case State.Initializing:
                // Backup user's already selected devices
                BluetoothDevice selected1 = (BluetoothDevice)cbxBTSelect1.SelectedItem;
                BluetoothDevice selected2 = (BluetoothDevice)cbxBTSelect2.SelectedItem;
                // Refresh combo box lists
                cbxBTSelect1.Items.Clear();
                cbxBTSelect2.Items.Clear();
                var inRange = getBTDevicesInRange();
                foreach (BluetoothDevice bt in inRange)
                {
                    // Only add device to list if not in database
                    if (AuthenticationSequence.Start(bt) == null)
                    {
                        cbxBTSelect1.Items.Add(bt);
                        cbxBTSelect2.Items.Add(bt);
                        if (bt.Equals(selected1))
                        {
                            cbxBTSelect1.SelectedItem = selected1;
                        }
                        if (bt.Equals(selected2))
                        {
                            cbxBTSelect2.SelectedItem = selected2;
                        }
                    }
                }
                break;

            case State.Idle:
                // Backup selected item to reselect after refresh:
                var backupSelectedBT = listIdleBTDevices.SelectedItem;
                listIdleBTDevices.Items.Clear();
                var inRangeAndRecognized = getBTDevicesInRangeAndRecognized();
                foreach (BluetoothDevice bt in inRangeAndRecognized)
                {
                    listIdleBTDevices.Items.Add(bt);
                }
                listIdleBTDevices.SelectedItem = backupSelectedBT;
                break;
            }
        }
Esempio n. 6
0
        private void FormUserManagement_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Console.WriteLine("Form Start Key Pressed");
            //Console.WriteLine("Pressed: " + e.KeyChar);
            //Console.WriteLine("Shift: " + shift);
            //Console.WriteLine("New Card Entry: " + newCardEntry);

            // Disallow unwanted mag stripe interference in other states
            if (!acceptMagStripeInput)
            {
                return;
            }

            // Check KeyPressed to see if it's the beginning of a new card entry
            if (e.KeyChar == ';' || (e.KeyChar == '%'))
            {
                newCardEntry = true;
            }

            if (newCardEntry)
            {
                // Stop adding to card input string when "Return" is entered
                if (e.KeyChar == '\r') //|| e.KeyChar == '\n')
                {
                    // Check for invalid read before anything else
                    if (cardInput.Contains(";E?") || cardInput.Contains("%E?") || cardInput.Contains("+E?"))
                    {
                        // Invalid read. Swipe again.
                        newCardEntry = false;
                        cardInput    = "";
                        Console.WriteLine("Invalid read. Swipe again.");
                        return;
                    }

                    // Don't allow duplicate cards in the database
                    AuthenticationSequence authSeq = AuthenticationSequence.Start(new Card(cardInput));
                    bool cardNotAlreadyInDatabase  = authSeq == null;
                    if (cardNotAlreadyInDatabase)
                    {
                        txtAddNewUserStatus.Visible = false;
                        tbxCard.Text = cardInput;
                    }
                    else
                    {
                        // Error: Two separate users cannot use the same card for authentication
                        txtAddNewUserStatus.Visible = true;
                        txtAddNewUserStatus.Text    = "Cannot add an authentication method which already exists in the database. Please try again.";
                        tbxCard.Text = "";
                        cardInput    = ""; // just in case
                        loseFocus();
                    }

                    Console.WriteLine(cardInput);

                    // Reset cardInput to allow for a new card swipe to be registered
                    newCardEntry = false;
                    cardInput    = "";
                    return;
                }
                else
                {
                    cardInput   += e.KeyChar;
                    newCardEntry = true;
                }
            }
        }
Esempio n. 7
0
        private void FormStart_KeyPress(object sender, KeyPressEventArgs e)
        {
            Console.WriteLine("Form Start Key Pressed");
            Console.WriteLine("Pressed: " + e.KeyChar);
            //Console.WriteLine("Shift: " + shift);
            //Console.WriteLine("New Card Entry: " + newCardEntry);

            if (_globalState == State.AccessDenied)
            {
                return;
            }
            RestartTimer();
            RestartAccessDeniedTimer(); //??

            // Disallow unwanted mag stripe interference in other states
            if (!acceptMagStripeInput)
            {
                return;
            }

            // Check KeyPressed to see if it's the beginning of a new card entry
            if (e.KeyChar == ';' || (e.KeyChar == '%'))
            {
                newCardEntry = true;
            }

            if (newCardEntry)
            {
                // Stop adding to card input string when "Return" is entered
                if (e.KeyChar == '\r' || e.KeyChar == '\n')
                {
                    // Check for invalid read before anything else
                    if (cardInput.Contains(";E?") || cardInput.Contains("%E?") || cardInput.Contains("+E?"))
                    {
                        // Invalid read. Swipe again.
                        newCardEntry = false;
                        cardInput    = "";
                        Console.WriteLine("Invalid read. Swipe again.");
                        return;
                    }

                    Console.WriteLine(cardInput);

                    Card card = new Card(cardInput);
                    if (_globalState == State.SecondFactor && _currentAuthSequence.NextAuthenticationMethod is Card)
                    {
                        tbxSecFactorPinOrCard.Text = cardInput;
                        btnOptionsSave_Click(sender, EventArgs.Empty);
                    }
                    else
                    {
                        // Check database to see if this is a new card entry or a recognized card associated with a user.
                        _currentAuthSequence = AuthenticationSequence.Start(card);
                        bool cardRecognized = (_currentAuthSequence != null);

                        if (!cardRecognized)
                        {
                            // this is a new card
                            tbxCard.Text = cardInput;
                            if (_globalState != State.Initializing)
                            {
                                _globalState = State.Initializing;
                                UpdateComponents();
                            }
                            else
                            {
                                txtAddNewUserStatus.Visible = false;
                            }
                        }
                        else
                        {
                            // this card is already in the database
                            if (_globalState == State.Initializing)
                            {
                                // Error: Two separate users cannot use the same card for authentication
                                txtAddNewUserStatus.Visible = true;
                                txtAddNewUserStatus.Text    = "Cannot add an authentication method which already exists in the database. Please try again.";
                                tbxCard.Text = "";
                                cardInput    = ""; // just in case
                                loseFocus();
                                // TODO: Set Validation of some kind telling them to swipe a different card
                            }
                            else if (_currentAuthSequence.User.PermissionLevel == User.PermissionLevels.NONE)
                            {
                                // user does not have door unlocking permission
                                _globalState = State.AccessDenied;
                                UpdateComponents();
                            }
                            else
                            {
                                // request second factor authentication
                                numTriesLeftSecondFactor = NUM_TRIES; // Give the user NUM_TRIES tries before denying access
                                _globalState             = State.SecondFactor;
                                UpdateComponents();
                            }
                        }
                    }


                    // Reset cardInput to allow for a new card swipe to be registered
                    cardInput = "";
                }
                else
                {
                    cardInput   += e.KeyChar;
                    newCardEntry = true;
                }
            }
        }