I want to send a random byte array including for example 24 elements to my JavaCard applet and then my applet is supposed to change that array using a specific method. For example that method XOR each elements with 0x05
and returns the result array in APDU response.
To aim the above goal I wrote the following program so far:
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;
}
}
I must send the following APDU command after compiling and selecting my applet:
>>> 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
And the expected data that my applet must return is :
<<< 14 27 36 41 50 ... bd
I have problem with installing this Applet.
I can not install it to my Java card while I am sure that there is no problem with the Java Card version compatibility between my applet and my card. Anyway my program is compiled with Java Card Dev Kit 2.2.1.
It is notable that I created a default Java Card project without any additional code and it installed successfully on my card. It was compiled by JavaCard Development kit version 2.2.1 ,also.
I used the globalPlatformPro to install my applet and it gave me 0x6700
error in status words.
Update 1:
I entered install command with -v -d parameter . OutPut is:
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)
Is there something wrong with my applet? What is the issue?
-d -v
arguments in the install command. I.e output ofgp.exe -install E:\keyGeneratorPackage.cap -v -d
– Ebrahim Ghaseminew keyGeneratorPackage.KeyGeneratorPackage()
Just usenew KeyGeneratorPackage()
2 - Some Javacards based on their transfer protocol differ in registering the applet, Try Registering the applet without parameters and tell us the results Usenew KeyGeneratorPackage(bArray, bOffset, bLength)
ininstall
method, then create a constructor and useregister()
in that, don't forget not to send any parameter inregister
method – Hana Bzh