Skip to content

Commit

Permalink
Support NFC in sign_arkg
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Nov 5, 2024
1 parent cad07d1 commit 3f9c1e9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/sign_arkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

try:
from fido2.pcsc import CtapPcscDevice
from smartcard.Exceptions import CardConnectionException
except ImportError:
CtapPcscDevice = None

Expand Down Expand Up @@ -70,6 +71,7 @@ def request_uv(self, permissions, rd_id):

uv = "discouraged"
rk = "discouraged"
pcsc = False

if WindowsClient.is_available() and not ctypes.windll.shell32.IsUserAnAdmin():
# Use the Windows WebAuthn API if available, and we're not running as admin
Expand All @@ -83,6 +85,8 @@ def request_uv(self, permissions, rd_id):
user_interaction=CliInteraction(),
)
if "sign" in client.info.extensions:
if isinstance(dev, CtapPcscDevice):
pcsc = True
break
else:
print("No Authenticator with the sign extension found!")
Expand Down Expand Up @@ -153,6 +157,32 @@ def request_uv(self, permissions, rd_id):
# Prepare parameters for getAssertion
request_options, state = server.authenticate_begin(credentials, user_verification=uv)


# NFC devices need to be removed and replaced to again trigger UV
if pcsc:
print("Remove the Authenticator from the NFC reader...")
while True:
try:
dev.get_atr()
except CardConnectionException:
dev.close()
break

print("Now place the Authenticator back on the reader...")
while True:
for dev in CtapPcscDevice.list_devices():
client = Fido2Client(
dev,
"https://example.com",
user_interaction=CliInteraction(),
)
if "sign" in client.info.extensions:
break
else:
continue
break


# Authenticate the credential
result = client.get_assertion(
{
Expand Down

0 comments on commit 3f9c1e9

Please sign in to comment.