FabAccess
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    NFC Lib - DESFire === ###### tags: `Docs` **[LibLogicalAccess](https://github.com/islog/liblogicalaccess)** > Müssen wir uns mal anschauen, da die das können, was wir wollen # ISO 7816 Die ISO 7816 spezifiziert in mehreren Teilen die Normen für kontaktbehaftete Chipkarten. Für die DESFire Bibliotheke ist der Teil 4 relevant, da dort die Kommunikation mit der Chipkarte definiert wird. ## ISO 7816 Parts [siehe Wikipedia](https://en.wikipedia.org/wiki/ISO/IEC_7816) ## ISO 7816 Part 4 ### APDU Command (wird an PICC gesendet) | CLA | INS | P1 | P2 | Lc | Data | Le | | -----| --- | ---- | --- | ------ | ---- | -- | |1 byte|1 byte|1 byte|1 byte|1* byte|max. 253* bytes|0-3 bytes| [siehe Wikipedia](https://de.wikipedia.org/wiki/Application_Protocol_Data_Unit#command_APDU) ### APDU Response (kommt als Antwort vom PICC) | Data | SW1-SW2 | | ---------------- | ------- | | max. 253** bytes | 2 bytes | [siehe Wikipedia](https://de.wikipedia.org/wiki/Application_Protocol_Data_Unit#response_APDU) CLA=Instruction Class > gibt an, ob es sich nachfolgend um standardisierte Befehle oder um proprietäre Befehle handelt. Normalerweise 0x90. INS=Instruction Code > jeweiliger Befehl der ausgeführt werden soll. P1/P2 = Instruction parameter for command > spezifische Parameter für den Befehl, z.B. ein Offset in der Datie in der geschrieben werden soll. Lc = commando Length > nennt die Anzahl der Bytes die in [Data] übergeben werden. Kann 1 Byte (max 255) oder 3 (max 65 535, erstes Byte muss 0 sein) Bytes verwendet werden. Data = command data > Daten die im Zuge des Befehls übertragen werden sollen / als Antwort vom PICC zurückgegeben werden. Le = response Lenght > Anzahl der Bytes die als Antwort erwartet werden. Dabei stellt 0x00 ein "Platzhalter" für "eine undefinierte Länge bis zu 255 Bytes" da. SW1-SW2 = Response Trailer > gibt den Anwort-Status wieder, z.B. (Hex): > 90 00 für "Command successfully executed (OK)" > 91 00 für "OK" > [siehe Response codes](https://www.eftlab.com/knowledge-base/complete-list-of-apdu-responses/) "*" / "**" wir verwenden maximal 255 bytes, da ansonsten die Datenübertragung mittels MQTT sehr lang werden könnte. ## Beispiel select Application 0xC0FFEE [siehe OTA Beispiel](https://icedev.pl/blog/over-the-air-nfc-services-mifare/) |Parameter| Wert |Kommentar| | ------- | -------------- | ------- | | CLA | 0x90 |Standard Befehlssatz| | INS | 0x5A |select Application | | P1/P2 | 0x00/0x00 |keine zusätzliche Parameter| | Lc | 0x03 |3 Bytes| | Data |0xEE, 0xFF, 0xC0|umgekehrte Reihenfolge(?)| | Le | 0x00 |0x00 = maximal 255 bytes| Befehl: "\x90\x5A\x00\x00\x03\xEE\xFF\xC0\x00" bzw. 905A000003EEFFC000 Antwort "\x91\x00" bzw 9100 |Parameter| Wert |Kommentar| | ------- | -------------- | ------- | | Data | - | Befehlt erwartet keine Daten (Le=0)| | SW1/SW2 | 0x91, 0x00 | "OK"| # Befehle Wrapping von DESFire Native Commands in ISO 7816-4 APDU Frames. ClA(Class) = 0x90 (Bei allen Commands für die Karte) INS(Instrucation) = Command Code des jeweiligen Befehls ## Glossar AID = Application ID > Jede Application auf der DESFire Karte hat einen eigenen Identifier. Ein AID ist 3 Byte groß. PICC = Proximity Integrated Circuit Card > Die Chipkarte selber IV = Initialisierungsvektor > Ist ein Begriff aus der Kryptographie und bezeichnet einen Block von Zufallsdaten, der in bestimmten Modi einiger Blockchiffren verwendet wird, wie dem Cipher Block Chaining Mode. CBC = Cipher Block Chaining > Ist eine Betriebsart, in der Blockchiffren betrieben werden können. Vor dem Verschlüsseln eines Klartextblocks wird dieser zunächst mit dem im vorhergehenden Schritt erzeugten Geheimtextblock per XOR (exklusives Oder) verknüpft. Datenstruktur Low Level | PCB | [CID] | [NAD] | [INF] | EDC/CRC | | ---- | ----- | ----- | ------------- | ------- | | 0x0A | 0x00 | n.v. | APDU data | specific| |1 byte|1 byte |1 byte | max. 253 bytes| 2 bytes | PCB = Protocol Control Byte (low level, prologue field) > Ist Teil der "Umkapselung" eines APDU Kommandos in der Kommunikation mit dem PICC. Im Normalfall 0x0A (Information Block, no chaining, CID follows, no NAD, BlockNr = 0). CID = Card ID (low level, prologue field) > Ist Teil der "Umkapselung" eines APDU Kommandos in der Kommunikation mit dem PICC. Ist der Identifizierer des aktuelle PICCs. Ist nur relevant, wenn mehrere PICCs vom Leser gleichzeitig erkannt wurden und nacheinander selektiert wurden. Bei der Kommunikation mit nur einer Karte immer 0x00. NAD = Node Address > Identifizierer für Absender und Empfänger. Wird nicht verwendet. EDC / CDC = Error Detection Code / Cyclic Redundancy Check (low level, epilogue field) > Ist Teil der Umkapselung von jeder Nachricht an einem PICC. Wird forlaufend berechnet. Wird häufig von der Hardware selbst berechnet, muss jedoch manuell vom Programm angehangen werden. INF = Information Field > ist der Teil der Nachricht mit der Infromation mit der Karte ausgetauscht werden kann. Hier können einfache Kommandos oder APDUs verwendet werden ## APDU definition ## Get Application IDs APDU Case: 2 | Command Code | P1 | P2 | Data | | ------------ | --- | --- | ---- | | 0x6A | | | | The “Get AID List” command return the Application Identifiers of all active applications on a PICC. 0x000000 is PICC Application ID, is always returned. > TODO: 4 or 3 Bytes AID size > TODO: MSB or LSB first ## Select Application by AID APDU Case: 3 | Command Code | P1 | P2 | Data | | ------------ | --- | --- | ----------------------- | | 0x5A | | | AID (3 Byte, MSB first) | The “Select Application” command allows to select one specific application for further access. If this parameter is 0x000000, the PICC level is selected and any further operations are related to this level. If an application with the specified AID is found in the application directory of the PICC, the subsequent commands interact with this application. ## AuthenticateISO **Get Challenge** APDU Case: 4 | Command Code | P1 | P2 | Data | | ------------ | --- | --- | --------------- | | 0x1A | | | key_id (1 Byte) | **Send Challenge** APDU Case: 4 | Command Code | P1 | P2 | Data | | ------------ | --- | --- | --------------------- | | 0x5A | | | challenge (MSB first) | **Authentication Process** ![Authentication Process](https://media-exp1.licdn.com/dms/image/C4E12AQEsgzUEgi1GoQ/article-inline_image-shrink_1500_2232/0?e=1607558400&v=beta&t=y9BhiOJ9jLTY2gXr5RDPs3if9rvQz-tn-E7TlnIegP4) **Beispiel** [zum Beispiel](https://www.linkedin.com/pulse/mifare-desfire-introduction-david-coelho) **Zur Crypto** Es wird CBC verwendet. Zum Entschlüsslen von rndB wird der IV auf 0 gesetzt. > The IV of the session key is reset to zero only ONCE when the key is created after authentication. The IV of the authentication key is reset only ONCE when authentication starts. Bei allen anderen Verschlüsselungen oder Entschlüsselungen wird der letzte verschlüsselte Block als IV verwendet. # Response Codes > [TODO: Copy from eftlab.com] # Over the Air ## Ablauf Kommunikation ### Authentication ``` // Reader 1. Authenticate against lokal BFFH 2. Start Proxy Session 3. Meldet die Präsenz einer Karte // Client 1. Start Proxy Session // Lokale BFFH MifareDESFire mifareDESFire = new MifareDESFire(card); mifareDESFire.SelectApplication(FabAccessAID); // FabAccessIdentFileID ist unverschlüsselt byte[] filedata = mifareDESFire.ReadData(FabAccessIdentFileID, 0x00000000, 0x00000000); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string userdomain = enc.GetString(filedata); Console.WriteLine(userdomain); // Domain BFFH // Der Eigentümer der Karte mifareDESFire.SelectApplication(FabAccessAID); mifareDESFire.Authenticate(0x01, APP_Key_1); // jetzt wissen wir, das die Karte Authentisch ist byte[] filedata = mifareDESFire.ReadData(FabAccessIdentFileID, 0x00000000, 0x00000000); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string userdomain = enc.GetString(filedata); // jetzt wissen wir, dass die Domain auch wirklich auf die Karte ist // jetzt müßte man noch einmal die UID der Karte abfragen, um sicher zu stellen, dass der User auch der ist, für den er sich ursprünglich ausgegeben hat. connected_successfully = true; card.Disconnect(); ``` # Troubleshooting ## Error 0x910B Reinstall NFC Driver on Windows # Quellen ## NXP / Mifare ### Allgemein [Mifare Application Directory](https://www.nxp.com/docs/en/application-note/AN10787.pdf) [Missing Native Commands](https://www.mifare.net/support/forum/topic/native-commands-sending-to-mifare-desfire-ev1/) ### MIFARE DESFire spezifisch ### Produktübersicht [EV1 Factsheet](https://www.nxp.com/docs/en/fact-sheet/MIFARE-DESFIRE-EV1-FS.pdf) [EV2 Factsheet](https://www.nxp.com/docs/en/fact-sheet/MIFARE-DESFIRE-EV2-FS.pdf) [EV3 Factsheet](https://www.mifare.net/wp-content/uploads/2020/06/NXP-MIFARE-DESFire-EV3-IC-Fact-Sheet.pdf) #### Datasheets [EV1 Datasheet](https://www.nxp.com/docs/en/data-sheet/MF3ICDX21_41_81_SDS.pdf) [EV2 Datasheet](https://www.nxp.com/docs/en/data-sheet/MF3DX2_MF3DHX2_SDS.pdf) [EV3 Datasheet](https://www.nxp.com/docs/en/data-sheet/MF3DHx3_SDS.pdf) [Light Datasheet](https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf) #### Features [Over the Air](https://www.nxp.com/docs/en/application-note/AN12113.pdf) [EV3 Features](https://www.nxp.com/docs/en/application-note/AN12752.pdf) [EV3 Quick Start](https://www.nxp.com/docs/en/application-note/AN12753.pdf) #### andere Links [Generic Access Control Model](https://www.nxp.com/docs/en/application-note/AN10957.pdf) [System Level Security](https://www.nxp.com/docs/en/application-note/AN10969.pdf) [PHILLIPS Presentation](http://read.pudn.com/downloads134/ebook/572228/M306_Mifare_DESFire_Func_V1.pdf) [PHILLIPS DESFireSAM](http://13.209.45.252/pdf/download.php?id=5dccfb20a6e931d4e5f6d4f397b7cba9e73567&type=P&term=DESFire) [Authentification Spec](https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf) [ISO/IEC 14443 Type 4 Tag](https://www.nxp.com/docs/en/application-note/AN11004.pdf) [ISO/IEC 14443 Communication](https://www.nxp.com/docs/en/application-note/AN10834.pdf) [Error Code - 0x6A81](https://www.mifare.net/support/forum/topic/mifare-desfire-ev2-authenticate-with-6a81-response/) ### ISO [MIFARE ISO/IEC 14443](https://www.nxp.com/docs/en/application-note/AN10834.pdf) ## externe DESFire Spezifikationen oder Dokumentationen [DESFire OTA - Proof of Concept](https://icedev.pl/blog/over-the-air-nfc-services-mifare/) [Ridrix DESFire Commands](https://ridrix.wordpress.com/tag/desfire-commands/) [MIFARE DESFire Short Spec](https://www.plastikkartenmonster.de/images/datenblaetter/datenblatt-nxp-mifare-desfire-d40.pdf) [DESFire KeySettings](https://developer.fidesmo.com/documentation/desfire-implementation) [Response Codes](https://www.eftlab.com/knowledge-base/complete-list-of-apdu-responses/) [DESFire Authentification](https://www.linkedin.com/pulse/mifare-desfire-introduction-david-coelho) [DESFire Command Set](https://scancode.ru/upload/iblock/de4/mifare_application_programming_guide_for_desfire_rev.e.pdf) [AES Authentication](https://www.ti.com/lit/an/sloa213/sloa213.pdf?ts=1601849488974&ref_url=https%253A%252F%252Fwww.google.com%252F) [PHILLIPS DESFire Specification](http://neteril.org/files/M075031_desfire.pdf) ## ISO Specifications [ISO 7816-4](https://cardwerk.com/smart-card-standard-iso7816-4-section-9-application-independent-card-services/) [ISO/IEC7816-4](http://www.unsads.com/specs/ISO/7816/ISO7816-4.pdf) ## andere NFC Bibliotheken (mit DESFire) [JavaCardOS](https://github.com/JavaCardOS/pyResMan/blob/master/pyResMan/DESFireEx.py) [Easypay](https://github.com/nceruchalu/easypay/blob/master/mifare/mifare.c) [Android Java App](https://github.com/jekkos/android-hce-desfire/blob/master/hceappletdesfire/src/main/java/net/jpeelaer/hce/desfire/ValueRecord.java) [RFID Door Lock](https://www.codeproject.com/Articles/1096861/DIY-electronic-RFID-Door-Lock-with-Battery-Backup) [RFDoorLock](https://github.com/sotechcllc/RFDoorLock) [DESFire Server](https://github.com/icedevml/ota-nfc-server) [libfreefare](https://github.com/nfc-tools/libfreefare) [DesFire for Python](https://github.com/miohtama/desfire) [libopenkey](https://github.com/henryk/libopenkey) [mfrc522](https://www.rubydoc.info/gems/mfrc522/1.0.1/Mifare/DESFire#change_key-instance_method) **[LibLogicalAccess](https://github.com/islog/liblogicalaccess)** > Müssen wir uns mal anschauen, da die das können, was wir wollen ## andere Links [DESFire Auth 2K3DES](https://stackoverflow.com/questions/14117025/des-send-and-receive-modes-for-desfire-authentication) [Authentication Question](https://stackoverflow.com/questions/38283998/desfire-ev1-communication-examples) [Kommunikationsbeispiele](https://hack.cert.pl/files/desfire-9f122c71e0057d4f747d2ee295b0f5f6eef8ac32.html) [DESFire CRC Question](https://stackoverflow.com/questions/11027162/which-crc-is-used-to-change-key-in-desfire-card) ## unsere Mitschnitte der Kommunkation verschiendener Bibliotheken [OTA Proof-of-Concept]()

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully