【发布时间】:2016-04-18 20:06:45
【问题描述】:
我想通过 org.globalplatform 包在我的小程序中使用安全消息传递。我有一个 C# 库,它实现了一些 globalplatform 命令。我可以在 CLR、MAC 和 ENC 模式下打开卡的安全通道,我可以在上述模式下在卡上加载和安装小程序。 我也在我的小程序中成功打开了安全通道,外部身份验证响应为 9000。像这样:
case INS_INIT_UPDATE:
case INS_External_AUTHENTICATION:
SDInstruction(apdu);
break;
和
private void SDInstruction(APDU apdu)
{
byte[] buf = apdu.getBuffer();
byte cla = buf[ISO7816.OFFSET_CLA];
byte ins = buf[ISO7816.OFFSET_INS];
apdu.setIncomingAndReceive();
if(ins == INS_INIT_UPDATE)
secureChannel = GPSystem.getSecureChannel();
short len = secureChannel.processSecurity(apdu);
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytes(ISO7816.OFFSET_CDATA, (short) len);
}
但是当我想在我的小程序中解包命令 apdu“由全局平台 c# 库包装”时,cardManager 返回 6982(安全状态不满足)。解包代码:
byte[] buf = apdu.getBuffer();
if (secureChannel.getSecurityLevel() < (SecureChannel.AUTHENTICATED))
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
short len = secureChannel.unwrap(buf, (short) 0, (short) buf.length);
安全通道 apdu 的踪迹:
Command APDU >> Class=00 Ins=A4 P1=04 P2=00 P3=09 Data=A00000030800001000
Response APDU << SW=611A
Command APDU >> Class=00 Ins=C0 P1=00 P2=00 P3=1A
Response APDU << SW=9000 Data=61174F06000010000100790D4F0BA00000030800001000010009
Command APDU >> Class=80 Ins=50 P1=00 P2=00 P3=08 Data=0101010101010101
Response APDU << SW=611C
Command APDU >> Class=00 Ins=C0 P1=00 P2=00 P3=1C
Response APDU << SW=9000 Data=4D0022840106A783224FFF01AF258B0267752E248D07854961DA9851
Command APDU >> Class=84 Ins=82 P1=01 P2=00 P3=10 Data=F6E5BC84DE83E5242E8B6C9CA0ECB741
Response APDU << SW=9000
Command APDU >> Class=04 Ins=20 P1=00 P2=80 P3=0E Data=3131313131315F34DCF6BE7EDD3A
Response APDU << SW=6982
Wrapping apdu command faild.
有人可以帮助我吗? 非常感谢,
莫森。
【问题讨论】:
-
向您的问题添加 APDU 命令跟踪很有用。您还可以在
if(...)块中将ISO7816.SW_CONDITIONS_NOT_SATISFIED替换为(short) secureChannel.getSecurityLevel()以检查其值。 :) -
嗨,亚伯拉罕,(短)secureChannel.getSecurityLevel() 返回 0x81
-
嗨,亲爱的莫森。在
SDInstruction方法的第 4 行中,您已将 CLA 值限制为CLA_GP或0x84,并且您最后一个 APDU 命令的 CLA 是0x04。正确的?你的小程序中这个命令有类似的限制吗? -
感谢您的回复。抱歉,在最新版本的代码中,此块已被删除。
-
我看到您在第一个代码块中处理
INS_External_AUTHENTICATION指令,但在第二个代码块中没有。这是故意的吗?