简体   繁体   English

Android NFC API对Mifare Desfire的支持程度如何?

[英]How well does the Android NFC API support Mifare Desfire?

I'm likely to be working on a project where existing Desfire cards (used to access paid services) will be replaced with an NFC-capable mobile device. 我很可能在一个项目中,将现有的Desfire卡(用于访问付费服务)替换为支持NFC的移动设备。 Can anyone point me to any resources to help me understand what's involved in a) replicating a Desfire card's data onto a mobile device so it can take the place of a card, and b) for the app to deliver NFC data in order to present to the reader as if it were a card. 任何人都可以指向我使用任何资源来帮助我了解涉及以下内容的内容:a)将Desfire卡的数据复制到移动设备上,以便可以代替卡; b)应用程序传递NFC数据以呈现给读者就像卡一样。 All relevant keys and access will be provided by the card issuer (if the project goes ahead) but I'm keen to understand the process in advance. 发卡机构将提供所有相关的密钥和访问权限(如果项目继续进行的话),但我很想提前了解该过程。

I also need to understand how well the Android NFC API supports Desfire, because as far as I can see it only properly support Classic. 我还需要了解Android NFC API支持Desfire的程度,因为据我所知,它仅正确支持Classic。 http://developer.android.com/reference/android/nfc/tech/package-summary.html http://developer.android.com/reference/android/nfc/tech/package-summary.html

MIFARE DESFire is ISO 14443-4 compliant. MIFARE DESFire符合ISO 14443-4。 Support in Android for ISO 14443-4 (and therefore MIFARE DESFire) is done by the IsoDep class. IsoDep类可为Android提供对ISO 14443-4(因此也支持MIFARE DESFire)的IsoDep You can send any DESFire command using the transceive() method of that class. 您可以使用该类的transceive()方法发送任何DESFire命令。

Besides that, DESFire can be configured to be NFC Forum type 4 Tag compliant. 除此之外,DESFire可以配置为符合NFC论坛4类标签。 In which case Android will read out automatically any NDEF messages from the tag and dispatch it in an intent. 在这种情况下,Android会自动从标记中读取所有NDEF消息,并有意将其分发。 So you can make your app start automatically when a specific tag is scanned. 因此,当扫描特定标签时,您可以使您的应用自动启动。 (Android can also format a DESFire chip to contain NDEF and write NDEF data to it.) (Android还可以格式化DESFire芯片以包含NDEF并向其中写入NDEF数据。)

Replacing a DESFire card by a mobile NFC device is another matter. 用移动NFC设备更换DESFire卡是另一回事。 Card emulation on currently available Android devices is done by an embedded Secure Element connected to the NFC chip. 当前可用的Android设备上的卡模拟是通过连接到NFC芯片的嵌入式安全元件完成的。 An Android app cannot emulate a card (there is also no API for this) and the Secure Element cannot emulate a DESFire chip. Android应用程序不能模拟卡(也没有用于此的API),安全元素也不能模拟DESFire芯片。 Furthermore, there is no open API to access the Secure Element from an app. 此外,没有开放的API可以从应用程序访问Secure Element。

The only way an Android NFC app can communicate via NFC to another device (that is not a card) is using Android Beam . Android NFC应用程序可以通过NFC与另一台设备(不是卡)通信的唯一方法是使用Android Beam This is, however, a different protocol than that used between card and reader. 但是,这是与卡和读卡器之间使用的协议不同的协议。

NFC guy answer is excellent, but a bit outdated, so I decided to add an update. NFC家伙的回答非​​常好,但是有点过时了,所以我决定添加一个更新。

Starting with KitKat (4.4), you can now emulate cards without a secure element. 从KitKat(4.4)开始,您现在可以仿真没有安全元素的卡。

It is called Host-based Card Emulation ( Hce ) and with that you can emulate a ISO 14443 type A card.. Like a desfire card. 它被称为基于主机的卡仿真( Hce ),可以用来模拟ISO 14443 A型卡。

