我想發送一個包含例如24個元素的隨機字節數組到我的JavaCard小程序,然後我的小程序應該使用特定方法更改該數組。例如,該方法XOR每個元素都帶有0x05
,並在APDU響應中返回結果數組。在Java Card小程序安裝過程中接收6700狀態字錯誤
要瞄準上述目標,我寫了下面的程序至今:
>>> 80 00 00 00 18 11 22 33 44 55 66 77 88 99 10 20 30 40 50 60 70 80 90 b1 b2 b3 b4 b5 b6 b7 b8
和預期:
package keyGeneratorPackage;
import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.framework.Util;
public class KeyGeneratorPackage extends Applet {
private static final byte HW_CLA = (byte) 0x80;
private static final byte HW_INS = (byte) 0x00;
public static void install(byte[] bArray, short bOffset, byte bLength) {
new keyGeneratorPackage.KeyGeneratorPackage().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
apdu.setIncomingAndReceive();
byte[] buffer = apdu.getBuffer();
byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF);
byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF);
short lc = (short) (buffer[ISO7816.OFFSET_LC] & (short)0x00FF);
byte[] Data = JCSystem.makeTransientByteArray(lc, JCSystem.CLEAR_ON_DESELECT);
if (CLA != HW_CLA) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch (INS) {
case HW_INS: {
// copying the apdu data into byte array Data
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, Data, (short) 0, lc);
getKey(apdu, Data);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void getKey(APDU apdu, byte[] data) {
byte[] buffer = apdu.getBuffer();
short length = (short) data.length;
//prepareing the key array of same length of Data
byte[] key = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_DESELECT);
generateKey(data, key);
Util.arrayCopyNonAtomic(key, (short) 0, buffer, (short) 0, (short) length);
apdu.setOutgoingAndSend((short) 0, length);
}
private byte[] generateKey(byte[] Data, byte[] key) {
short i;
for (i = 0; i < Data.length; i++) {
key[i] = (byte) (Data[i]^(byte)0x05);
}
return key;
}
}
我必須編制並選擇我的小程序後發送以下APDU命令我的小程序必須返回的數據是:
<<< 14 27 36 41 50 ... bd
我在安裝此Applet時遇到問題。
我無法將它安裝到我的Java卡上,但我確信我的小應用程序和我的卡之間的Java Card版本兼容性沒有問題。無論如何,我的程序是用Java Card Dev Kit 2.2.1編譯的。
值得注意的是,我創建了一個沒有任何附加代碼的默認Java Card項目,並且它已成功安裝在我的卡上。它也是由JavaCard開發工具包版本2.2.1編譯的。
我用globalPlatformPro安裝我的小程序,它給我0x6700
錯誤的狀態字。
更新1:
我進入安裝帶有-v參數-d命令。 OutPut是:
E:\javacard\GlobalPlatformPro>gp -install E:\newPack.cap -v -d
# Detected readers from SunPCSC
[ ] Duali DE-ABCM Contactless Reader 0
[ ] Duali DE-ABCM Sam1 Reader 0
[*] Duali DE-ABCM Sam2 Reader 0
[ ] JAVACOS Virtual Contact Reader 0
[ ] JAVACOS Virtual Contactless Reader 1
SCardConnect("Duali DE-ABCM Sam2 Reader 0", T=*) -> T=0, 3B6B000080653140DC48428
3009000
SCardBeginTransaction("Duali DE-ABCM Sam2 Reader 0")
Reader: Duali DE-ABCM Sam2 Reader 0
ATR: 3B6B000080653140DC484283009000
More information about your card:
http://smartcard-atr.appspot.com/parse?ATR=3B6B000080653140DC484283009000
A>> T=0 (4+0000) 00A40400 00
A<< (0027+2) (73ms) 6F198408A000000003000000A50D9F6E064842928832319F6501FF 9000
Auto-detected ISD AID: A000000003000000
# ...
# Authentication Process Censored.
# ...
CAP file (v2.1) generated on Mon Jun 29 10:11:23 IRDT 2015
By Sun Microsystems Inc. converter 1.3 with JDK 1.7.0_09 (Oracle Corporation)
Package: newPack v1.2 with AID 1020304050
Applet: newApplet with AID 10203040500000
Import: A0000000620101 v1.2
A>> T=0 (4+0010) 84F28000 0A 4F0031993E2681C862DD 00
A<< (0011+2) (599ms) 08A000000003000000019E 9000
A>> T=0 (4+0010) 84F24000 0A 4F00EFCEFA0D825EAC3B 00
A<< (0011+2) (91ms) 08AABBCCDDEEFF00000700 9000
A>> T=0 (4+0010) 84F22000 0A 4F0050316231A15388BE 00
A<< (0143+2) (277ms) 08D156000027100106010008D156000027100101010006A000000151000
10007A0000000030000010008D156000027100102010007A0000000620201010007A000000062010
2010008A000000062010101010007A0000000620101010007A0000000620002010007A0000000620
003010007A0000000620001010008D156000027100108010006AABBCCDDEEFF0100 9000
A>> T=0 (4+0010) 84F21000 0A 4F00358E1689D8208F09 00
A<< (0176+2) (331ms) 08D15600002710010601000008D15600002710010101000006A00000015
10001000007A000000003000001000008D15600002710010201000007A000000062020101000007A
000000062010201000008A00000006201010101000007A000000062010101000007A000000062000
201000007A000000062000301000007A000000062000101000008D15600002710010801000109D15
60000271001080106AABBCCDDEEFF01000108AABBCCDDEEFF0000 9000
A>> T=0 (4+0026) 84E60200 1A 05102030405008A0000000030000000000005DC20F51A0D4CA2
9
A<< (0001+2) (474ms) 9000
A>> T=0 (4+0255) 84E80000 FF C482018E01000FDECAFFED010204020105102030405002001F0
00F001F000B000B003A000C00CA000A00150000008700000000000001010004000B01020107A0000
00062010103000B010710203040500000000806000C00800300FF0007010000001C0700CA0001101
88C00007A05308F00013D8C0002181D0441181D258B00037A0525188B000460037A198B00053B198
B00062D1A03251100FF535B321A04251100FF535B29041A07251100FF5329051605058D000728061
F10806A08116E008D0008160473001D0000000000091A0815060316058D00093B181915068C000A7
008116D008D00087A0533198B00062E1A9229041604AA59A4DD02FCF125
A<< (0000+2) (792ms) 6700
pro.javacard.gp.GPException: LOAD failed SW: 6700
at pro.javacard.gp.GlobalPlatform.check(GlobalPlatform.java:1092)
at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:728)
at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:686)
at pro.javacard.gp.GPTool.main(GPTool.java:453)
我的小程序有什麼問題嗎?什麼是問題?
請在安裝命令中使用'-d -v'參數時添加安裝過程的輸出。 I.e輸出'gp.exe -install E:\ keyGeneratorPackage.cap -v -d' – Abraham
您是否嘗試過使用相同的工具,讀取器和卡加載另一個.cap文件?有些閱讀器和卡片不喜歡數據部分長度爲255的APDU。如果可能的話,您可以爲小應用程序安裝設置較低的塊大小。 – vojta
我通過gpj成功安裝了我的小程序。但是當我發送命令發送數據並通過Opensc工具接收到更改的數據時,它會返回無效的數據,這意味着命令不正確。什麼是問題?我會用我在gpj平臺上收到的輸出更新我的問題。 –