Hello,
I am using nxp-jcop-tools-jcop4.5-v6.9.0.12_RC1 with Eclipse.
In general, the simulation is working fine in Eclipse.
I have written a test applet which should create a global array but JCSystem.makeGlobalArray throws a SecurityException.
Below is example code (slightly modified) and the log output from JCShell.
Best regards
Frank
package com.xyz.test;
import javacard.framework.*;
public class GlobalArray extends Applet {
Object globalArray;
public static void install(byte[] bArray, short bOffset, byte bLength) {
new com.xyz.test.GlobalArray().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) { return; }
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
try {
globalArray = JCSystem.makeGlobalArray(JCSystem.ARRAY_TYPE_BYTE, (short) 8);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x6ff1);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
cm> /select 112233445511
=> 00 A4 04 00 06 11 22 33 44 55 11 00 ......"3DU..
(3688 usec [SYS], 4 JavaCard byte codes [DEV])
<= 90 00 ..
Status: No Error
cm> /send 00000000
NAD=05
=> 00 00 00 00 ....
(3636 sec [SYS], 17 JavaCard byte codes [DEV])
<= 6F F1 o.
Status: 0x6FF1
Solved! Go to Solution.
Hi @FrankF ,
The issue is not the allocation of the array but its assignment to the class variable 'globalArray'. If you remove the assignment you will see that it works. Javacard specification makes the following statement about Global Arrays.
A global array can be accessed from any applet context. References to global arrays cannot be stored in class variables or instance variables or array components. (See Runtime Environment Specification, Java Card Platform, Classic Edition, section 6.2.2 for details)
The code therefore can be made to work by assigning the globalArray object to an automatic variable as below:
package com.xyz.test;
import javacard.framework.*;
public class GlobalArray extends Applet {
public static void install(byte[] bArray, short bOffset, byte bLength) {
new com.xyz.test.GlobalArray().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) { return; }
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
Object globalArray;
try {
globalArray = (byte[]) JCSystem.makeGlobalArray(JCSystem.ARRAY_TYPE_BYTE, (short) 8);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x6ff1);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
Hope that helps,
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi @Kan_Li ,
thank you very much. Storing the reference in the class variable was the problem.
Have a great day, too!
Cheers,
Frank
Hi @FrankF ,
The issue is not the allocation of the array but its assignment to the class variable 'globalArray'. If you remove the assignment you will see that it works. Javacard specification makes the following statement about Global Arrays.
A global array can be accessed from any applet context. References to global arrays cannot be stored in class variables or instance variables or array components. (See Runtime Environment Specification, Java Card Platform, Classic Edition, section 6.2.2 for details)
The code therefore can be made to work by assigning the globalArray object to an automatic variable as below:
package com.xyz.test;
import javacard.framework.*;
public class GlobalArray extends Applet {
public static void install(byte[] bArray, short bOffset, byte bLength) {
new com.xyz.test.GlobalArray().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) { return; }
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
Object globalArray;
try {
globalArray = (byte[]) JCSystem.makeGlobalArray(JCSystem.ARRAY_TYPE_BYTE, (short) 8);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x6ff1);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
Hope that helps,
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------