There are two small caveats: 有两个小警告:

  • your reader must issues, just after polling the "card", a ISO SELECT (aid), with a fixed application id (aid) of your choice. 您的读者必须在轮询“卡”后立即发出带有您选择的固定应用程序ID(帮助)的ISO SELECT(帮助)。 This AID must be registered in your app manifest. 此AID必须在您的应用清单中注册。 Android will intercept this ISO SELECT, read the aid, and call you only if it matches with the one in your manifest. Android会拦截此ISO SELECT,阅读辅助信息,并仅在清单中的辅助信息与之匹配时才打电话给您。 Then you can exchange anything, it does not even have to be ISO APDUs (ISO 14443 encapsulation is done by android). 然后,您可以交换任何东西,它甚至不必是ISO APDU(ISO 14443封装由android完成)。 So, for example, if you want to , you can even emulate the challenge response authentication of desfire (0xA0 key_num, 0xAF challenge, 0xAF response, 0x00 session_key) 因此,例如, 如果您愿意 ,甚至可以模拟desfire的质询响应身份验证(0xA0 key_num,0xAF质询,0xAF响应,0x00 session_key)

  • you cannot rely on the UID (but you don't, right? This is a bad practice anyway, so no-one does it... right? :) ) because it is random, and it changes constantly (not inside a single session, of course, but...) 您不能依赖UID(但是您不对,对吗?无论如何这是一种不好的做法,所以没有人这样做...对吗?:)),因为它是随机的,并且会不断地变化(而不是在一个内部)会话,当然,但是...)

We are emulating our desfire cards, and the only change we had to do was to switch from our initial desfire select application (0x5A) to a ISO SELECT (0x00 0xA4 0x04). 我们正在模拟desfire卡,唯一要做的更改是从最初的desfire选择应用程序(0x5A)切换到ISO SELECT(0x00 0xA4 0x04)。

Emulating authentication (the challenge-response thing) can be tricky, but we had already done it "the other way around" (using NFC to read desfire cards), so it was easy for us. 模拟身份验证(挑战响应事件)可能很棘手,但是我们已经“另辟(径”了(使用NFC读取除火卡),因此对我们来说很容易。

And if you rely on the card UID for authentication.. it's a good time to change it :) 如果您依靠卡UID进行身份验证,那么现在是更改它的好时机了:)

Given your situation, i would say Android SDK is more than sufficient to solve your problem. 考虑到您的情况,我想说Android SDK足以解决您的问题。 There are two parts to your case: 您的案例分为两部分:

  1. Reading the information from the existing cards. 从现有卡中读取信息。
  2. Making an app with the information you have read from the cards. 使用您从卡中读取的信息制作应用。

Part 1: 第1部分:

Your only worry has to be in reading the DESFire card. 您唯一需要担心的就是读取DESFire卡。 If the information in the DESFire card is stored in NDEF format, it makes things even more easy. 如果DESFire卡中的信息以NDEF格式存储,它将使事情变得更加容易。

Ndef is a class in the SDK which can be used to retrieve the information in NdefMessage type which you can then use to save the retrieved information into your storage facility, be it a local database, or a remote database, or just in the application memory. Ndef是SDK中的一个类,可用于检索NdefMessage类型的信息,然后可将其用于将检索到的信息保存到本地数据库,远程数据库或仅在应用程序内存中的存储工具。

The above is under the assumption the card is not protected. 以上是在该卡未受保护的假设下。 If it is, then you have to use transceive function to interact using raw byte communication. 如果是这样,则必须使用transceive功能通过原始字节通信进行交互。 This would unlock for the rest of the information to be read. 这将解锁以读取其余信息。 From here you can read the NDEF records. 从这里您可以阅读NDEF记录。

Part 2: My suggestion is skip the card emulation aspect of it. 第2部分:我的建议是跳过其卡仿真方面。 You are going to hit a wall at some point in time. 您将在某个时间点碰壁。

If the device that has been reading the card in the existing solution is attached to an android device, then Android Beam is the way to go. 如果在现有解决方案中已在读取卡的设备已连接到android设备,则可以使用Android Beam。 Which is nothing but Android App to Android App communication! 除了Android App与Android App的交流之外,别无所求! Android already does the heavy lifting, so most of your work is going to be easy. Android已经完成了繁重的工作,因此您的大部分工作将变得很容易。

The information on the card can be stored as ndef messages and sent through beam, or you can simply create a custom object and send it through. 卡上的信息可以存储为ndef消息并通过Beam发送,或者您可以简单地创建一个自定义对象并将其发送出去。

You may want to look at Mifare4Mobile, the initiative set up to transition from Mifare cards to NFC devices: 您可能想看看Mifare4Mobile,它是从Mifare卡过渡到NFC设备的主动性:

http://mifare4mobile.org/ http://mifare4mobile.org/

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

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