1

アプレットで org.globalplatform パッケージによる安全なメッセージングを使用したいと考えています。globalplatform コマンドのいくつかを実装する C# のライブラリがあります。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);        
    }

しかし、アプレットで「グローバル プラットフォームの C# ライブラリによってラップされた」アンラップ コマンド apdu が必要な場合、cardManager は 6982(Security Status not satisfid.unwraping code) を返します。

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.

誰でも私を助けることができますか?どうもありがとうございました、

モーセン。

4

1 に答える 1

1

アンラップ コマンドが間違った長さを指定していると思います。
試す:

short len = secureChannel.unwrap(buf, (short) 0, (short)(ISO7816.OFFSET_CDATA + apdu.getIncomingLength()));
于 2016-04-18T12:06:45.087 に答える