Exemplo n.º 1
0
        private async void DeleteServiceButton_Click(object sender, RoutedEventArgs e)
        {
            var result = await DialogHost.Show(new ConfirmDialog(), "root");

            if (result == null)
            {
                return;
            }

            try
            {
                if ((bool)result)
                {
                    var service = (Service)((Button)e.Source).DataContext;
                    await UserData.ApiClient.ApiEcccredentialsDeleteAsync(service.Id);

                    Services.Remove(service);
                }
            }
            catch (ApiException <ProblemDetails> exc)
            {
                foreach (var error in ApiErrorsBuilder.GetErrorList(exc.Result.Errors))
                {
                    Notifier.ShowError(error);
                }
            }
            catch (Exception)
            {
                Notifier.ShowError("Unknown error");
            }
        }
Exemplo n.º 2
0
        private async void EditServiceButton_Click(object sender, RoutedEventArgs e)
        {
            var service = (Service)((Button)e.Source).DataContext;
            var dialog  = new EditServiceDialog(service, Notifier);
            var result  = await DialogHost.Show(dialog, "root");

            if (result == null)
            {
                return;
            }

            try
            {
                if ((bool)result)
                {
                    var eccService     = new EccKeyServiceProvider();
                    var ServiceKeyPair = eccService.CreateNew_secp256r1_ECKeyPair();

                    var userKeyPair      = UserData.eccKeyPairs[0];
                    var masterKeyService = new KeyDerivationServiceProvider();
                    var crypto           = new SymmetricCryptographyServiceProvider();

                    var derivedKey = eccService.EcdhDervieKey(
                        new EccKeyPairBlob(userKeyPair.PublicKey.Curve, userKeyPair.PublicKey.PublicKey, null),
                        ServiceKeyPair,
                        HashAlgorithmName.SHA256);

                    var masterKey = masterKeyService.Pbkdf2Sha256DeriveKeyFromPassword(derivedKey, 16, 16);

                    var encrypted = crypto.Aes128GcmEncrypt(masterKey.MasterKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(service)));

                    var putModel = new EccCredentialPutModel()
                    {
                        EccDerivationBlob = new EccDerivationBlobModel()
                        {
                            Curve     = ServiceKeyPair.Curve,
                            PublicKey = ServiceKeyPair.PublicKey
                        },
                        EccKeyPairId            = userKeyPair.Id,
                        SymmetricCiphertextBlob = new SymmetricCiphertextBlobModel()
                        {
                            AuthenticationTag     = encrypted.AuthenticationTag,
                            CipherDescription     = encrypted.CipherDescription,
                            Ciphertext            = encrypted.Cipthertext,
                            InitializationVector  = encrypted.InitializationVector,
                            DerivationDescription = masterKey.DerivationDescription,
                            DerivationSalt        = masterKey.DerivationSalt
                        },
                    };

                    await UserData.ApiClient.ApiEcccredentialsPutAsync(service.Id, putModel);
                }
            }
            catch (ApiException <ProblemDetails> exc)
            {
                foreach (var error in ApiErrorsBuilder.GetErrorList(exc.Result.Errors))
                {
                    Notifier.ShowError(error);
                }
            }
            catch (Exception)
            {
                Notifier.ShowError("Unknown error");
            }
        }
Exemplo n.º 3
0
        private async void SaveChangesButton_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(OldPasswordBox.Password) ||
                String.IsNullOrEmpty(NewPasswordBox.Password) ||
                String.IsNullOrEmpty(ConfirmNewPasswordBox.Password))
            {
                Notifier.ShowError("Fields can not be empty!");
                return;
            }

            var keyPairs = new List <EccKeyPairModel>();

            foreach (var keyPair in UserData.eccKeyPairs)
            {
                var masterKeyService    = new KeyDerivationServiceProvider();
                var decryptionMasterKey = masterKeyService.DeriveKeyFromBlob(UserData.BytePassword, new KeyDerivationBlob(
                                                                                 keyPair.EncryptedPrivateKey.DerivationDescription,
                                                                                 keyPair.EncryptedPrivateKey.DerivationSalt,
                                                                                 null
                                                                                 ));

                var crypto = new SymmetricCryptographyServiceProvider();

                var privateKeyDecrypted = crypto.DecryptFromSymmetricCipthertextBlob(decryptionMasterKey.MasterKey, new SymmetricCipthertextBlob
                                                                                     (
                                                                                         keyPair.EncryptedPrivateKey.CipherDescription,
                                                                                         keyPair.EncryptedPrivateKey.InitializationVector,
                                                                                         keyPair.EncryptedPrivateKey.Ciphertext,
                                                                                         keyPair.EncryptedPrivateKey.AuthenticationTag
                                                                                     )
                                                                                     );

                var encryptionMasterKey = masterKeyService.Pbkdf2Sha256DeriveKeyFromPassword(Encoding.UTF8.GetBytes(NewPasswordBox.Password), 16, 16);
                var encryptedPrivateKey = crypto.Aes128GcmEncrypt(encryptionMasterKey.MasterKey, privateKeyDecrypted);

                keyPairs.Add(new EccKeyPairModel()
                {
                    Id                  = keyPair.Id,
                    PublicKey           = keyPair.PublicKey,
                    EncryptedPrivateKey = new EccEncryptedPrivateKeyModel()
                    {
                        Curve                 = keyPair.EncryptedPrivateKey.Curve,
                        AuthenticationTag     = encryptedPrivateKey.AuthenticationTag,
                        CipherDescription     = encryptedPrivateKey.CipherDescription,
                        Ciphertext            = encryptedPrivateKey.Cipthertext,
                        InitializationVector  = encryptedPrivateKey.InitializationVector,
                        DerivationDescription = encryptionMasterKey.DerivationDescription,
                        DerivationSalt        = encryptionMasterKey.DerivationSalt
                    }
                });
            }

            try
            {
                PasswordHashingServiceProvider phsp = new PasswordHashingServiceProvider();

                await UserData.ApiClient.ApiUsersChangePasswordAsync(new Core.ApiClient.UserChangePasswordModel()
                {
                    CurrentPassword = await phsp.Client_ComputePasswordForLogin(Encoding.UTF8.GetBytes(UserData.UserName), Encoding.UTF8.GetBytes(OldPasswordBox.Password)),
                    Password        = await phsp.Client_ComputePasswordForLogin(Encoding.UTF8.GetBytes(UserData.UserName), Encoding.UTF8.GetBytes(NewPasswordBox.Password)),
                    PasswordRepeat  = await phsp.Client_ComputePasswordForLogin(Encoding.UTF8.GetBytes(UserData.UserName), Encoding.UTF8.GetBytes(ConfirmNewPasswordBox.Password)),
                    EccKeyPairs     = keyPairs
                });

                WindowManager.MainWindow.Logout();
                var dialogResult = await DialogHost.Show(new MessageDialog("Password changed successfully!\nYou can login now."), "login");
            }
            catch (ApiException <ProblemDetails> exc)
            {
                foreach (var error in ApiErrorsBuilder.GetErrorList(exc.Result.Errors))
                {
                    Notifier.ShowError(error);
                }
            }
            catch (Exception)
            {
                Notifier.ShowError("Unknown error");
            }
        }