Skip to content

Commit

Permalink
Merge PR #234
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Oct 23, 2024
2 parents d1c6459 + 4b5a325 commit 7d495b4
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 180 deletions.
4 changes: 2 additions & 2 deletions examples/cred_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def request_uv(self, permissions, rd_id):
sys.exit(1)

# Prefer UV token if supported
if client.info.options.get("pinUvAuthToken") or client.info.options.get("uv"):
if client.info.options.get("uv") or client.info.options.get("bioEnroll"):
uv = "preferred"
print("Authenticator supports UV token")
print("Authenticator is configured for User Verification")


server = Fido2Server({"id": "example.com", "name": "Example RP"})
Expand Down
2 changes: 1 addition & 1 deletion examples/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def request_uv(self, permissions, rd_id):
client = Fido2Client(dev, "https://example.com", user_interaction=CliInteraction())

# Prefer UV if supported and configured
if client.info.options.get("uv") or client.info.options.get("pinUvAuthToken"):
if client.info.options.get("uv") or client.info.options.get("bioEnroll"):
uv = "preferred"
print("Authenticator supports User Verification")

Expand Down
4 changes: 2 additions & 2 deletions examples/large_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def request_uv(self, permissions, rd_id):
sys.exit(1)

# Prefer UV token if supported
if client.info.options.get("pinUvAuthToken") or client.info.options.get("uv"):
if client.info.options.get("uv") or client.info.options.get("bioEnroll"):
uv = "preferred"
print("Authenticator supports UV token")
print("Authenticator is configured for User Verification")


server = Fido2Server({"id": "example.com", "name": "Example RP"})
Expand Down
23 changes: 20 additions & 3 deletions examples/prf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from fido2.hid import CtapHidDevice
from fido2.server import Fido2Server
from fido2.client import Fido2Client, WindowsClient, UserInteraction
from fido2.utils import websafe_encode
from getpass import getpass
import ctypes
import sys
Expand Down Expand Up @@ -119,6 +120,10 @@ def request_uv(self, permissions, rd_id):
credential = result.attestation_object.auth_data.credential_data
print("New credential created, with the PRF extension.")

# If created with UV, keep using UV
if result.attestation_object.auth_data.is_user_verified():
uv = "required"

# Prepare parameters for getAssertion
allow_list = [{"type": "public-key", "id": credential.credential_id}]

Expand All @@ -144,18 +149,30 @@ def request_uv(self, permissions, rd_id):
output1 = result.extension_results["prf"]["results"]["first"]
print("Authenticated, secret:", output1.hex())

# Authenticate again, using two salts to generate two secrets:
# Authenticate again, using two salts to generate two secrets.

# This time we will use evalByCredential, which can be used if there are multiple
# credentials which use different salts. Here it is not needed, but provided for
# completeness of the example.

# Generate a second salt for PRF:
salt2 = os.urandom(32)
print("Authenticate with second salt:", salt2.hex())

# The first salt is reused, which should result in the same secret.

result = client.get_assertion(
{
**request_options["publicKey"],
"extensions": {"prf": {"eval": {"first": salt, "second": salt2}}},
"extensions": {
"prf": {
"evalByCredential": {
websafe_encode(credential.credential_id): {
"first": salt,
"second": salt2,
}
}
}
},
}
)

Expand Down
4 changes: 2 additions & 2 deletions examples/resident_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def request_uv(self, permissions, rd_id):
sys.exit(1)

# Prefer UV if supported and configured
if client.info.options.get("uv") or client.info.options.get("pinUvAuthToken"):
if client.info.options.get("uv") or client.info.options.get("bioEnroll"):
uv = "preferred"
print("Authenticator supports User Verification")
print("Authenticator is configured for User Verification")

server = Fido2Server({"id": "example.com", "name": "Example RP"}, attestation="direct")

Expand Down
Loading

0 comments on commit 7d495b4

Please sign in to comment.