diff --git a/samples/AllowAll/com/gieseckedevrient/javacard/allowall/AllowAll.java b/samples/AllowAll/com/gieseckedevrient/javacard/allowall/AllowAll.java new file mode 100644 index 0000000..0b32279 --- /dev/null +++ b/samples/AllowAll/com/gieseckedevrient/javacard/allowall/AllowAll.java @@ -0,0 +1,114 @@ +package com.gieseckedevrient.javacard.allowall; + +import javacard.framework.*; + +public class AllowAll extends Applet implements MultiSelectable +{ + static final byte INS_GET_DATA = (byte) 0xCA; + static final short TAG_CMD_GET_NEXT = (short) 0xFF60; + static final short TAG_CMD_GET_SPECIFIC = (short) 0xFF50; + static final short TAG_CMD_GET_ALL = (short) 0xFF40; + static final short TAG_CMD_GET_REFRESH = (short) 0xDF20; + + + private final static byte[] RESPONSE_GET_REFRESH = { (byte)0xDF, (byte)0x20, (byte)0x08, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05, (byte)0x06, (byte)0x07, (byte)0x08 }; + + private final static byte[] RESPONSE_GET_SPECIFIC = { (byte)0xFF, (byte)0x50, (byte)0x08, (byte) 0xE3, (byte) 0x06, (byte)0xD0, (byte)0x01, (byte)0x01, (byte)0xD1, (byte)0x01, (byte)0x01 }; + + private final static byte[] RESPONSE_GET_ALL = {(byte)0xFF, (byte)0x40,(byte)0x10, (byte)0xE2,(byte)0x0E, (byte)0xE1,(byte)0x04, (byte)0x4F,(byte)0x00, (byte)0xC1, (byte)0x00, (byte)0xE3, (byte)0x06, (byte)0xD0, (byte)0x01, (byte)0x01, (byte)0xD1, (byte)0x01, (byte)0x01 }; + + + public static void install(byte[] abArray, short sOffset, byte bLength) + { + (new AllowAll()).register( abArray, (short) (sOffset + 1), abArray[sOffset] ); + } + + public boolean select(boolean appInstAlreadyActive) + { + return true; + } + + public void deselect(boolean appInstStillActive) + { + return; + } + + public void process(APDU oAPDU) throws ISOException + { + short sSW1SW2 = ISO7816.SW_NO_ERROR; + short sOutLength = (short)0; + + byte[] abData = oAPDU.getBuffer(); + + byte bINS = abData[ ISO7816.OFFSET_INS ]; + + short sMode = Util.getShort( abData, ISO7816.OFFSET_P1 ); + + if( selectingApplet() == true ) + { + return; + } + + try + { + if( bINS != INS_GET_DATA ) + ISOException.throwIt( ISO7816.SW_INS_NOT_SUPPORTED ); + + if( sMode == TAG_CMD_GET_ALL ) + { + sOutLength = Util.arrayCopyNonAtomic( RESPONSE_GET_ALL, + (short)0, + abData, + (short)0, + (short)RESPONSE_GET_ALL.length + ); + } + else if( sMode == TAG_CMD_GET_SPECIFIC ) + { + oAPDU.setIncomingAndReceive(); + + sOutLength = Util.arrayCopyNonAtomic( RESPONSE_GET_SPECIFIC, + (short)0, + abData, + (short)0, + (short)RESPONSE_GET_SPECIFIC.length + ); + } + else if( sMode == TAG_CMD_GET_NEXT ) + { + ISOException.throwIt( ISO7816.SW_CONDITIONS_NOT_SATISFIED ); + } + else if( sMode == TAG_CMD_GET_REFRESH ) + { + sOutLength = Util.arrayCopyNonAtomic( RESPONSE_GET_REFRESH, + (short)0, + abData, + (short)0, + (short)RESPONSE_GET_REFRESH.length + ); + } + else + { + ISOException.throwIt( ISO7816.SW_WRONG_P1P2 ); + } + } + catch( ISOException e ) + { + sSW1SW2 = e.getReason(); + } + catch( Exception e ) + { + sSW1SW2 = ISO7816.SW_UNKNOWN; + } + + if( sSW1SW2 != ISO7816.SW_NO_ERROR ) + { + ISOException.throwIt( sSW1SW2 ); + } + + if( sOutLength > (short)0 ) + { + oAPDU.setOutgoingAndSend( (short)0, sOutLength ); + } + } +} diff --git a/samples/AllowAll/compiler.sh b/samples/AllowAll/compiler.sh new file mode 100755 index 0000000..2d6f3e0 --- /dev/null +++ b/samples/AllowAll/compiler.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +export JC_HOME=$PWD/java_card_kit-2_2_1 +export PATH=$PATH:$JC_HOME/bin + +javac -g -source 1.3 -target 1.1 -classpath $JC_HOME/lib/api.jar com/gieseckedevrient/javacard/allowall/*.java diff --git a/samples/AllowAll/converter.sh b/samples/AllowAll/converter.sh new file mode 100755 index 0000000..ee51146 --- /dev/null +++ b/samples/AllowAll/converter.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +JC_HOME=$PWD/java_card_kit-2_2_1 +PATH=$PATH:$JC_HOME/bin + +java -classpath $JC_HOME/lib/converter.jar:$JC_HOME/lib/api.jar com.sun.javacard.converter.Converter -noverify -i -classdir . -out CAP -exportpath $JC_HOME/api_export_files -applet 0xA0:0x00:0x00:0x01:0x51:0x41:0x43:0x4C:0x00 com.gieseckedevrient.javacard.allowall.AllowAll com.gieseckedevrient.javacard.allowall 0xA0:0x00:0x00:0x01:0x51:0x41:0x43:0x4C 1.0 + +cp com/gieseckedevrient/javacard/allowall/javacard/allowall.cap .