2016-04-17 33 views
1

我想通过org.globalplatform包在我的applet中使用安全消息传递。我在C#中有一个库,它实现了一些全局平台命令。我可以在CLR,MAC和ENC模式下打开安全通道卡,并且可以在提到的模式下在卡上加载和安装小程序。 此外,我打开successfuly在我的小程序安全通道和外部认证响应9000这样的:secureChannel.unwrap函数返回6982(安全状态不满意)

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(安全状态不satisfid).unwraping代码:

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. 

任何人都可以帮到我吗? 非常感谢,

Mohsen。

+0

添加APDU命令跟踪到您的问题是有用的。您还可以在'if(...)'块中用'(short)secureChannel.getSecurityLevel()'代替'ISO7816.SW_CONDITIONS_NOT_SATISFIED'来检查它的值。 :) – Abraham

+1

嗨亚伯拉罕,(短)secureChannel.getSecurityLevel()返回0x81 –

+0

嗨亲爱的莫赫森。在'SDInstruction'方法的第4行中,您已将CLA值限制为'CLA_GP'或'0x84',并且您的最后一个APDU命令的CLA为'0x04'。对?这个命令在你的applet中有类似的限制吗? – Abraham

回答

0

我认为你的解包命令指定了错误的长度。
尝试:

short len = secureChannel.unwrap(buf, (short) 0, (short)(ISO7816.OFFSET_CDATA + apdu.getIncomingLength())); 
+0

谢谢保罗,你是对的。 :d –