Android的NFC IsoDep读取文件内容 [英] Android NFC IsoDep read file content

查看:3031
本文介绍了Android的NFC IsoDep读取文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读一些信息出来的 ISO / IEC 14443 A类卡。

I'm trying to read some information out of an ISO/IEC 14443 Type A card.

该显卡搭配Android应用程序分析后的 NFC TagInfo ,我发现,应用程序(AID:15845F)有特定的文件(文件编号:01)。我需要

After analysing the card with the android app NFC TagInfo, I found out, that the application (AID: 15845F) has the particular file (File ID: 01) that I need.

我已经成功地连接到卡上,选择应用程序。

I already managed to connect to the card and to select the application.

String action = getIntent().getAction();
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action))
{
    Tag tagFromIntent = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);  
    Log.i(TAG, Arrays.toString(tagFromIntent.getTechList()));

    IsoDep isoDep = IsoDep.get(tagFromIntent);
    try
    {
        isoDep.connect();

        byte[] SELECT = { 
            (byte) 0x00, // CLA = 00 (first interindustry command set)
            (byte) 0xA4, // INS = A4 (SELECT)
            (byte) 0x04, // P1  = 04 (select file by DF name)
            (byte) 0x0C, // P2  = 0C (first or only file; no FCI)
            (byte) 0x06, // Lc  = 6  (data/AID has 6 bytes)
            (byte) 0x31, (byte) 0x35,(byte) 0x38,(byte) 0x34,(byte) 0x35,(byte) 0x46 // AID = 15845F
        };

        byte[] result = isoDep.transceive(SELECT);
        Log.i(TAG, "SELECT: " + bin2hex(result));

        if (!(result[0] == (byte) 0x90 && result[1] == (byte) 0x00))
            throw new IOException("could not select application");

        byte[] GET_STRING = { 
            (byte) 0x00, // CLA Class
            (byte) 0xB0, // INS Instruction
            (byte) 0x00, // P1  Parameter 1
            (byte) 0x00, // P2  Parameter 2
            (byte) 0x04  // LE  maximal number of bytes expected in result
        };

        result = isoDep.transceive(GET_STRING);
        Log.i(TAG, "GET_STRING: " + bin2hex(result));
    }
}

但我的第二个查询失败,出现错误code:6A86(不正确的参数P1-P2)。我已经用Google搜索了很多,发现不同的单证(如: http://bit.ly/180b6tB ),但我只是不明白,我怎么能实施正确的值 P1 P2

But my second query fails with the error code: 6A86 (Incorrect parameters P1-P2). I already googled a lot and found different documentations (for example: http://bit.ly/180b6tB), but I just could not understand, how I can implement the right values for P1 and P2.

修改

该卡采用标签式的 NFC TagInfo :ISO / IEC 14443-4智能卡而言,MIFARE DESFire非EV1(MF3ICD81)

Tag type of the card using NFC TagInfo: ISO/IEC 14443-4 Smart Card, Mifare DESFire EV1 (MF3ICD81)

在源$ C ​​$ C使用的SELECT命令实际上并没有失败,而是它返回一个9000的响应。所以这就是为什么我认为一切工作正常。

The SELECT command as used in the source code actually did not fail, but instead it returned a 9000 response. So this is why I assumed that everything is working fine.

您提到的 NFC TagInfo 不提供的正确的值DF-名称等是值 0x313538343546 正确的,你是怎么做找到它?

You mentioned that NFC TagInfo does not provide the correct values for DF-names etc. Is the value 0x313538343546 correct and how did you find it out?

你能提供给我一个的的描述,我怎么能得到我想要的数据?是否有我可以用它来读取正确的DF-名称,艾滋病等其他Android应用程序?基本上,我需要获得一个文件出的一个应用程序。我还可以提供所收集的信息的一些截图 NFC TagInfo ,如果需要的话。

Can you provide me a short description, how I could get the data I want? Are there any other android apps that I can use to read the right DF-names, AIDs etc.? I basically need to get ONE file out of ONE application. I could also provide some screenshots of the information gathered with NFC TagInfo, if needed.

编辑2

我已经重写了命令,但(你提出的),让他们在APDU包装。因此,我结束了有两个不同的命令,一个是应用程序的选择,另外一个是文件的选择

I have rewritten the commands, but (as you proposed) kept them in the APDU wrapper. Therefore I ended up having two different commands, one for the selection of the application and the other one for the selection of the file.

private final byte[] NATIVE_SELECT_APP_COMMAND = new byte[]
{
    (byte) 0x90, (byte) 0x5A, (byte) 0x00, (byte) 0x00, 3,  // SELECT
    (byte) 0x5F, (byte) 0x84, (byte) 0x15, (byte) 0x00      // APPLICATION ID
};
private final byte[] NATIVE_SELECT_FILE_COMMAND = new byte[]
{
    (byte) 0x90, (byte) 0xBD, (byte) 0x00, (byte) 0x00, 7,  // READ
    (byte) 0x01,                                            // FILE ID
    (byte) 0x00, (byte) 0x00, (byte) 0x00,                  // OFFSET
    (byte) 0x00, (byte) 0x00, (byte) 0x00,                  // LENGTH
    (byte) 0x00
};

寻求一个教程本地Mifire-DESFIRE命令并不成功,所以我坚持下面的教程:的 http://noobstah.blogspot.de/2013/04/mifare-desfire-ev1-and-android.html

本教程提供了一个卡的真伪,我停用,并且还使用了收发方式,这对于我的理解是不是正确的方法来执行本地命令?哪一种方法,purhaps甚至code的这段,用于执行本机命令?安卓级我应该使用哪一个?

This tutorial provides a card authentification, which I disabled, and also uses the transceive method, which for my understanding is not a proper way for executing native commands? Which method, purhaps even code snippit, is used for executing native commands? Which Android-Class should I use?

我已经重写了教程中提供的类并将其上传到引擎收录。执行我下面的结果得到了类之后。

I have rewritten the class provided in the tutorial and uploaded it to pastebin. After executing the class I've got following results.

Select APPLICATION: 9100
Read DATA: 91AE

在这一点上我很卡,不知道什么步骤我应该做的下一步。当时其实是错误或者说什么样的变化在我应该执行,得到我想要的数据?

At this point I am quite stuck and do not know what steps I should do next. Was is actually the error or rather what changes in the queries should I perform, to get the data I want?

推荐答案

由于从NFC TagInfo和您尝试使用这些命令中提取的信息,我认为该卡是MIFARE DESFire非EV1。是否正确?

Given the information you extracted from NFC TagInfo and the commands you are trying to use, I assume the card is MIFARE DESFire EV1. Correct?

关于你的选择命令:NFC TagInfo目前不读了的DESFire EV1的ISO命令集使用的DF名称值。因此,我认为在DF-名称的设置此应用程序实际上是0x313538343546,否则SELECT命令应该失败。但是请注意,此值绝不可源自于NFC TagInfo所示的DESFire AID!事实上,DF-name是应用程序创建过程中定义一个单独的值。 (这是从previous的DESFire版本不同。)

Regarding your selection command: NFC TagInfo does not currently read the DF name value used in the ISO command set for DESFire EV1. Thus, I assume that the DF-name that's setup for this application is actually 0x313538343546, otherwise the SELECT command should fail. Note, however, that this value is by no means derivable from the DESFire AID shown in NFC TagInfo! In fact the DF-name is a seperate value defined during application creation. (This is different from the previous DESFire version.)

关于你的READ BINARY命令:你使用会暗示你previously所选文件的命令。但是,你只能选择的应用程序。因此,你要么需要发出一个SELECT命令的数据文件或READ BINARY命令中使用短文件ID:

Regarding your READ BINARY command: The command you used would imply that you previously selected a file. However, you only selected the application. Thus, you would either need to issue a SELECT command for the data file or use a short file ID within the READ BINARY command:

byte[] READ_BINARY = { 
        (byte) 0x00, // CLA Class
        (byte) 0xB0, // INS Instruction
        (byte) 0x80, // P1  (indicate use of SFI)
        (byte) 0x01, // P2  (SFI = 0x01)
        (byte) 0x04  // LE  maximal number of bytes expected in result
};


然而,当涉及到的DESFire(EV1),我建议,而不是使用ISO 7816-4,你宁愿坚持DESFire非原生指令集(无论是直接或包装)的APDU。


However, when it comes to DESFire (EV1) I suggest that you rather stick to the DESFire native command set (either direct or wrapped) instead of using ISO 7816-4 APDUs.

使用本机命令​​集,你会得到MIFARE DESFire非的全部功能。命令包裹通过嵌入原生的DESFire命令到ISO 7816-4 APDU结构完成的。该包装的命令是这样的:

With the native command set, you get the full functionality of MIFARE DESFire. Command wrapping is done by embedding native DESFire commands into a ISO 7816-4 APDU structure. The wrapping command looks like this:

0x90 CMD 0x00 0x00 LEN CMD-PARAM 0x00

其中cmd是本机的DESFire指挥和CMD-PARAM是命令的参数。响应为:

Where CMD is the native DESFire command and CMD-PARAM are the commands parameters. The response is:

[DATA] 0x91 STATUS

如果状态是本地的DESFire状态code。如果状态是0xAF执行,则可以通过发出以下命令获得剩余的响应数据:

Where status is the native DESFire status code. If STATUS is 0xAF, you can get the remaining response data by issuing this command:

0x90 0xAF 0x00 0x00 0x00

因此​​,在你的情况,你会发出一个选择应用程序的命令为您的应用0x15845F(考虑到不同字节顺序!):

So in your case, you would issue a select application command for your application 0x15845F (mind the different byte order!):

0x90 0x5A 0x00 0x00 3 0x5F 0x84 0x15 0x00
   |SELECT|          |APPLICATION ID|

然后,你要读取数据文件0×01(整个文件,开始于偏移0):

Then, you want to read the data file 0x01 (whole file, starting at offset 0):

0x90 0xBD 0x00 0x00 7 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    |READ|           |FILE|    OFFSET    |    LENGTH    |


关于你提到的问题,如何获得ISO DF名和ISO FID的为您的应用程序,你可以试试下面的命令:


Regarding your question how to get the ISO DF names and ISO FIDs for your application, you can try the following commands:

选择主应用程序:

905A00000300000000

获取应用程序,包括它们的DF名称:

Get applications including their DF names:

906D000000

选择您的应用程序:

905A0000035F841500

获取的DESFire FID的:

Get DESFire FIDs:

906F000000

获取ISO FID的:

Get ISO FIDs:

9061000000


您可以随时使用IsoDep对象的收发()方法。 IsoDep(即ISO / IEC 14443-4)的反正用(本机的DESFire命令,包本机命令和ISO 7816-4命令)。


You can always use the transceive() method of the IsoDep object. IsoDep (i.e. ISO/IEC 14443-4) is used anyways (for native DESFire commands, for wrapped native commands and for ISO 7816-4 commands).

您从卡(0xAE)收到的错误code表示验证错误(见本技术资料了解更多信息:的 DESFire非)。因此,该文件允许已通过验证只读(参见NFC TagInfo所示的准入条件)。

The error code you received from the card (0xAE) indicates an authentication error (see this datasheet for further information: DESFire). Thus, the file allows authenticated read only (see the access conditions shown in NFC TagInfo).

因此​​,为了读取这个文件,你将需要实现的认证过程。

Thus, in order to read this file, you will need to implement the authentication procedure.

这篇关于Android的NFC IsoDep读取文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