Add scripts for managing real smartcards
This commit is contained in:
parent
9d5d03346a
commit
5d679cccc1
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -63,3 +63,7 @@ local.properties
|
|||
.gen/
|
||||
deliverables/
|
||||
apdu_scripts/
|
||||
|
||||
# Build Output
|
||||
*.class
|
||||
javacard/
|
||||
|
|
3
hwb1/card/c222.cmd
Normal file
3
hwb1/card/c222.cmd
Normal file
|
@ -0,0 +1,3 @@
|
|||
@rem compile applet with JcDK 2.2.2
|
||||
javac -g -target 1.1 -source 1.2 -cp %JC_HOME%\lib\api.jar -d . %~dp0../src/%PACKAGE%/*.java
|
||||
converter -exportpath "%JC_HOME%\api_export_files" -applet 0x01:0x02:0x03:0x04:0x5:0x6:0x8:0x9 %PACKAGE%.%APPLET% %PACKAGE% 0x01:0x02:0x03:0x04:0x5:0x6:0x8 1.0
|
1
hwb1/card/delete.cmd
Normal file
1
hwb1/card/delete.cmd
Normal file
|
@ -0,0 +1 @@
|
|||
gp --delete 01020304050608
|
5
hwb1/card/e222.cmd
Normal file
5
hwb1/card/e222.cmd
Normal file
|
@ -0,0 +1,5 @@
|
|||
@echo off
|
||||
set PACKAGE=hwb1
|
||||
set APPLET=MyApplet
|
||||
set "JAVA_HOME=%JAVA8_HOME%"
|
||||
set "path=%JAVA_HOME%\bin;%JC_HOME%\bin;%JC_HOME%\..;%JC_HOME%\..\GPShell-1.4.4;%path%"
|
2
hwb1/card/install.cmd
Normal file
2
hwb1/card/install.cmd
Normal file
|
@ -0,0 +1,2 @@
|
|||
@rem -f to force install over old version
|
||||
gp --install %~dp0..\javacard\%PACKAGE%.cap -f
|
1
hwb1/card/list.cmd
Normal file
1
hwb1/card/list.cmd
Normal file
|
@ -0,0 +1 @@
|
|||
gp --list
|
1
hwb1/card/test.cmd
Normal file
1
hwb1/card/test.cmd
Normal file
|
@ -0,0 +1 @@
|
|||
gpshell %~dp0test.txt
|
33
hwb1/card/test.txt
Normal file
33
hwb1/card/test.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
// test my applet
|
||||
establish_context
|
||||
enable_trace
|
||||
enable_timer
|
||||
card_connect
|
||||
// select
|
||||
send_apdu -sc 0 -APDU 00A40400080102030405060809
|
||||
|
||||
// Query Author Name
|
||||
send_apdu -sc 0 -APDU 80000000
|
||||
|
||||
// Store Data
|
||||
send_apdu -sc 0 -APDU 8002000002FFFE
|
||||
|
||||
// Querying Data
|
||||
send_apdu -sc 0 -APDU 800400000001
|
||||
send_apdu -sc 0 -APDU 800400000002
|
||||
|
||||
// Triggering Unsupported Instruction Error
|
||||
send_apdu -sc 0 -APDU 8001000000
|
||||
|
||||
// Triggering Unsupported CLA Error
|
||||
send_apdu -sc 0 -APDU 9001000000
|
||||
|
||||
// Sending Too Many Bytes (> 20)
|
||||
send_apdu -sc 0 -APDU 80020000150102030405060708090A0B0C0D0E0F101112131415
|
||||
|
||||
// Querying Incorrect Amount of Bytes
|
||||
send_apdu -sc 0 -APDU 8002000002FFFE
|
||||
send_apdu -sc 0 -APDU 8004000003
|
||||
|
||||
card_disconnect
|
||||
release_context
|
|
@ -6,21 +6,13 @@
|
|||
package hwb1;
|
||||
|
||||
import javacard.framework.*;
|
||||
import javacardx.annotations.*;
|
||||
import static hwb1.MyAppletStrings.*;
|
||||
|
||||
/**
|
||||
* Applet class
|
||||
*
|
||||
* @author <user>
|
||||
*/
|
||||
@StringPool(value = {
|
||||
@StringDef(name = "Package", value = "hwb1"),
|
||||
@StringDef(name = "AppletName", value = "MyApplet"),
|
||||
@StringDef(name = "AuthorName", value = "Manuel") },
|
||||
// Insert your strings here
|
||||
name = "MyAppletStrings")
|
||||
public class MyApplet extends Applet {
|
||||
private byte[] authorName = new byte[] { 'M', 'a', 'n', 'u', 'e', 'l' };
|
||||
private byte[] storage = new byte[] {};
|
||||
|
||||
/**
|
||||
|
@ -47,11 +39,13 @@ public class MyApplet extends Applet {
|
|||
* @see APDU
|
||||
* @param apdu the incoming APDU
|
||||
*/
|
||||
@Override
|
||||
public void process(APDU apdu) {
|
||||
short length;
|
||||
byte[] buffer = apdu.getBuffer();
|
||||
|
||||
if (selectingApplet()) {
|
||||
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
||||
} else {
|
||||
if (buffer[ISO7816.OFFSET_CLA] != (byte)0x80) {
|
||||
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
|
||||
} else {
|
||||
|
@ -64,7 +58,7 @@ public class MyApplet extends Applet {
|
|||
length = apdu.setOutgoing();
|
||||
|
||||
if (instruction == 0x00) {
|
||||
response = AuthorName;
|
||||
response = authorName;
|
||||
length = (short)response.length;
|
||||
} else {
|
||||
response = storage;
|
||||
|
@ -96,3 +90,4 @@ public class MyApplet extends Applet {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue