简体   繁体   English

ISO 14443 A型卡使用Android读/写

[英]ISO 14443 Type A Card Read/Write using Android

I am trying to write an Android App to read/write an NFC Card which supports the ISO 14443 Type A standard. 我正在尝试编写一个Android应用程序来读取/写入支持ISO 14443 A类标准的NFC卡。 After a thorough search it seems that the only option left now for me is to use the IsoDep class and its transceive method by sending the APDU commands. 经过彻底的搜索后,似乎现在唯一的选择是通过发送APDU命令来使用IsoDep类及其收发方法。 The card that I have is a SmartCafe dual interface card supporting the ISO 14443 and ISO 7816 standards. 我的卡是支持ISO 14443和ISO 7816标准的SmartCafe双接口卡。

Then I stated to look for APDUs for the 14443 standard. 然后我说要寻找14443标准的APDU。 I have found this page with a good resource regarding this. 我发现这个页面有很好的资源。 However, the problem is the lack of any example APDUs. 但问题是缺少任何示例APDU。

There are several questions and answers with APDUs (eg this ) in the stackoverflow which I tried with no luck. 在stackoverflow中有几个问题和答案与APDU(例如这个 ),我试过没有运气。

A brute force attempt revealed the following result with a select command: 6F108408A000000003000000A5049F6501FF9000 which looks like a file control information for the card. 强力尝试通过选择命令显示以下结果: 6F108408A000000003000000A5049F6501FF9000 ,它看起来像卡的文件控制信息。 But I am struggling on how to interpret this information. 但我正在努力解释这些信息。

I am also struggling with the flow to work with the card. 我也在努力解决使用该卡的问题。 So far I have understood: 到目前为止,我已经明白:

  1. I need to select a file and 我需要选择一个文件和
  2. then read from the file or write into the file. 然后从文件中读取或写入文件。

The card is a new one and might not have any other file or information other than the file control information. 该卡是新的,可能没有除文件控制信息之外的任何其他文件或信息。 So which PDU can be used to create a file in a specific location and which PDU can be used to read from that file? 那么哪个PDU可用于在特定位置创建文件,哪个PDU可用于从该文件中读取?

The card you are using (SmartCafe dual interface) is a JavaCard. 您正在使用的卡(SmartCafe双接口)是一个JavaCard。

Your attempted SELECT command must have been something like: 您尝试的SELECT命令必须是这样的:

00 A4 04 00 00

or 要么

00 A4 04 00 08 A000000003000000 00

What you see in response to that SELECT command is the FCI of the GlobalPlatform card manager: 您在响应SELECT命令时看到的是GlobalPlatform卡管理器的FCI:

6F 10 (FCI template)
  84 08 (Application DF name)
    A000000003000000
  A5 04 (Proprietary data)
    9F65 01 (Maximum length of data field in command message)
      FF (256)
9000 (status=no error)

With that type of card, the concept of files does not really exist by default (so just selecting a file and reading/writing to it won't normally work). 对于这种类型的卡,默认情况下文件的概念并不存在(因此只选择一个文件并读取/写入它通常不起作用)。 Instead this card contains Java-based applications that you can interact with using APDU commands. 相反,此卡包含可以使用APDU命令进行交互的基于Java的应用程序。

So the typical flow to interact with an application would be: 因此,与应用程序交互的典型流程是:

  1. SELECT an application based on its AID (application identifier). 基于其AID(应用程序标识符)选择应用程序。 In terms of ISO 7816-4, the AID can be seen as a DF name and you issue a SELECT command for that specific DF name. 就ISO 7816-4而言,可以将AID视为DF名称,并为该特定DF名称发出SELECT命令。

  2. Send arbitrary APDUs (according to ISO 7816-4, with either inter-industry or proprietary coding) to the selected application. 将任意APDU(根据ISO 7816-4,采用行业间或专有编码)发送到所选应用程序。

  3. The Java-based (actually JavaCard-based, where JavaCard is an extended sub-set of the Java language) application receives the command, decodes and processes it and generates a response. 基于Java(实际上基于JavaCard,JavaCard是Java语言的扩展子集)应用程序接收命令,解码并处理它并生成响应。

  4. The card sends the application's response back to the reader. 卡将应用程序的响应发送回阅读器。

Now there is several possiblities: 现在有几种可能性:

  1. The card is pre-prorgammed for a specific purpose and you don't have the keys to access the card manager. 该卡是针对特定目的进行预先安装的,您没有钥匙可以访问卡管理器。
    In that case, you would need to know how to interface the application that's on the card. 在这种情况下,您需要知道如何连接卡上的应用程序。 Ideally, the application documentation would show you what AID you need to select and what commands you can send. 理想情况下,应用程序文档会显示您需要选择的AID以及您可以发送的命令。

  2. The card is pre-programmed for a specific purpose but you do have the keys to access the card manager -- and, of course, you do not want to use the pre-programmed application but want to use your own application (otherwise the same as in 1. applies). 该卡是为特定目的预编程的,但您确实有钥匙可以访问卡管理器 - 当然,您不想使用预编程的应用程序但想要使用您自己的应用程序(否则相同)如1.适用)。
    In that case, you could create your own JavaCard application (or use some ready-made application that fits your purpose) and install it onto the card (eg using open tools like GPShell ). 在这种情况下,您可以创建自己的JavaCard应用程序(或使用一些适合您目的的现成应用程序)并将其安装到卡上(例如使用像GPShell这样的开放工具)。 Then you can access the card using the interface you defined yourself. 然后,您可以使用自己定义的界面访问该卡。

  3. The card is not pre-programmed for a specific purpose and you do have the keys to access the card manager. 该卡没有预先编程为特定目的和有访问卡管理的关键。
    In that case, the only option you have is to create your own application as in 2. 在这种情况下,您唯一的选择是创建自己的应用程序,如2所示。

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

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