gpt4 book ai didi

smartcard - 智能卡读卡器 T0 T1 APDU 级通信

转载 作者:行者123 更新时间:2023-12-04 15:21:32 31 4
gpt4 key购买 nike

我很难理解我必须使用什么协议(protocol)来与卡 T0 或 T1 通信?所以,如果我错了,请纠正我,但如果卡同时支持这两种协议(protocol),阅读器实际上会自行决定使用什么协议(protocol)与卡进行通信。

所以我现在的逻辑是:

// if ATR(T1) -> set_params(T1 structure) -> T1 APDU communication
// if ATR(T0) -> set_params(T0 structure) -> T0 APDU communication

但事实证明,这个逻辑是错误的,它意外地适用于大多数读者。我刚刚发现即使卡 ATR 返回 T1 也期望 T0 通信的读卡器。

问:确定使用什么协议(protocol)的逻辑是什么?如果它背后有规范,请你指出来。

编辑:我忘了提到我的代码在操作系统之前处于预启动环境(UEFI)。所以我没有(使用)任何 API。我的代码处于字节流 APDU 级别,并使用 UEFI UsbIo 通信直接与硬件对话。

谢谢大家!

祝一切顺利,

亚历克斯

最佳答案

好的,我一遍又一遍地重新阅读规范(7816-3),也许是 5 次或更多。这些是我的发现:
根据规范,没有 这样的东西“自动” “默认”任何协议(protocol)。

8.2.3 Interface bytes TA TB TC TD

The “first offered transmission protocol” is defined as follows.If TD1 is present, then it encodes the first offered protocol T.If TD1 is absent, then the only offer is T=0.


好吧,更进一步...

6.3.1 Selection of transmission parameters and protocol

... until completion of a successful PPS exchange (see 9.3), after what the interface device shall start the negotiated transmission protocol using the negotiated values of the transmission parameters.


在这种情况下,下一个更有趣:

Otherwise, the interface device shall have started the “first offered transmission protocol” (see TD1 in 8.2.3). The interface device shall do so when the card offers only one transmission protocol and only the default values of the transmission parameters. Such a card need not support PPS exchange.


卡 A 不完全正确,因为它确实支持 PPS 交换!它根本不适用于 Cherry 阅读器。
好的,下一个关键点在6.3.1:

NOTE 3 An interface device facing a card in negotiable mode and supporting neither PPS exchange nor the “first offered transmission protocol” can perform either a warm reset or a deactivation.


因此,如果是 Cherry 阅读器,它 不符合标准! 外壳支持在第一个提供的协议(protocol)中进行通信,即 T1。
我在 SmartCard Handbook, 4th Edition 中发现了一个非常有趣的东西8.2 协议(protocol)参数选择 (PPS) 章节:

The PPS process described above is not suitable for changing protocols with a terminal that has its own specific protocol but cannot execute a PPS.

Figure 8.11 A possible sequence for switching between two transmission protocols supported by a smart card without using a PPS. With the sequence outlined here, the terminal does not have to perform an explicit PPS, but can nevertheless switch between the two protocols by initiating a reset...

...This solution is not ideal from a technical perspective, since a device should always behave the same after each reset, but it is certainly a pragmatic solution for a heterogeneous terminal world.


但它不适用于我的卡,因为卡不会通过执行热重置来切换协议(protocol)。但这可能是对读者奇怪行为的回答。

关于smartcard - 智能卡读卡器 T0 T1 APDU 级通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29993498/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com