简体   繁体   English

发送数据、使用 HCE 还是使用安全元件? (安卓,Kotlin,Mifare 1k)

[英]Sending data, using HCE, or using secure element? (Android, Kotlin, Mifare 1k)

I'm trying to implement the functionality for emulating a Mifare One (1K/S50, ISO14443A) chip to be able to use a phone with NFC capability instead of a physical Mifare card or, if possible sending only the data to the reader.我正在尝试实现模拟 Mifare One(1K/S50,ISO14443A)芯片的功能,以便能够使用具有 NFC 功能的手机而不是物理 Mifare 卡,或者如果可能只将数据发送到读卡器。

I have this type of reader/writer: https://www.evelta.com/er302-high-frequency-nfc-writer-usb/我有这种类型的读写器: https://www.evelta.com/er302-high-frequency-nfc-writer-usb/

After looking around on forums, stackoverflow questions I found this article to be the best example:在浏览了论坛,stackoverflow 问题后,我发现这篇文章是最好的例子:

https://medium.com/the-almanac/how-to-build-a-simple-smart-card-emulator-reader-for-android-7975fae4040f https://medium.com/the-almanac/how-to-build-a-simple-smart-card-emulator-reader-for-android-7975fae4040f

I implemented the HCE part, run the program, and the reader beleives my phone is a Mifare chip, so far so good.我实现了 HCE 部分,运行程序,读者认为我的手机是 Mifare 芯片,到目前为止一切都很好。

My problems:我的问题:

  • No matter what "standard" Authentication key I tried to use...it gives me Auth error.无论我尝试使用什么“标准”身份验证密钥......它都会给我身份验证错误。 I read this question about Auth: Authentication failure for Mifare 1K NFC tag using ACR122U NFC reader , it works on a physical Mifare card...but I don't know how to set or get to know the keys for the emulated one.我读到了这个关于 Auth: Authentication failure for Mifare 1K NFC tag using ACR122U NFC reader的问题,它适用于物理 Mifare 卡......但我不知道如何设置或了解模拟卡的密钥。

  • I don't get why this example emulates that exact Mifare chip type...even breakpoints don't work in the APDUService, but the reader detecting a Mifare cheap somehow.我不明白为什么这个例子模拟了确切的 Mifare 芯片类型......即使断点在 APDUService 中也不起作用,但是阅读器以某种方式检测到 Mifare 便宜。

After reading about it, I get I can't 100% emulate a physical card, so I have to send all the data I want in my APDU response with the service somehow (I beleive it's the transreceive part).读完之后,我发现我不能 100% 模拟物理卡,所以我必须以某种方式在我的 APDU 响应中发送我想要的所有数据(我相信这是收发部分)。

However I can't even authenticate.但是我什至无法进行身份验证。

I tried to look for other possible solutions:我试图寻找其他可能的解决方案:

  • AndroidBeam : Android - Android p2p...sounds simple, relatively high-level API, but it's being deprecated, moreover it's not guaranted that the reader will even use Android...it might be a 'simple' USB reader hardware like the one I use. AndroidBeam : Android - Android p2p...sounds simple, relatively high-level API, but it's being deprecated, moreover it's not guaranted that the reader will even use Android...it might be a 'simple' USB reader hardware like the one我用。

  • SecureElement : Ironically...it seems to be the most recommended, I read that 'yes, it's possible for mifare' and things like that, yet I couldn't find a good example of it and the official Google docs don't have any good example. SecureElement :具有讽刺意味的是……它似乎是最推荐的,我读到“是的,mifare 有可能”之类的东西,我找不到一个很好的例子,官方的谷歌文档也没有任何好的例子。 I read that it's for "ISO/IEC 7816-4", but Mifare 1K is ISO14443A, so I'm a bit sceptic about this API.我读到它适用于“ISO/IEC 7816-4”,但 Mifare 1K 是 ISO14443A,所以我对这个 API 有点怀疑。

  • " Simply " sending the data to the reader : If I could just simply "push" the data out to the reader when it's reading the phone without complicating the matter or emulating anything...it would be great but I don't know if it's even possible. 简单地”将数据发送给阅读器:如果我可以在阅读手机时简单地将数据“推送”给阅读器,而不会使事情复杂化或模拟任何事情......那就太好了,但我不知道这甚至是可能的。 This whole NFC topic seems to be more and more complex.整个 NFC 话题似乎越来越复杂。

So alltogether I only need to do one thing: taking the data and send it to the reader.所以总的来说,我只需要做一件事:获取数据并将其发送给阅读器。

I realized it's a fairy tale like illusion to beleive it's as simple as it sounds, still, I hope there is a way to do it.我意识到这是一个童话般的幻想,相信它听起来很简单,但我希望有办法做到这一点。

If I could send the data in it's own, without emulating Mifare or anything...after all what matters is that the data on the card, not the type of the chip, the more simple the solution will be, the better.如果我可以自己发送数据,而不用模拟 Mifare 或其他任何东西……毕竟重要的是卡上的数据,而不是芯片的类型,解决方案越简单越好。

Sorry for possible English grammar mistakes.对于可能的英语语法错误,我们深表歉意。

The problem is you cannot use HCE on Android to emulate a Mifare Classic 1K ( https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf ) as this is a custom Type NFC card. The problem is you cannot use HCE on Android to emulate a Mifare Classic 1K ( https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf ) as this is a custom Type NFC card. As HCE is about emulating Type 4 cards.因为 HCE 是关于模拟 Type 4 卡。 See https://developer.android.com/guide/topics/connectivity/nfc/hce#SupportedProtocols请参阅https://developer.android.com/guide/topics/connectivity/nfc/hce#SupportedProtocols

And the below image helps understand the type.下图有助于理解类型。

在此处输入图像描述

You can see this from it's datasheet, nowhere does it talk about AID's and standard Type 4 NFC commands您可以从它的数据表中看到这一点,它没有谈论 AID 和标准 4 型 NFC 命令

Though Type 2 and Type 4 can share the Anti Collision mechanism and Reading the UID (which is part of the process) any other access methods are not shared.尽管 Type 2 和 Type 4 可以共享防冲突机制和读取 UID(这是该过程的一部分),但不共享任何其他访问方法。

Type 4 Spec for reference is at http://apps4android.org/nfc-specifications/NFCForum-TS-Type-4-Tag_2.0.pdf供参考的 4 类规范位于http://apps4android.org/nfc-specifications/NFCForum-TS-Type-4-Tag_2.0.pdf

I have seen some USB readers that offer on reader emulation of other card types but not HCE where the host does the emulation not the NFC hardware.我见过一些 USB 读卡器,它们提供其他卡类型的读卡器仿真,但不提供 HCE,主机进行仿真而不是 NFC 硬件。

The Authentication on Type 4 Cards or emulated ones is handled differently.对 4 类卡或模拟卡的身份验证处理方式不同。

You can emulate a MIFARE DESFire Card as that is a Type 4 card.您可以模拟 MIFARE DESFire 卡,因为它是 4 类卡。

The specs of your card reader are not documented well and it looks very "lite" and that it does not support any of the higher level protocols needed to talk to non Mifare Classic cards.您的读卡器的规格没有很好地记录,它看起来非常“精简”,并且它不支持与非 Mifare Classic 卡通信所需的任何更高级别的协议。 It could support them but as Mifare protocol was the original spec, it could be possible for it to be and old design and only support the Mifare protocol.它可以支持它们,但由于 Mifare 协议是原始规范,它可能是旧设计并且仅支持 Mifare 协议。

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

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