示例#1
0
        private async Task LoadSettings()
        {
            YubiCryptOAuth2Token storedAccessToken     = SettingsHelper.LoadSetting <YubiCryptOAuth2Token>(Consts.SETTINGS_ACCESS_TOKEN_KEY);
            TFTokenData          storedTokenSecretData = SettingsHelper.LoadSetting <TFTokenData>(Consts.SETTINGS_TOKEN_SECRET_KEY);
            var localStoredFiles = await localStorageFolder.GetFilesAsync();

            if (storedAccessToken != null)
            {
                authenticationInfoText.Text = string.Format("Access token expires: {0}", storedAccessToken.Expires);
                DeleteTokenButton.IsEnabled = true;
            }
            else
            {
                authenticationInfoText.Text = "No access token.";
                DeleteTokenButton.IsEnabled = false;
            }

            if (storedTokenSecretData != null)
            {
                keyStorageInfoText.Text   = string.Format("Storing Secret Key for token with Serial# {0}.", storedTokenSecretData.SerialNumber);
                DeleteKeyButton.IsEnabled = true;
            }
            else
            {
                keyStorageInfoText.Text   = "No stored token information";
                DeleteKeyButton.IsEnabled = false;
            }

            DeleteLocalFilesButton.IsEnabled = false;
            LocalFileStorageInfo.Text        = string.Format("{0} decrypted file(s) stored locally.", localStoredFiles.Count);
            if (localStoredFiles.Count > 0)
            {
                DeleteLocalFilesButton.IsEnabled = true;
            }
        }
        private async Task <bool> TokenSecretFirstTimeSetup()
        {
            var noTokenMessage = new MessageDialog(this.resourceLoader.GetString("Message_NoTokenSecret"));
            await noTokenMessage.ShowAsync();

            var passphraseDialog = new RetrieveTokenSecretDialog();
            ContentDialogResult passphraseDialogResult = await passphraseDialog.ShowAsync();

            if (passphraseDialogResult == ContentDialogResult.Primary)
            {
                await ToggleProgressBar(true);

                var tokenStoredSecret = await client.GetTokenStoredSecret(passphraseDialog.TokenGeneratedOTP);

                TFTokenData tokenSecret = new TFTokenData();
                tokenSecret.SerialNumber = tokenStoredSecret.TokenSerialNumber;
                await Task.Run(() =>
                {
                    tokenSecret.SecretKey = engine.DecryptTokenSecret(tokenStoredSecret.TFKDEncryptedSecret, tokenStoredSecret.TFKDEncryptionSalt, passphraseDialog.Passphrase);
                });

                SettingsHelper.SaveSetting(Consts.SETTINGS_TOKEN_SECRET_KEY, tokenSecret);
                await ToggleProgressBar(false);

                return(true);
            }

            return(false);
        }