Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to load tokens when there are unrecognized ones #33

Closed
dalmohub opened this issue Oct 14, 2022 · 3 comments
Closed

Fails to load tokens when there are unrecognized ones #33

dalmohub opened this issue Oct 14, 2022 · 3 comments

Comments

@dalmohub
Copy link

After configuring Windows Hello for business, a certificate was created in my PC which is somehow identified as a token by Bit4Id (PKCS#11 library).

image

Since then I'm unable to access my actual PKCS#11 USB Token because Pkcs11X509Store.Slots throws an exception due to the bogus Windows Hello token. The error happens in Pkcs11Token.GetTokenContext when calling Slot.GetTokenInfo() which throws a Pkcs11Exception exception => CKR_TOKEN_NOT_RECOGNIZED.

The error handling below allows "good" tokens to be loaded regardless of the presence of "invalid" ones.

private List<Pkcs11Slot> GetSlots()
{
	var slots = new List<Pkcs11Slot>();

	foreach (ISlot slot in _storeContext.Pkcs11Library.GetSlotList(SlotsType.WithTokenPresent))
	{
		try
		{
			var pkcs11Slot = new Pkcs11Slot(slot, _storeContext);
			slots.Add(pkcs11Slot);
		}
		catch (Pkcs11Exception ex)
		{
			if (ex.RV != CKR.CKR_TOKEN_NOT_RECOGNIZED && ex.RV != CKR.CKR_TOKEN_NOT_PRESENT)
			{
				throw;
			}
		}
	}

	return slots;
}
@lucaquaglio
Copy link

Up

@lucaquaglio
Copy link

lucaquaglio commented Sep 25, 2023

Created PR for the issue #35

jariq added a commit that referenced this issue Apr 20, 2024
@jariq
Copy link
Member

jariq commented Apr 20, 2024

@dalmohub thanks for reporting. Fix will be included in Pkcs11Interop.X509Store 0.5.0.

@jariq jariq closed this as completed Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants