/// <summary> /// Click handler for the 'ChangeAdminKey' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ChangeAdminKey_Click(object sender, RoutedEventArgs e) { if (!rootPage.ValidateTPMSmartCard()) { rootPage.NotifyUser( "Use Scenario One to create a TPM virtual smart card.", NotifyType.ErrorMessage); return; } Button b = sender as Button; b.IsEnabled = false; try { IBuffer newadminkey = CryptographicBuffer.GenerateRandom( MainPage.ADMIN_KEY_LENGTH_IN_BYTES); SmartCard card = await rootPage.GetSmartCard(); SmartCardProvisioning provisioning = await SmartCardProvisioning.FromSmartCardAsync(card); rootPage.NotifyUser("Changing smart card admin key...", NotifyType.StatusMessage); using (SmartCardChallengeContext context = await provisioning.GetChallengeContextAsync()) { IBuffer response = ChallengeResponseAlgorithm.CalculateResponse( context.Challenge, rootPage.AdminKey); await context.ChangeAdministrativeKeyAsync(response, newadminkey); rootPage.AdminKey = newadminkey; } rootPage.NotifyUser( "Smart card change admin key operation completed.", NotifyType.StatusMessage); } catch (Exception ex) { rootPage.NotifyUser( "Changing smart card admin key operation failed " + "with exception: " + ex.ToString(), NotifyType.ErrorMessage); } finally { b.IsEnabled = true; } }
/// <summary> /// Click handler for the 'VerifyResponse' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void VerifyResponse_Click(object sender, RoutedEventArgs e) { if (!rootPage.ValidateTPMSmartCard()) { rootPage.NotifyUser( "Use Scenario One to create a TPM virtual smart card.", NotifyType.ErrorMessage); return; } Button b = sender as Button; b.IsEnabled = false; try { bool verifyResult = false; SmartCard card = await rootPage.GetSmartCard(); SmartCardProvisioning provisioning = await SmartCardProvisioning.FromSmartCardAsync(card); rootPage.NotifyUser("Verifying smart card response...", NotifyType.StatusMessage); using (SmartCardChallengeContext context = await provisioning.GetChallengeContextAsync()) { IBuffer response = ChallengeResponseAlgorithm.CalculateResponse( context.Challenge, rootPage.AdminKey); verifyResult = await context.VerifyResponseAsync(response); } rootPage.NotifyUser( "Smart card response verification completed. Result: " + verifyResult.ToString(), NotifyType.StatusMessage); } catch (Exception ex) { rootPage.NotifyUser( "Verifying smart card response operation failed " + "with exception: " + ex.ToString(), NotifyType.ErrorMessage); } finally { b.IsEnabled = true; } }