proxmark3/doc/desfire.md

392 lines
16 KiB
Markdown
Raw Normal View History

2021-12-31 18:25:27 +08:00
# Notes on MIFARE DESFire
2021-12-31 17:52:28 +08:00
<a id="Top"></a>
# Table of Contents
2021-12-31 18:25:27 +08:00
- [Notes on MIFARE DESFire](#notes-on-mifare-desfire)
2021-12-31 17:52:28 +08:00
- [Table of Contents](#table-of-contents)
- [Documentation](#documentation)
- [Source code](#source-code)
- [Communication channel with a card](#communication-channel-with-a-card)
- [Card architecture](#card-architecture)
- [Card structure](#card-structure)
- [DESFire Light](#desfire-light)
- [How to](#how-to)
- [How to get card UID](#how-to-get-card-uid)
- [How to get/set default communication channel settings](#how-to-getset-default-communication-channel-settings)
- [How to guess default communication channel settings](#how-to-guess-default-communication-channel-settings)
- [How to try communication channel settings](#how-to-try-communication-channel-settings)
- [How to look at the application list on the card](#how-to-look-at-the-application-list-on-the-card)
- [How to look/dump files from the application file list](#how-to-lookdump-files-from-the-application-file-list)
- [How to change key](#how-to-change-key)
- [How to create the application](#how-to-create-the-application)
- [How to create files](#how-to-create-files)
- [How to delete files](#how-to-delete-files)
- [How to read/write files](#how-to-readwrite-files)
- [How to work with transaction mac](#how-to-work-with-transaction-mac)
- [How to switch DESFire Light to LRP mode](#how-to-switch-desfire-light-to-lrp-mode)
2021-08-13 20:18:39 +08:00
## Documentation
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
[DESFire Light datasheet MF2DL(H)x0](https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[Features and Hints AN12343](https://www.nxp.com/docs/en/application-note/AN12343.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[Quick Start Guide AN12341](https://www.nxp.com/docs/en/application-note/AN12341.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[LRP Specification](https://www.nxp.com/docs/en/application-note/AN12304.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[NTAG 424 DNA NT4H2421Gx](https://www.nxp.com/docs/en/data-sheet/NT4H2421Gx.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[NTAG features and hints - LRP mode](https://www.nxp.com/docs/en/application-note/AN12321.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[ev2 samples AN12196](https://www.nxp.com/docs/en/application-note/AN12196.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[MIFARE Application Directory AN10787](https://www.nxp.com/docs/en/application-note/AN10787.pdf)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[Symmetric key diversifications AN10922](https://www.nxp.com/docs/en/application-note/AN10922.pdf)
## Source code
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[desfire_crypto from proxmark3](https://github.com/RfidResearchGroup/proxmark3/blob/master/armsrc/desfire_crypto.c)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[libfreefare](https://github.com/nfc-tools/libfreefare)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[desfire-tools-for-android](https://github.com/skjolber/desfire-tools-for-android)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[nfcjlib](https://github.com/andrade/nfcjlib/)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[java-card-desfire-emulation](https://github.com/gathigai/java-card-desfire-emulation)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[ChameleonMiniDESFireStack](https://github.com/maxieds/ChameleonMiniDESFireStack/)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
[LRP/ev2 nfc-ev2-crypto](https://github.com/icedevml/nfc-ev2-crypto)
2021-12-31 17:52:28 +08:00
## Communication channel with a card
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
The card can work with a combination of: key type - command set - secure channel - communication mode
2021-08-13 20:18:39 +08:00
2021-08-13 22:23:24 +08:00
*key types:*
2021-08-22 07:23:46 +08:00
**des** - 8-byte key. can be present in a form of **2tdea** key with length 16 bytes by duplicating contents twice.
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**2tdea** - 16-byte key
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**3tdea** - 24-byte key. can be disabled on the card level.
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**aes** - 16-byte AES-128 key
2021-08-13 20:18:39 +08:00
*command sets:*
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
**native** - raw commands
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**native iso** - wraps raw commands into the ISO APDU. **CLA** = 0x90, **INS** = command code, **data** = the remaining data from raw command
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**iso** - works only for some commands: ISO select by ISO ID (if enabled), authenticate, read and write in the **plain** mode, read in the **mac** mode
2021-08-13 20:18:39 +08:00
*secure channels:*
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
**d40** - old secure channel that can work only with **des** and **2tdea** keys
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
**ev1** - secure channel that can work with all the keys: **des**, **2tdea**, **3tdea**, **aes**
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
**ev2** - the newest channel that can work with **aes** key only
2021-08-22 07:23:46 +08:00
*communication modes*
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
**plain** - just plain data between card and reader
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**maced** - mac applied to request/response/both (may be sent or not)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
**encrypted** - encrypted data in the request/response/both in the ev2 channel data signed with mac.
2021-08-13 20:18:39 +08:00
## Card architecture
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 20:18:39 +08:00
2021-08-22 07:23:46 +08:00
The card has several applications on it and the applications have files and some other objects.
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
Each card has a master application with AID 0x000000 that saves the card's configuration.
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
Master application has many keys with different purposes, but commands show that there is only one key - card master key.
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
Each application may have its own key type and set of keys. Each file can only have links to these keys in its access rights.
2021-12-31 17:52:28 +08:00
## Card structure
^[Top](#top)
2021-08-13 20:18:39 +08:00
- Application
- Application number: 1 byte
2021-08-22 07:23:46 +08:00
- Application ISO number: if set at the time of application creation. It can be selected by this ID in the ISO command set.
- Application DF name: 1-16 chars. It can be selected by this name in the ISO command set.
2021-08-13 20:18:39 +08:00
- Key settings: number of keys, key type, key config (what can do/not user with keys)
- Keys: up to 14 keys (indexes 0..d)
2021-08-22 07:23:46 +08:00
- Key versions: key version of corresponding key
2021-08-13 20:18:39 +08:00
- Files:
- File number: 1 byte
2021-08-22 07:23:46 +08:00
- File ISO number: should be present if and only if application created with ISO number.
2021-08-13 20:18:39 +08:00
- File type: standard, backup, value, cyclic record, linear record, transaction mac
2021-08-22 07:23:46 +08:00
- Some settings that belong to file type (size for standard file for example)
2021-08-13 20:18:39 +08:00
- File communication mode: plain/maced/encrypted
2021-08-22 07:23:46 +08:00
- File access right: there are 4 modes: read/write/read-write/change settings. And each mode access can be: key0..keyD, E - free access, F - deny access
2021-08-13 20:18:39 +08:00
2021-12-31 17:52:28 +08:00
## DESFire Light
^[Top](#top)
2021-08-22 00:36:38 +08:00
2021-08-22 07:23:46 +08:00
The card has one preinstalled master file (ISO ID 0x3f00) and one application (0xdf01)
2021-08-22 00:36:38 +08:00
In the application, there are 6 files:
- 0x00 Standard data file with size 256 bytes
- 0x01 Cyclic record file with 5 records with size 16 bytes each
- 0x03 Value file
- 0x04 Standard data file with size 256 bytes
- 0x0f Transaction MAC file with size 256 bytes
- 0x1f Standard data file with size 32 bytes. Used for FCI.
User can't create/delete files (except Transaction MAC file).
2021-08-22 07:23:46 +08:00
ISO file IDs, the other files and application parameters can be changed via SetConfiguration command only.
2021-08-22 00:36:38 +08:00
2021-08-22 07:23:46 +08:00
The card has two secure channels: EV2 and LRP. By default, EV2 is on. LRP can be switched on by issuing SetConfiguration command and after that, it can't be switched off.
2021-08-22 00:36:38 +08:00
2021-08-22 07:23:46 +08:00
Application on the card can't be selected by DESFire native select. Needs to issue ISO select command. All the commands that can work in LRP channel have **--appisoid** option
2021-08-22 00:36:38 +08:00
2021-08-22 07:23:46 +08:00
Transaction MAC file - the only file that can be created and deleted. By default, all transaction operations (operations with Value and Record file) need to issue CommitReaderID command.
So (to fast check- it is needed to delete this file) it has default file id - 0x0f.
2021-08-22 00:36:38 +08:00
2021-08-22 00:48:37 +08:00
FCI sends from card to reader after selecting the application (df01 by default)
2021-08-22 07:23:46 +08:00
If it needs to have more space for FCI - just change the ID of one of the bigger files to 0x1f (and the current ID to something else) via SetConfiguration command.
2021-08-22 00:48:37 +08:00
2021-08-13 20:18:39 +08:00
## How to
2021-12-31 17:52:28 +08:00
2021-08-13 20:18:39 +08:00
### How to get card UID
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
The card can return UID in encrypted communication mode. Needs to authenticate with any key from the card.
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes getuid` - authenticate with default key
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes getuid -s d40` - via d40 secure channel
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes getuid -s ev2 -t aes -k 11223344556677889900112233445566` - via ev2 secure channel with specified aes key
### How to get/set default communication channel settings
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
All the commands use these settings by default if a more important setting is not specified in the command line.
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes default` - get channel settings
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes default -n 1 -t aes` - set key number 1 and key type aes
### How to guess default communication channel settings
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes detect` - simply detect key for master application (PICC level)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes detect --save` - detect key and save to defaults. look after to output of `hf mfdes default`
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes detect -s d40` - detect via channel d40
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes detect --dict mfdes_default_keys` - detect key with help of dictionary file
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes detect --aid 123456 -n 2` - detect key 2 from application with AID 123456
### How to try communication channel settings
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes auth -n 0 -t des -k 1122334455667788 --aid 123456` - try application 123456 master key
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes auth -n 0 -t aes --save` - try PICC AES master key and save the configuration to defaults if authentication succeeds
### How to look at the application list on the card
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes lsapp --no-auth` - show applications list without authentication
2021-08-13 22:23:24 +08:00
2021-08-13 20:18:39 +08:00
`hf mfdes lsapp` - show applications list with authentication from default settings
2021-08-13 22:23:24 +08:00
2021-08-13 20:35:52 +08:00
`hf mfdes lsapp --files` - show applications list with their files
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes getaids --no-auth` - this command can return a simple AID list if it is enabled in the card settings
2021-08-13 20:35:52 +08:00
### How to look/dump files from the application file list
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 20:35:52 +08:00
`hf mfdes lsfiles --aid 123456 -t aes` - file list for application 123456 with aes key
2021-08-13 22:23:24 +08:00
2021-08-13 20:35:52 +08:00
`hf mfdes dump --aid 123456` - shows files and their contents from application 123456
2021-08-13 21:45:56 +08:00
### How to change key
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
Changing key algorithm can be done only in one case - change card master key.
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
Key algorithm for application can be chosen only on its creation.
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes changekey -t des --newalgo aes --newkey 11223344556677889900112233445566 --newver a5` - change picc master key from des default to aes
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes changekey --aid 123456 -t des -n 0 -k 5555555555555555 --newkey 1122334455667788` - change application master key from one key to another
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes changekey --aid 123456 -t des -n 0 --newkeyno 1 --oldkey 5555555555555555 --newkey 1122334455667788` - change key 1 with authentication with key 0 (app master key)
2021-08-13 20:35:52 +08:00
### How to create the application
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes createapp --aid 123456 --fid 2345 --dfname aid123456 --dstalgo aes` - create an application with ISO file ID, df name, and key algorithm AES
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes createapp --aid 123456` - create an application 123456 with DES key algorithm and without ISO file ID. in this case, iso file id can't be provided for application's files
2021-08-13 20:35:52 +08:00
### How to create files
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes createfile --aid 123456 --fid 01 --isofid 0001 --size 000010` - create standard file with ISO ID and default access settings
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createfile --aid 123456 --fid 01 --isofid 0001 --size 000010 --backup` - create backup file
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
Create standard file with mac access mode and specified access settings. access settings can be changed later with command `hf mfdes chfilesettings`
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createfile --aid 123456 --fid 01 --isofid 0001 --size 000010 --amode mac --rrights free --wrights free --rwrights free --chrights key0`
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createvaluefile --aid 123456 --fid 01 --isofid 0001 --lower 00000010 --upper 00010000 --value 00000100` - create value file
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createrecordfile --aid 123456 --fid 01 --isofid 0001 --size 000010 --maxrecord 000010` - create linear record file
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createrecordfile --aid 123456 --fid 01 --isofid 0001 --size 000010 --maxrecord 000010 --cyclic` - create cyclic record file
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes createmacfile --aid 123456 --fid 01 --rawrights 0FF0 --mackey 00112233445566778899aabbccddeeff --mackeyver 01` - create transaction mac file
### How to delete files
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes deletefile --aid 123456 --fid 01` - delete file
2021-08-13 20:35:52 +08:00
### How to read/write files
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*read:*
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes read --aid 123456 --fid 01` - autodetect file type (with `hf mfdes getfilesettings`) and read its contents
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes read --aid 123456 --fid 01 --type record --offset 000000 --length 000001` - read one last record from a record file
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
*read via ISO command set:*
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
Here it is needed to specify the type of the file because there is no `hf mfdes getfilesettings` in the ISO command set
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes read --aid 123456 --fileisoid 1000 --type data -c iso` - select application via native command and then read file via ISO
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes read --appisoid 0102 --fileisoid 1000 --type data -c iso` - select all via ISO commands and then read
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes read --appisoid 0102 --fileisoid 1100 --type record -c iso --offset 000005 --length 000001` - read one record (number 5) from file ID 1100 via ISO command set
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes read --appisoid 0102 --fileisoid 1100 --type record -c iso --offset 000005 --length 000000` - read all the records (from 5 to 1) from file ID 1100 via ISO command set
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*write:*
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes write --aid 123456 --fid 01 -d 01020304` - autodetect file type (with `hf mfdes getfilesettings`) and write data with offset 0
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes write --aid 123456 --fid 01 --type data -d 01020304 --commit` - write backup data file and commit
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes write --aid 123456 --fid 01 --type value -d 00000001` increment value file
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes write --aid 123456 --fid 01 --type value -d 00000001 --debit` decrement value file
2021-08-13 22:23:24 +08:00
2021-08-13 21:45:56 +08:00
`hf mfdes write --aid 123456 --fid 01 --type record -d 01020304` write data to a record file
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes write --aid 123456 --fid 01 --type record -d 01020304 --updaterec 0` update record 0 (latest) in the record file.
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*write via iso command set:*
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes write --appisoid 1234 --fileisoid 1000 --type data -c iso -d 01020304` write data to std/backup file via ISO command set
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
`hf mfdes write --appisoid 1234 --fileisoid 2000 --type record -c iso -d 01020304` send record to record file via ISO command set
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*transactions:*
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
For more detailed samples look at the next howto.
`hf mfdes write --aid 123456 --fid 01 -d 01020304 --readerid 010203` write data to the file with CommitReaderID command before and CommitTransaction after write
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
### How to work with transaction mac
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
There are two types of transactions with mac: with and without the CommitReaderID command. The type can be chosen by `hf mfdes createmacfile` command.
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
By default, the application works with transactions. All the write operations except write to standard file need to be committed by CommitTransaction command.
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
CommitTransaction command issued at the end of each write operation (except standard file).
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
Mac mode of transactions can be switched on by creating a mac file. There may be only one file with this file type for one application.
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
Command CommitReaderID enable/disable mode can be chosen at the creation of this file.
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
When CommitReaderID is enabled, it is needed to issue this command once per transaction. The transaction can't be committed without this command.
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
When the command is disabled - CommitReaderID returns an error.
*more info from MF2DL(H)x0 datasheet (link at the top of this document):*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
10.3.2.1 Transaction MAC Counter (page 41)
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
10.3.2.5 Transaction MAC Reader ID and its encryption (page 43)
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
10.3.3 Transaction MAC Enabling (page 44)
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
10.3.4 Transaction MAC Calculation (page 45)
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
10.3.4.3 CommitReaderID Command (page 47)
*create mac file:*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes createmacfile --aid 123456 --fid 0f --rawrights 0FF0 --mackey 00112233445566778899aabbccddeeff --mackeyver 01` - create transaction mac file. CommitReaderID disabled
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes createmacfile --aid 123456 --fid 0f --rawrights 0F10 --mackey 00112233445566778899aabbccddeeff --mackeyver 01` - create transaction mac file. CommitReaderID enabled with key 1
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*read mac and transactions counter from mac file:*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes read --aid 123456 --fid 0f` - with type autodetect
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*write to data file without CommitReaderID:*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes write --aid 123456 --fid 01 -d 01020304`
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
*write to data file with CommitReaderID:*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes write --aid 123456 --fid 01 -d 01020304 --readerid 010203`
2021-08-13 22:23:24 +08:00
2021-08-22 07:23:46 +08:00
*write to data file with CommitReaderID and decode previous reader ID:*
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
step 1. read mac file or read all the files to get transaction mac counter
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes read --aid 123456 --fid 0f` - read mac file
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes dump --aid 123456` - read all the files
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
step 2. write something to a file with CommitReaderID command and provide the key that was set by `hf mfdes createmacfile` command
2021-08-13 22:23:24 +08:00
2021-08-13 22:11:50 +08:00
`hf mfdes write --aid 123456 --fid 01 -d 01020304 --readerid 010203 --trkey 00112233445566778899aabbccddeeff`
2021-08-22 00:48:37 +08:00
2021-08-22 07:23:46 +08:00
### How to switch DESFire Light to LRP mode
2021-12-31 17:52:28 +08:00
^[Top](#top)
2021-08-22 00:48:37 +08:00
Remove failed authentication counters (if needs, but strongly recommended)
`hf mfdes setconfig --appisoid df01 -t aes -s ev2 --param 0a --data 00ffffffff`
or in the LRP mode
`hf mfdes setconfig --appisoid df01 -t aes -s lrp --param 0a --data 00ffffffff`
Switch LRP mode on
`hf mfdes setconfig --appisoid df01 -t aes -s ev2 --param 05 --data 00000000010000000000`