Smartcard RequestPinChangeAsync throws exception

Frederik 21 Reputation points
2022-01-12T13:48:07.203+00:00

Im following the example here:
https://video2.skills-academy.com/en-us/windows/uwp/security/smart-cards

To initiate a smart card pin change or reset.

I can successfully enumerate readers/cards etc. and also issue certificates.
The following code executes successfully:

SmartCardProvisioning provisioning = await SmartCardProvisioning.FromSmartCardAsync(card);  
var id = await provisioning.GetIdAsync();  
var name = await provisioning.GetNameAsync();  
var status = await card.GetStatusAsync();  

But

bool result = await provisioning.RequestPinChangeAsync();  

Throws COM exception

 System.Runtime.InteropServices.COMException: 'Elementet blev ikke fundet. (0x80070490)'  

Translates to "Element not found"

Stack trace:

	StackTrace	"   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)\r\n   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)\r\n   at ABI.Windows.Devices.SmartCards.ISmartCardProvisioningMethods.RequestPinChangeAsync(IObjectReference _obj)\r\n   at Windows.Devices.SmartCards.SmartCardProvisioning.RequestPinChangeAsync()\r\n   at Liga.LocalID.Providers.CardResetProvider.<ResetPin>d__4.MoveNext() in C:\\Users\\frederik\\source\\repos\\LigaID\\LigaLocalID\\Providers\\CardResetProvider.cs:line 64"	string  

I am building a packaged desktop app on dotnet framework 5, referencing Microsoft.WindowsAppSDK 1.0.0 and Microsoft.Windows.SDK.BuildTools 10.0.22000.196

I have requested the "Shared User Certificates" capability in the package.appxmanifest .

<Capabilities>  
    <rescap:Capability Name="runFullTrust" />  
    <uap:Capability Name="userAccountInformation"/>  
    <uap:Capability Name="sharedUserCertificates"/>  
  </Capabilities>  

and these are the dependencies:

  <Dependencies>  
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />  
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />  
  </Dependencies>  

Im developing in c#, Visual studio 2019 pro, on windows 10 build 19043.1415.

The smartcard is physical, GIDS/OpenSmartcard and works flawlessly with regular pkcs11 tools like pkcs11admin

So, short recap:
I am successfully enumerating smartcards and readers, issuing certificates to the cards, etc.
The problem is to get windows (the minidriver?) to display a pin change dialog.

Any help appreciated!

Kind regards
Frederik Borg

Universal Windows Platform (UWP)
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
748 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,731 Reputation points Microsoft Vendor
    2022-01-13T05:34:49.817+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Based on your description, you are trying to call this API in a .Net desktop app, not a UWP app. The SmartCardProvisioning.RequestPinChangeAsync API is limited to UWP apps. You could not call it in desktop app or even WinUI3 apps. And it's the same for other similar APIs like SmartCardProvisioning.RequestPinResetAsync(). If you want to call this API, please do it in UWP apps instead of desktop apps.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful