简体   繁体   English

NFC读卡器无法读取加密卡仿真数据

[英]NFC Reader Cannot Read Encrypted Card Emulation Data

I'm currently using Seeed Studio's NFC Shield v2 and Arduino Uno R3. 我目前正在使用Seeed Studio的NFC Shield v2和Arduino Uno R3。 Here's the code from the sketch that I'm using to read. 这是我正在阅读的草图中的代码。 It based on the example provided by Seeed Studio Android HCE libraries: 它基于Seeed Studio Android HCE库提供的示例:

void loop() {
    ...
    uint8_t response[510];
    uint8_t responseLen = sizeof(response);
    success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), 
              response, &responseLen);

    if(success) {
      Serial.print("Response Length: "); Serial.println(responseLen);
      // nfc.PrintHexChar(response, responseLen);
      printResponse(response, responseLen);
    } else Serial.println("Failed sending SELECT AID"); 
  } else Serial.println("Didn't find anything!");
  delay(1000);
}

On the Android app that I have, I'm extending Android Developer's HCE example by adding digital signatures and AES encryption. 在我的Android应用程序上,我通过添加数字签名和AES加密来扩展Android Developer的HCE示例。 I know for a fact that the app is readable if I don't add the AES encryption, and can verify the contents using a Python script. 我知道如果我不添加AES加密,应用程序是可读的,并且可以使用Python脚本验证内容。 Once I add the encryption, the Arduino reads nothing from the app even though the Android device outputs logs that show the APDU was requested. 一旦我添加加密,即使Android设备输出显示请求APDU的日志,Arduino也不会从应用程序中读取任何内容。

There seems to be two culprits: 似乎有两个罪魁祸首:

  1. Response[510] is not the right size. Response[510]的大小不合适。
  2. The encrypted data being sent to Arduino is too big. 发送到Arduino的加密数据太大了。

I changed the Response[] to various values such as 80, 1022, 2046, 8196, etc. However, the higher the values, the more freaked out Arduino becomes. 我将Response[]更改为各种值,例如80, 1022, 2046, 8196,等。但是,值越高,Arduino变得越吓坏。 Too low of a value, and nothing happens. 价值太低,没有任何反应。 510 seems to be the magic number. 510似乎是神奇的数字。 I've logged a length count of my data being transferred: 我记录了正在传输的数据的长度计数:

  • Without AES encryption, data length was 197 bytes which outputted fine on the Arduino serial console. 没有AES加密,数据长度为197 bytes ,在Arduino串行控制台上输出正常。
  • With AES encryption, data length was 268 bytes and resulted in an output of "Failed sending SELECT AID", which is a false error since I was able to retrieve the AID request and APDU header. 使用AES加密,数据长度为268 bytes ,导致输出“发送SELECT AID失败”,这是一个错误的错误,因为我能够检索AID请求和APDU标头。

What seems to be the problem and how can I go about fixing it, or at least have some workaround? 什么似乎是问题,我该如何解决它,或者至少有一些解决方法?


UPDATE: If I were to make the data being sent less than 245 bytes, the Arduino would output the data on the Serial console. 更新:如果我要发送的数据少于245个字节,Arduino将在串行控制台上输出数据。 Once it made it 246 bytes, it fails and outputs "Failed sending SELECT AID". 一旦它成为246字节,它就会失败并输出“发送SELECT AID失败”。

I still don't know how to work around this "limitation" on the Arduino but I've found a workaround. 我仍然不知道如何在Arduino上解决这个“限制”,但我找到了一个解决方法。 The key is to keep the data less than 245 bytes . 关键是保持数据少于245 bytes

What I did is, instead of encrypting both the data and the signature together, I've decided to just encrypt the data and appended the signature to the end of the data along with something that I can use to delimit with (ie. "::"). 我所做的是,不是一起加密数据和签名,我决定只加密数据并将签名附加到数据的末尾以及我可以用来划分的东西(即“:”: :“)。

This combination resulted to be a total 206 bytes , and it is being read and passed on as serial data to my Python script. 这个组合总共有206 bytes ,它被读取并作为串行数据传递给我的Python脚本。

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

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