Код: Выделить всё
sourceapplet.java
Код: Выделить всё
sourceapplet.java
< /code>
public void checkNumber(byte[] number) {
short numberLength = (short)number.length;
if (numberLength < 6) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
< /code>
Configurations.java
< /code>
public interface Configuration extends Shareable {
public void checkNumber(byte[] number);
}
< /code>
targetapplet.java
< /code>
public final class TargetApplet extends Applet implements MultiSelectable {
private static final byte INS_TEST_CHECK_NUMBER = (byte) 0x11;
private AID checkNumberAppletAID;
private TargetApplet() {
// Initialize the AID of the checkNumberApplet
byte[] aidBytes = {(byte) 0xB2, 0x86, 0x00, 0x00, 0x00, 0x01};
checkNumberAppletAID = JCSystem.lookupAID(aidBytes, (short)0, (byte) aidBytes.length);
if (checkNumberAppletAID == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); // Applet not found
}
}
public void process(APDU apdu) {
final byte[] buffer = apdu.getBuffer();
final byte ins = buffer[ISO7816.OFFSET_INS];
switch (ins) {
case INS_TEST_CHECK_NUMBER:
processCheckNumber(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void processCheckNumber(APDU apdu) {
Configuration config = (Configuration) JCSystem.getAppletShareableInterfaceObject(checkNumberAppletAID, (byte) 0x00);
if (config == null) {
ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
}
byte[] number = new byte[]{1,2,3,4};
// byte[] number = new byte[] {(byte) '1', (byte) '2', (byte) '3', (byte) '4'};
config.checkNumber(number);
}
}
< /code>
Now when I send apdu 00 11 00 00
Код: Выделить всё
public void checkNumber(byte[] number) {
/* short numberLength = (short)number.length;
if (numberLength < 6) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
} */
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
< /code>
can anyone please let me know what is the issue here and how to resolve it? is there any issue with number array that is passed in processCheckNumber
>
Использование переходной памяти в targetApplet.java < /code> < /p>
Код: Выделить всё
private byte[] number;
private TargetApplet() {
number = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_DESELECT); // Also tried with CLEAR_ON_RESET
// Initialize the AID of the checkNumberApplet
byte[] aidBytes = {(byte) 0xB2, 0x86, 0x00, 0x00, 0x00, 0x01};
checkNumberAppletAID = JCSystem.lookupAID(aidBytes, (short)0, (byte) aidBytes.length);
if (checkNumberAppletAID == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); // Applet not found
}
}
private void processCheckNumber(APDU apdu) {
Configuration config = (Configuration) JCSystem.getAppletShareableInterfaceObject(checkNumberAppletAID, (byte) 0x00);
if (config == null) {
ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
}
number[0] = 1;
number[1] = 2;
number[2] = 3;
number[3] = 4;
config.checkNumber(number);
}
< /code>
Using persistent memory in targetapplet.java
Код: Выделить всё
private byte[] number;
private TargetApplet() {
number = new byte[4];
// Initialize the AID of the checkNumberApplet
byte[] aidBytes = {(byte) 0xB2, 0x86, 0x00, 0x00, 0x00, 0x01};
checkNumberAppletAID = JCSystem.lookupAID(aidBytes, (short)0, (byte) aidBytes.length);
if (checkNumberAppletAID == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); // Applet not found
}
}
private void processCheckNumber(APDU apdu) {
Configuration config = (Configuration) JCSystem.getAppletShareableInterfaceObject(checkNumberAppletAID, (byte) 0x00);
if (config == null) {
ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
}
number[0] = 1;
number[1] = 2;
number[2] = 3;
number[3] = 4;
config.checkNumber(number);
}
< /code>
[b]Update2[/b]
Added try-catch in sourceapplet.java
Код: Выделить всё
public void checkNumber(byte[] number) {
try {
short numberLength = (short)number.length;
if (numberLength < 6) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
} catch (ISOException e) {
ISOException.throwIt(e.getReason());
} catch (SecurityException e) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
}
< /code>
And now I get 6982 SW_SECURITY_STATUS_NOT_SATISFIED
p.s: пожалуйста, дайте мне знать, если не хватает какой -либо информации
Подробнее здесь: https://stackoverflow.com/questions/790 ... n-javacard