1

EDIT: when mentioning "cards" in the question below, I mean the kind of badges/cards you can but at Aliexpress that claim to be "magic" cards (or that ndo not claim anything and then are "read-only" ones)

I am planning to use 13.56 MHz NFC cards to protect a lock. I will write the software part myself (this is not a problem, including the security aspects) but I have a hard time understanding NFC cards (in the context of my project). I will build the reader myself, based on a NodeMCU and an RC522 reader.

I have done some reading and in the chaotic information I found (I must have not looked at the right place), and for the 13.56 MHz cards I have, my understanding is the following:

  • "static" cards, with their information written once and not changeable. I connected the Arduino to the RC522 reader and can read a 4 bytes UID.
    Question 1: is it possible to read more data? (MIFARE cards apparently have 1kB of data)
    Question 2: if so - what is the nature of this data? (and notably - is it random data?)

  • "rewritable" cards (also called "magic") where one can write to the card. The UID can be written to, but this also possible with more data (Home Assistant writes a UUID for instance).
    Question 3: Are there different cards with the possibility to write "only UID" or "UID and more data"?

And finally Question 4: is it possible to programmatically query/guess the type of card? (with a NodeMCU + RC522 but I am open to other combinations)

That's a lot of questions, let me know if you want me to split them into 4 different posts.

I have gathered over the years many NFC tags (some rewtitable, some not) and would like to put them to use but I first need to understand their nature.

1 Answer 1

3

I'm not sure where you got your classification, it seems a bit weird to me.

There are dozens of 13.56 MHz RFID card types and sub-types, but some of the most common are:

  • NTAG devices (could be actual cards, or take many other forms, especially stickers). Those are used mostly to "publish" an URL which can be read by a mobile phone for instance (like you would print a QR Code containing an URL), though like QR Codes, you could have all sors of data in there. NTAG devices have capacities in the dozens or hundreds of bytes. There are originally rewritable, but you can write-protect them after programming them.

  • Mifare cards. There are quite a few models (Classic, Ultralight, DESFire...) and submodels (EV1/EV2/EV3, 1K/2K/4K/8K, etc.). Those have storage capabilities, and depending on the models, various modes of encryption and protection. Mostly used for access badges and for ticketing in transportation systems.

  • EMV payment cards (credit cards, debit cards...). Usually dual mode (contact + contactless), they can contain multiple applications, perform PIN verification (and self-disable once you have reached the maximum number of wrong PINs), hold a balance, perform crypto operations (digital signatures...).

  • e-Passports and some ID cards and driver's licenses.

  • Smartphone can also emulate quite a few of the above (as well as read quite a few of the above).

There are quite a few other RFID cards and devices, but the above are probably the most common, at least in Europe and North America (in Japan and a few other countries you'll also find Felica, Icode, and others). Not all are actually NFC (NFC is only a subset of all 13.56 MHz RFID cards).

The UID is present on all those cards, it is used in the anti-collision protocol. The UID is supposed to be static, unique and non-rewritable, but of course you now have random UIDs, re-used UIDs, and carts with modifiable UID (used to clone existing cards).

Using the UID to identify a card is very simple and used a lot for non-security-sensitive applications. As soon as you need security, you can just forget about that, you'll need something more secure.

Most cards can store a lot more information, it can range from a few bytes to tens of thousands. There are often ways to protect the data (e.g. on most Mifare cards you can save data which is protected and can only be read if you have the relevant keys). Some cards like payment cards and the like can use asymmetric crypto and store a private key which you can read (but you can check the card knows the correct key by sending a challenge and verifying the signature it returns with the matching public key/certificate).

To answer your questions specifically:

Is it possible to read more data?

Yes, there are commands to do so.

if so - what is the nature of this data? (and notably - is it random data?)

It would be the data you stored there. Before you write any data, depending on the card, it could be just 0s or some other fixed pattern, or just random data. Just think of it as a (very small) hard drive or USB stick. It holds blocks, you write data to it, and you can later read it back (taking into account various levels of protections if there are any).

Some cards may also have other read-only data, though the details vary from card to card, you would have to check the data sheet for the specific model. Other cards may have dynamic data as well (e.g. number of activations).

Some cards are able to generate dynamic data with a counter and a signature involving that counter, other data, and a private key (so one can even on some of them generate a dynamic URL which changes at each read). Again, specific to each type of card.

Are there different cards with the possibility to write "only UID" or "UID and more data"?

I'm not aware of any card on which you could only write the UID. Most cards to not allow changing the UID. And there is nearly always more data you can write to. However many cards can be write-protected, so you can write data, then set the card to read-only (either permanently or until you provide a password you set at the same time, depending on the card). Read-only mode can be set either card-wide or per block, depending on the device.

Is it possible to programmatically query/guess the type of card?

Very generally it can quite difficult given the very large number of card types but there are ways to do it for specific cards. See for instance the MIFARE type identification procedure

For some cards/tags you can use the NFC TagInfo by NXP app on Android which will try to determine the tag type and provide more information, though results vary quite a bit depending on the type of card/tag. There is also an iOS version but it provides less information, and has probably more limited compatibility.

3
  • Thank you very much for the comprehensive answer. I realized that I should have narrowed my question a lot - I updated it with an edit. Thanks!
    – WoJ
    Nov 3, 2023 at 13:49
  • The most common cards are probably cards of the Mifare family or clones of those (most often Mifare Classic I would think), but there are dozens of "official" models, and yet more more or less faithful clones. There are also lots of NTAG devices (and clones thereof), though those are more often sold as stickers than cards I believe.
    – jcaron
    Nov 3, 2023 at 14:01
  • Note: if you want a system that you can rely on, Aliexpress is probably not the best source, as you never know exactly what you get (it can even change from one order to the next) and it's usually difficult to get exact specs or a data sheet.
    – jcaron
    Nov 3, 2023 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.