Is it possible to send long bytes APDU (exceed 256)?
Is it possible to send long bytes APDU (exceed 256)?
How to send a very long data APUD into a java card (exceed 256 or said the max data length can exceed 261). What is the software you used?
And the similar question how to send a very long data APUD from a java card to the terminal software or application.How to do that? Any sample codes?
And the similar question how to send a very long data APUD from a java card to the terminal software or application.How to do that? Any sample codes?
-
- Posts: 55
- Joined: Thu Sep 22, 2016 5:05 am
- Points :784
- Contact:
Re: Is it possible to send long bytes APDU (exceed 256)?
You can use JCIDE to develop the applet of the javacard.
Your applet shall extends ExtendedLength interface.
Please refer to this example: https://javacardos.com/wiki/javacard-ap ... munication
applet :
public class EIDApplet extends Applet implements ExtendedLength{}
function:
public short receiveAPDU(APDU apdu, byte src[], short Lc, byte dest[]) {
short bytesReceived = (short)0;
bytesReceived = apdu.setIncomingAndReceive();
if (Lc == (short)0x00) {
short received = (short)0;
short dataLength = (short)0;
dataLength = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
if ((dataLength < (short)0)
|| (dataLength < bytesReceived)){
ISOException.throwIt((short)0x6700);
}
bytesReceived = abs((short)(bytesReceived + ISO7816.OFFSET_EXT_CDATA));
Util.arrayCopyNonAtomic(src, (short)0, dest, (short)0, bytesReceived);
dataLength = (short)(dataLength + ISO7816.OFFSET_EXT_CDATA);
if(dataLength > dest.length){
Error.wrong6700_P3Error();
}
while (bytesReceived < dataLength)
{
received = apdu.receiveBytes((short)0);
Util.arrayCopyNonAtomic(src, (short)0, dest, bytesReceived, received);
bytesReceived += received;
if ((apdu.getCurrentState() == APDU.STATE_FULL_INCOMING) &&
((short)bytesReceived != dataLength)){
ISOException.throwIt((short)0x6700);
}
}
src = dest;
Lc = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_EXT_CDATA);
}
else
{
Util.arrayCopyNonAtomic(src, (short)0x00, dest, (short)0x00, (short)(Lc+5));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA);
}
return Lc;
}
public void sendAPDU(APDU apdu, byte buffer[], short offset, short length, boolean hasLe) {
short Le = (short)0x00;
short t0Max = (short)32767;
short sendlength = (short)0x00;
if (hasLe == true) {
Le = (short)0x00;
}
else {
Le = apdu.setOutgoing();
}
if (length > t0Max) {
ISOException.throwIt((short)0x6700);
}
if ((Le == (short)0x00) || (Le == (short)256) || (Le == t0Max)) {
Le = length;
}
else if (Le > (short)length) {
if (APDU.getProtocol() == APDU.PROTOCOL_T1) {
ISOException.throwIt((short)0x6700);
}
else if (APDU.getProtocol() == APDU.PROTOCOL_T0) {
ISOException.throwIt(Util.makeShort((byte)0x6C, (byte)length));
}
else
{
Le = length;
}
}
else {
Le = length;
}
apdu.setOutgoingLength(Le);
while (Le > (short)0) {
sendlength = (Le < (short)256) ? Le : (short)256;
apdu.sendBytesLong(buffer, offset, sendlength);
offset += sendlength;
Le -= sendlength;
}
}
Your applet shall extends ExtendedLength interface.
Please refer to this example: https://javacardos.com/wiki/javacard-ap ... munication
applet :
public class EIDApplet extends Applet implements ExtendedLength{}
function:
public short receiveAPDU(APDU apdu, byte src[], short Lc, byte dest[]) {
short bytesReceived = (short)0;
bytesReceived = apdu.setIncomingAndReceive();
if (Lc == (short)0x00) {
short received = (short)0;
short dataLength = (short)0;
dataLength = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
if ((dataLength < (short)0)
|| (dataLength < bytesReceived)){
ISOException.throwIt((short)0x6700);
}
bytesReceived = abs((short)(bytesReceived + ISO7816.OFFSET_EXT_CDATA));
Util.arrayCopyNonAtomic(src, (short)0, dest, (short)0, bytesReceived);
dataLength = (short)(dataLength + ISO7816.OFFSET_EXT_CDATA);
if(dataLength > dest.length){
Error.wrong6700_P3Error();
}
while (bytesReceived < dataLength)
{
received = apdu.receiveBytes((short)0);
Util.arrayCopyNonAtomic(src, (short)0, dest, bytesReceived, received);
bytesReceived += received;
if ((apdu.getCurrentState() == APDU.STATE_FULL_INCOMING) &&
((short)bytesReceived != dataLength)){
ISOException.throwIt((short)0x6700);
}
}
src = dest;
Lc = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_EXT_CDATA);
}
else
{
Util.arrayCopyNonAtomic(src, (short)0x00, dest, (short)0x00, (short)(Lc+5));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA);
}
return Lc;
}
public void sendAPDU(APDU apdu, byte buffer[], short offset, short length, boolean hasLe) {
short Le = (short)0x00;
short t0Max = (short)32767;
short sendlength = (short)0x00;
if (hasLe == true) {
Le = (short)0x00;
}
else {
Le = apdu.setOutgoing();
}
if (length > t0Max) {
ISOException.throwIt((short)0x6700);
}
if ((Le == (short)0x00) || (Le == (short)256) || (Le == t0Max)) {
Le = length;
}
else if (Le > (short)length) {
if (APDU.getProtocol() == APDU.PROTOCOL_T1) {
ISOException.throwIt((short)0x6700);
}
else if (APDU.getProtocol() == APDU.PROTOCOL_T0) {
ISOException.throwIt(Util.makeShort((byte)0x6C, (byte)length));
}
else
{
Le = length;
}
}
else {
Le = length;
}
apdu.setOutgoingLength(Le);
while (Le > (short)0) {
sendlength = (Le < (short)256) ? Le : (short)256;
apdu.sendBytesLong(buffer, offset, sendlength);
offset += sendlength;
Le -= sendlength;
}
}
Who is online
Users browsing this forum: No registered users and 31 guests