From 9409ebacf3eabfbb202d53b30cc9ffb981e7b038 Mon Sep 17 00:00:00 2001 From: ahtlon Date: Wed, 20 May 2026 20:13:46 +0200 Subject: [PATCH] desfire test app --- test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..63e2db3 --- /dev/null +++ b/test.py @@ -0,0 +1,31 @@ +from smartcard.CardRequest import CardRequest +from smartcard.CardType import AnyCardType +from smartcard.Exceptions import CardRequestTimeoutException + +from desfire import DESFire, DESFireKey, PCSCDevice, to_hex_string + +cardtype = AnyCardType() +cardrequest = CardRequest(timeout=30, cardType=cardtype) +print("Please present DESfire tag...") + +try: + cardservice = cardrequest.waitforcard() +except CardRequestTimeoutException: + print("No tag detected within the timeout.") + exit(0) + + +cardservice.connection.connect() + +# Create Desfire object, which allows further communication with then card +desfire = DESFire(PCSCDevice(cardservice.connection.component)) + +# Authenticate with default DES key by retrieving the key settings from the card, +# providing the default key and then authenticate against the master key 0x0 +key_settings = desfire.get_key_setting() +mk = DESFireKey(key_settings, "00" * 8) +desfire.authenticate(0x0, mk) + +# Get real UID +uid = desfire.get_real_uid() +print(to_hex_string(uid)) \ No newline at end of file