简体   繁体   English

如何在Android中检测NFC标签中的UID是否随机?

[英]How to detect in Android whether UID from NFC tag is random?

I am working on an Android project which relies on the unique UID of a discovered NFC tag to process the tag. 我正在开发一个Android项目,该项目依赖于已发现的NFC标签的唯一UID来处理标签。 I extract this UID using the following code: 我使用以下代码提取此UID:

byte[] extraID = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);

However, for some technologies this UID is randomly generated for security purposes. 但是,对于某些技术,此UID是出于安全目的而随机生成的。 Does anybody have an idea how I could detect that this is a randomly generated UID? 有没有人知道如何检测到这是一个随机生成的UID? Is there some kind of flag that is set? 是否设置了某种标志?

note: a simple solution would be to read the tag twice and compare the UIDs. 注意:一个简单的解决方案是读取标记两次并比较UID。 However, I would like to avoid this. 但是,我想避免这种情况。

For NfcA (and IsoDep and/or MifareClassic combined with NfcA), the ID is random if it exactly 4 bytes long and starts with 0x08. 对于NfcA(和IsoDep和/或MifareClassic结合NfcA),如果ID恰好是4个字节长并且以0x08开头,则ID是随机的。 There are some cards (MIFARE DESFire) that can be configured with a random ID that is 4 bytes long and starts with 0x80. 有些卡(MIFARE DESFire)可以配置一个4字节长的随机ID,并以0x80开头。

For NfcB (and IsoDep combined with NfcB), there is no predetermined ID range that is reserved for random IDs. 对于NfcB(以及与NfcB组合的IsoDep),没有为随机ID保留的预定ID范围。 In fact, any NfcB ID can be a random one. 实际上,任何NfcB ID都可以是随机的。 The NfcB ID is actually called PUPI, which stands for "Pseudo Unique PICC Identifier". NfcB ID实际上称为PUPI,它代表“伪唯一PICC标识符”。 So the name already indicates that uniqueness is not guaranteed. 所以这个名字已经表明不保证唯一性。

For NfcF and NfcV, the ID will generally not be random. 对于NfcF和NfcV,ID通常不是随机的。

Reading the tag twice to detect a random ID only works if you remove the tag from the RF field. 只有从RF字段中删除标记,才能读取标记两次以检测随机ID。 A tag will usually keep the same random ID as long as it stays powered by the Rf field. 标签通常保持相同的随机ID,只要它由Rf字段保持供电即可。

This RFC: http://tools.ietf.org/html/rfc4122#section-4.1.3 defines the format of a UID; 此RFC: http//tools.ietf.org/html/rfc4122#section-4.1.3定义了UID的格式; it includes a field indicating what type of UID it is: 它包含一个字段,指示它是什么类型的UID:

 Msb0  Msb1  Msb2  Msb3   Version  Description

    0     0     0     1        1     The time-based version
                                     specified in this document.

    0     0     1     0        2     DCE Security version, with
                                     embedded POSIX UIDs.

    0     0     1     1        3     The name-based version
                                     specified in this document
                                     that uses MD5 hashing.

    0     1     0     0        4     The randomly or pseudo-
                                     randomly generated version
                                     specified in this document.

    0     1     0     1        5     The name-based version
                                     specified in this document
                                     that uses SHA-1 hashing.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM