简体   繁体   English

存取MIFARE DESFire卡

[英]Access MIFARE DESFire Card

How can I access a MIFARE DESFire card using an Android phone as NFC reader? 如何使用Android手机作为NFC读取器访问MIFARE DESFire卡? I am planning to develop an android application (for payment) on Android phone. 我打算在Android手机上开发一个Android应用程序(用于付款)。

The DESFire operations (Authentication, Read and Write) that I want to perform using the Android phone need a SAM card, I thought I can emulate that SAM card in the phone using HCE. 我想使用Android手机执行的DESFire操作(身份验证,读取和写入)需要SAM卡,我想我可以使用HCE在手机中模拟SAM卡。

DESFire/DESFire EV1 cards communicate on top of the ISO/IEC 14443-4 data exchange protocol (ISO-DEP). DESFire / DESFire EV1卡在ISO / IEC 14443-4数据交换协议(ISO-DEP)之上进行通信。 Therefore, on Android devices, they can be accessed through the IsoDep class. 因此,在Android设备上,可以通过IsoDep类访问它们。 So once you get your tag handle ( Tag object), you can instantiate the IsoDep object using: 因此,一旦获得标签句柄( Tag对象),就可以使用以下方法实例化IsoDep对象:

Tag tag = ...  // (e.g. get from NFC discovery intent)
IsoDep isoDep = IsoDep.get(tag);

You can connect to the card and use the IsoDep object's transceive() method to send commands to (and receive responses from) the card: 您可以连接到卡,并使用IsoDep对象的transceive()方法向卡发送命令(并从卡接收响应):

isoDep.connect();
byte[] response = isoDep.transsceive(command);

You can either use the DESFire native command set, the DESFire APDU wrapped native command set or the ISO/IEC 7816-4 command set (see the DESFire datasheet for more details). 您可以使用DESFire本机命令集,DESFire APDU包装的本机命令集或ISO / IEC 7816-4命令集(有关更多详细信息,请参见DESFire数据表)。 Due to known problems with the presence detection on some devices (which automatically sends READ BINARY APDUs to detect if a tag is still available), I strongly suggest to use either the APDU wrapped native command set or the ISO/IEC 7816-4 command set (see this question ). 由于某些设备上的状态检测存在已知问题(它会自动发送READ BINARY APDU以检测标记是否仍然可用),因此我强烈建议使用APDU包装的本机命令集或ISO / IEC 7816-4命令集(请参阅此问题 )。

Now, the problematic part is the SAM. 现在,有问题的部分是SAM。 A SAM (Secure Access Module) is a secure smartcard chip that holds keys and performs security critical parts of the communication with the DESFire card. SAM(安全访问模块)是一种安全的智能卡芯片,可保存密钥并执行与DESFire卡通信的安全关键部分。 You cannot simply "emulate" such a SAM using host-based card emulation. 您不能简单地使用基于主机的卡仿真来“仿真”这样的SAM。 That would not make much sense, as the whole idea of HCE is route communication from contactless smartcard readers through the NFC interface to the (insecure) application processor . 这没有多大意义,因为HCE的整个思想是将通信从非接触式智能卡读取器通过NFC接口路由到(不安全的)应用处理器 Implementing the SAM functionality on the application processor would defeat the whole purpose (ie high security level) of a dedicated SAM chip. 在应用处理器上实现SAM功能将破坏专用SAM芯片的整个目的(即高安全级别)。 Moreover, in order to emulate SAM functionality, you would not need HCE as you could directly store the credentials for access to the DESFire card within your application. 此外,为了模拟SAM功能,您不需要HCE,因为您可以直接在应用程序中存储用于访问DESFire卡的凭据。

An option that you might have is to use a cloud-based secure element approach. 您可能有一个选择是使用基于云的安全元素方法。 Thus, you could have the SAM functionality on a server/in the cloud and route the communication with your DESFire card though your app to that server. 因此,您可以在服务器/云中具有SAM功能,并通过应用程序将与DESFire卡的通信路由到该服务器。

byte[] command = receiveCommandFromBackend();  // receive command from server/cloud over the network
byte[] response = isoDep.transsceive(command);
sendResponseToBackend(response); // send response to server/cloud over the network

To summarize this: You don't need HCE. 总结一下:您不需要HCE。 Depending on your security requirements, you could either store the credentials for access to the DESFire cards within your app (note that an attacker might be able to extract that information) or you could use a cloud-based SE approach to shift the security critical parts to an online backend system (but that would typically require continuous network access during communication with the card). 根据您的安全要求,您可以在应用程序中存储用于访问DESFire卡的凭据(请注意,攻击者可能能够提取该信息),也可以使用基于云的SE方法来转移安全关键部分到在线后端系统(但是在与卡通信期间通常需要连续的网络访问)。

Yet another approach would of course be to use a local secure element within your device, but that would require that you have access to it which is usually not easy/impossible. 当然,还有另一种方法是在设备中使用本地安全元素,但这将要求您有权访问它,这通常不容易/不可能。

Mifare DESFire is not a standard for payment, you should rely on ISO14443-4 (ie ISO7816-4) instead, at least that's what all the big names did. Mifare DESFire不是付款的标准,您应该依赖ISO14443-4(即ISO7816-4),至少这是所有知名人士所做的。 These are also the standards that HCE is based upon. 这些也是HCE所基于的标准。 Having a payment system based on DESFire would probably be something very specific. 拥有基于DESFire的支付系统可能非常具体。 The problem with DESFire is that it is proprietary technology. DESFire的问题在于它是专有技术。 Developing a payment app using HCE is very challenging in terms of security. 在安全性方面,使用HCE开发支付应用程序非常具有挑战性。

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

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