Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a JavaCard emulate a MIFARE Ultralight or NTAG NFC tag?

I would like to write a Java Card applet that responds to an NFC reader as if it was a regular MIFARE Ultralight or NTAG NFC tag.

I am aware the MIFARE protocol is proprietary and may be a little more difficult but surely I should be able to achieve emulation of the NTAG protocol.

If I match the NTAG specification and respond to the correct APDUs then I can surely emulate an NTAG?

Update to original question

I think I asked my original question incorrectly. I'm not looking to emulate a specific tag per sé. What I am actually trying to do is use a Java Card powered card to be able to supply dynamic information to a smartphone such as Android or Apple iPhone using the new Core NFC API. Note that this API is said to support tags of type 1 through 5. I would like to be able to write a Java Card applet that can run on a contactless smartcard and allow (simplex) communication with a smartphone.

I guess my question is: How can I determine the flow of APDU from the Core NFC API so that I can write an applet that will respond suitably?

like image 201
jim Avatar asked Jan 31 '23 03:01

jim


1 Answers

No, that's not possible. MIFARE Ultralight, NTAG, and other NFC Forum Type 2 tags operate on top of the anti-collision and framing protocols defined in ISO/IEC 14443-3A (also called NFC-A).

Java Card applets (in general) communicate using APDU commands (a protocol layer defined in ISO/IEC 7816-4). The Java Card run-time environment only passes APDU commands to applets. Contactless smartcards exchange these APDU commands on top of the ISO-DEP half duplex transmission protocol (as specified in ISO/IEC 14443-4). This transmission protocol, in turn, sits on top of one of the framing protocols defined in ISO/IEC 14443-3 (also called NFC-A and NFC-B).

+-------------------------+  +-------------------------+
| MIFARE Ultralight/NTAG  |  | Contactless Java Card   |
+-------------------------+  +-------------------------+

                             +-------------------------+
                             | Commands: APDUs         |
                             | (ISO/IEC 7816-4)        |
+-------------------------+  +-------------------------+
| Commands: Proprietary   |  | ISO-DEP                 |
| or NFC Forum Type 2ary  |  | (ISO/IEC 14443-4)       |
+-------------------------+  +-------------------------+
| Framing: NFC-A          |  | Framing: NFC-A or NFC-B |
| (ISO/IEC 14443-3 A)     |  | (ISO/IEC 14443-3 A/B)   |
+-------------------------+  +-------------------------+
|           ...           |  |          ...            |
+-------------------------+  +-------------------------+

Consequently, while both technologies share common protocol layers, Java Card applets can only exchange APDU commands and cannot control much of the lower protocol layers directly.

Edit (based on ErikM's remark):

While it's not possible to emulate NFC Forum Type 2 tags on Java Card (unless there would be dedicated hardware support on your smartcard platform --- And I don't think that this currently exists.), you could easily emulate an NFC Forum Type 4 tag on any Java Card contactless smartcard. So if your goal is to emulate an NFC tag that presents an NDEF message to e.g. a smartphone, then you could follow this approach. There is even open-source implementations of such applets, e.g.

  • https://github.com/promovicz/javacard-ndef
  • https://github.com/slomo/ndef-javacard
like image 190
Michael Roland Avatar answered Feb 02 '23 23:02

Michael Roland