Skip to content

Commit

Permalink
Fix typos and example encoding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Oct 25, 2024
1 parent 4c0b217 commit d443f56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions examples/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from fido2.hid import CtapHidDevice
from fido2.server import Fido2Server
from fido2.client import Fido2Client, WindowsClient, UserInteraction
from fido2.utils import sha256, websafe_encode
from fido2.utils import sha256, websafe_encode, websafe_decode
from fido2.cose import CoseKey, ES256
from getpass import getpass
import ctypes
Expand Down Expand Up @@ -128,14 +128,16 @@ def request_uv(self, permissions, rd_id):
sys.exit(1)
print("New credential created, with the sign extension.")

pk = CoseKey.parse(cbor.decode(sign_key["publicKey"])) # COSE key in bytes
pk = CoseKey.parse(
cbor.decode(websafe_decode(sign_key["publicKey"]))
) # COSE key in bytes
kh = sign_key["keyHandle"] # key handle in bytes
signature = sign_result.get("signature")
print("public key", pk)
print("keyHandle", kh.hex())
print("keyHandle", kh)

print("Test verify signature", signature.hex())
pk.verify(message, signature)
print("Test verify signature", signature)
pk.verify(message, websafe_decode(signature))
print("Signature verified!")

message = b"New message"
Expand Down Expand Up @@ -168,7 +170,7 @@ def request_uv(self, permissions, rd_id):
print("GET sign result", sign_result)

signature = sign_result.get("signature")
print("Test verify signature", signature)

print("Test verify signature", signature.hex())
pk.verify(message, signature)
pk.verify(message, websafe_decode(signature))
print("Signature verified!")
14 changes: 8 additions & 6 deletions examples/sign_arkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from fido2.hid import CtapHidDevice
from fido2.server import Fido2Server
from fido2.client import Fido2Client, WindowsClient, UserInteraction
from fido2.utils import sha256, websafe_encode
from fido2.utils import sha256, websafe_encode, websafe_decode
from fido2.cose import CoseKey
from fido2.arkg import ARKG_P256ADD_ECDH
from getpass import getpass
Expand Down Expand Up @@ -125,10 +125,12 @@ def request_uv(self, permissions, rd_id):
sys.exit(1)

# Extension output contains master public key and keyHandle
pk = CoseKey.parse(cbor.decode(sign_key["publicKey"])) # COSE key in bytes
pk = CoseKey.parse(
cbor.decode(websafe_decode(sign_key["publicKey"]))
) # COSE key in bytes
kh = sign_key["keyHandle"] # key handle in bytes
print("public key", pk)
print("keyHandle from Authenticator", cbor.decode(kh))
print("keyHandle from Authenticator", cbor.decode(websafe_decode(kh)))

# Master public key contains blinding and KEM keys
# ARKG derive_public_key uses these
Expand All @@ -142,7 +144,7 @@ def request_uv(self, permissions, rd_id):
print("Derived public key", pk2)
ref = pk2.get_ref()
print("COSE Key ref for derived key", ref)
kh = cbor.encode(ref)
kh = websafe_encode(cbor.encode(ref))

# Prepare a message to sign
message = b"New message"
Expand Down Expand Up @@ -178,6 +180,6 @@ def request_uv(self, permissions, rd_id):
# Response contains a signature over message
signature = sign_result.get("signature")

print("Test verify signature", signature.hex())
pk2.verify(message, signature)
print("Test verify signature", signature)
pk2.verify(message, websafe_decode(signature))
print("Signature verified with derived public key!")
2 changes: 1 addition & 1 deletion fido2/ctap2/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def process_create_input(self, inputs):
)
outputs = {3: gk.algorithms, 4: flags}

if gk.pd_data:
if gk.ph_data:
outputs[0] = gk.ph_data

return outputs
Expand Down

0 comments on commit d443f56

Please sign in to comment.