OPSystem.setATRHistBytes 在 GlobalPlatform 兼容卡中如何工作?

how does OPSystem.setATRHistBytes works in GlobalPlatform compatible cards?

引自 GP2.1.1 API 文档:

setATRHistBytes
public static boolean setATRHistBytes(byte[] baBuffer,
                                      short sOffset,
                                      byte bLength)
This method sets the historical bytes of the ATR (Answer To Reset) string. The sequence of bytes will be visible on a subsequent power-up or reset.

Notes:

    This method shall not be invoked from the Applet.install() method.
    
The OPEN locates the entry of the current applet context in the Open Platform Registry and verifies that the application has the "default selected" privilege.
    The OPEN is responsible for updating the length of historical bytes in Format Character T0 of the ATR.

    Parameters:

    baBuffer - the source byte array containing the ATR historical bytes. Must be a global array.
    sOffset - offset of the ATR historical bytes within source byte array.
    bLength - the number of historical bytes.

    Returns:
    true if ATR bytes set, false otherwise.

问题 1:GP 是否强制默认选择小程序来更改 ATR 历史字节?

问题2:GP只改冷复位ATR吗?或者 Warm Reset ATR 也改变了?

问题三:我怎样才能收到卡的Warm Reset ATR?有什么命令吗?它是 reader 特定的吗?

关于1:我以前从未使用过这个命令,但是阅读时:

The OPEN locates the entry of the current applet context in the GlobalPlatform Registry and verifies that the Application has the Default Selected privilege.

我假设任何兼容的实现都必须以这种方式处理它。是否有理由不相信这一点,或者您是否问大多数供应商是否忽略了这一点?由于历史部分包含与默认选择的应用程序相关的信息(例如,卡是否为 MF、如何读取 EF.DR、默认应用程序的 AID、发行人所在的国家/地区,...)检查此权限是有意义的。这在今天的多应用智能卡世界中可能不合适。

关于 2:由于名称“历史字节”表示只有 ATR 的这一部分发生了变化。其他部分如时钟速度在冷热 ATR 之间可能有所不同。

关于 3:查看 PC/SC 命令 SCardConnect。参见 SCARD_RESET_CARDSCARD_UNPOWER_CARD

Question 1: Does GP forces the applet to be default-selected for changing the ATR Hist bytes?

不,Applet 需要拥有此权限 #5(或“GP v2.2 中的卡重置权限,请参阅 table11-7)才能更改它。它是在期间设置的INSTALL [and make Selectable]。基本上它需要在启动时默认选择,否则它无法更改 ATR 历史字节。对于 multi-purpose 卡,这可能是一个问题,尽管你可以说这是 ISO 7816-4 和协议的限制,而不是 Java 卡/全球平台。

来自全球平台规范 v2.2 的 2 个片段:

The Default Selected privilege is redefined as the Card Reset privilege to modify the historical bytes. An Application is able to refuse explicit selection, e.g. because it does not support the current card I/O interface, and allow the (partial) selection process by OPEN to continue. To provide backward compatibility, the privilege confers implicit selectability if it has not been awarded to another Application.

The presence of the Privileges is required. If an Application is only being installed and not made selectable with the same INSTALL command the Card Reset privilege cannot be set.

Question 2: Does GP changes the Cold Reset ATR only? Or the Warm Reset ATR changes too?

通常两者都会更改,大多数平台至少会将它们初始化为相同的值。请注意,更改了历史字节,通常指示卡的类型,而不是通信参数(速度、超时值等)

Question 3: How can I receive my card's Warm Reset ATR? Is there any command for that? Is it reader-specific?

一般情况下,您只需在不关闭电源的情况下执行重置即可。这当然可以使用 SCardReconnect 等标准命令来完成,但我不确定其他工具。通常,您只需执行重置,而对于冷重启,您只需移除卡、reader 或者实际上,只是移除电源。

通常您不会期望冷重启或热重启之间存在差异,但肯定可以对两者使用不同的 ATR(从有关几个 Java 卡芯片的专有信息中得知)。供应商通常有一种设置完整 ATR 的方法,只要有足够的权限和专有命令的知识。