private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            RegisterOutput ro           = GetSelectedValuesFromGUIRegister();
            bool           correctInput = ro.IsInputCorrect;

            if (correctInput)
            {
                User newUser = UsersManagement.AddUser(ro.Email, ro.Password);
                users.Add(newUser);

                //refresh all listboxes to show also newly added user
                RecipentsListBox.ItemsSource           = null;
                RecipentsListBoxDecryption.ItemsSource = null;
                RecipentsListViewRegister.ItemsSource  = null;

                RecipentsListBox.ItemsSource           = users;
                RecipentsListBoxDecryption.ItemsSource = users;
                RecipentsListViewRegister.ItemsSource  = users;

                resultTextBlockRegister.Text = "Zostałeś zarejestrowany, dziękujemy!";
            }
            else
            {
                MessageBoxResult result =
                    MessageBox.Show(ro.ErrorMessage,
                                    "Błędne dane wejściowe", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private void PrepareAppUsers()
        {
            users = UsersManagement.GetUsersListFromFile();

            //set listbox to display all users (as potential recipents of encrypted data)
            RecipentsListBox.ItemsSource           = users;
            RecipentsListBoxDecryption.ItemsSource = users;
            RecipentsListViewRegister.ItemsSource  = users;
        }
        public static RegisterOutput ParseRegisterValues(RegisterInput ri)
        {
            bool   readingAllOK = true;
            string errorMsg     = "";

            //retrieve email and password
            string email = ri.Email;

            if (string.IsNullOrEmpty(email))
            {
                readingAllOK = false;
                errorMsg    += "Błędny email.\n";
            }
            else
            {
                try
                {
                    var addr = new System.Net.Mail.MailAddress(email);
                    readingAllOK = (addr.Address == email);
                }
                catch
                {
                    readingAllOK = false;
                    errorMsg    += "Błędny email.\n";
                }
            }


            string password = ri.Password;

            if (!UsersManagement.PasswordCorrect(password))
            {
                readingAllOK = false;
                errorMsg    += "Błędne hasło. \n" +
                               "Ograniczenia hasła: Minimalna długość osiem znaków; \n" +
                               "co najmniej: jedna cyfra, jedna litera, jeden znak specjalny\n";
            }

            RegisterOutput ro = new RegisterOutput(readingAllOK,
                                                   email, password, errorMsg);

            return(ro);
        }
Example #4
0
        private byte[] ManageRecipent(string obtainedPassword)
        {
            //recipents are kept in a dictionary as
            //<recipentEmail, encryptedUserSessionKey> pairs

            //to decrypt the file we need a session key
            //we need to find selectedUser- the user that current user of the app claims to be-
            //get their encryptedUserSessionKey
            //and decrypt the key using user's private key

            //todo maybe set to some noise, so that if foreach doesn't find anything, the decoding will work and produce noise-file
            string encryptedSessionKeyString = "err";
            bool   userIsAuthorizedToDecrypt = false;

            foreach (KeyValuePair <string, string> emailKey in RecipentsEmailSessionKey)
            {
                if (emailKey.Key.Equals(DecryptionOutput.Recipent.Email))
                {
                    encryptedSessionKeyString = emailKey.Value;
                    userIsAuthorizedToDecrypt = true;
                    break;
                }
            }

            //if selected user is not on recipents list- they have no right to decrypt file
            //so generate random session key
            if (!userIsAuthorizedToDecrypt)
            {
                Console.WriteLine("user can't decode that file! generating random session key");
                return(null);
            }

            //decrypt session key using user's private key
            string userPrivateKeyString =
                UsersManagement.GetUserPrivateKey(DecryptionOutput.Recipent.Email, obtainedPassword);

            byte[] decryptedSessionKeyBytes =
                EncryptionHelper.DecryptSessionKeyFromString(encryptedSessionKeyString, userPrivateKeyString);
            return(decryptedSessionKeyBytes);
        }