Compare commits
11 commits
5d679cccc1
...
0633e5c767
Author | SHA1 | Date | |
---|---|---|---|
0633e5c767 | |||
7a616f49bc | |||
b587da3a84 | |||
551ac64fa7 | |||
de7ada08c9 | |||
db336bb058 | |||
abfeb97ebb | |||
80e1d752ad | |||
0b0e3d24ea | |||
4aaf1525ae | |||
7cb0c022d2 |
9 changed files with 153 additions and 34 deletions
31
.vscode/tasks.json
vendored
Normal file
31
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Flash hwb1",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${workspaceFolder}/hwb1/scripts/flash.cmd",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "List Applets",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${workspaceFolder}/hwb1/scripts/list.cmd",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Test hwb1 Applet",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${workspaceFolder}/hwb1/scripts/test.cmd",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Delete hwb1 Applet",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${workspaceFolder}/hwb1/scripts/delete.cmd",
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,2 +1,4 @@
|
||||||
|
SET PIN=31323334
|
||||||
|
|
||||||
@rem -f to force install over old version
|
@rem -f to force install over old version
|
||||||
gp --install %~dp0..\javacard\%PACKAGE%.cap -f
|
gp --install %~dp0..\javacard\%PACKAGE%.cap --params %PIN% -f
|
||||||
|
|
|
@ -6,6 +6,22 @@ card_connect
|
||||||
// select
|
// select
|
||||||
send_apdu -sc 0 -APDU 00A40400080102030405060809
|
send_apdu -sc 0 -APDU 00A40400080102030405060809
|
||||||
|
|
||||||
|
// Locked Commands
|
||||||
|
send_apdu -sc 0 -APDU 8002000002FFFE
|
||||||
|
|
||||||
|
// Send Wrong PIN
|
||||||
|
send_apdu -sc 0 -APDU 802000000431313131
|
||||||
|
|
||||||
|
// Still Locked Commands
|
||||||
|
send_apdu -sc 0 -APDU 800400000001
|
||||||
|
|
||||||
|
// Unlock Card With Correct PIN
|
||||||
|
send_apdu -sc 0 -APDU 802000000431323334
|
||||||
|
|
||||||
|
// Now Unlocked Commands
|
||||||
|
send_apdu -sc 0 -APDU 8002000002FFFE
|
||||||
|
send_apdu -sc 0 -APDU 800400000001
|
||||||
|
|
||||||
// Query Author Name
|
// Query Author Name
|
||||||
send_apdu -sc 0 -APDU 80000000
|
send_apdu -sc 0 -APDU 80000000
|
||||||
|
|
||||||
|
@ -27,7 +43,7 @@ send_apdu -sc 0 -APDU 80020000150102030405060708090A0B0C0D0E0F101112131415
|
||||||
|
|
||||||
// Querying Incorrect Amount of Bytes
|
// Querying Incorrect Amount of Bytes
|
||||||
send_apdu -sc 0 -APDU 8002000002FFFE
|
send_apdu -sc 0 -APDU 8002000002FFFE
|
||||||
send_apdu -sc 0 -APDU 8004000003
|
send_apdu -sc 0 -APDU 800400000003
|
||||||
|
|
||||||
card_disconnect
|
card_disconnect
|
||||||
release_context
|
release_context
|
||||||
|
|
5
hwb1/scripts/create-applet.script
Normal file
5
hwb1/scripts/create-applet.script
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// Select the installer applet
|
||||||
|
0x00 0xA4 0x04 0x00 0x09 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
|
||||||
|
|
||||||
|
// Create hwb1.MyApplet applet
|
||||||
|
0x80 0xB8 0x00 0x00 0x10 0x07 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x07 0x0 0x0 0x4 0x31 0x32 0x33 0x34 0x7F;
|
3
hwb1/scripts/delete.cmd
Normal file
3
hwb1/scripts/delete.cmd
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
SET CARD_ROOT=%~dp0..\card
|
||||||
|
call %CARD_ROOT%\e222.cmd
|
||||||
|
call %CARD_ROOT%\delete.cmd
|
5
hwb1/scripts/flash.cmd
Normal file
5
hwb1/scripts/flash.cmd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
@echo off
|
||||||
|
SET CARD_ROOT=%~dp0..\card
|
||||||
|
call %CARD_ROOT%\e222.cmd
|
||||||
|
call %CARD_ROOT%\c222.cmd
|
||||||
|
call %CARD_ROOT%\install.cmd
|
4
hwb1/scripts/list.cmd
Normal file
4
hwb1/scripts/list.cmd
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
@echo off
|
||||||
|
SET CARD_ROOT=%~dp0..\card
|
||||||
|
call %CARD_ROOT%\e222.cmd
|
||||||
|
call %CARD_ROOT%\list.cmd
|
4
hwb1/scripts/test.cmd
Normal file
4
hwb1/scripts/test.cmd
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
@echo off
|
||||||
|
SET CARD_ROOT=%~dp0..\card
|
||||||
|
call %CARD_ROOT%\e222.cmd
|
||||||
|
call %CARD_ROOT%\test.cmd
|
|
@ -6,31 +6,63 @@
|
||||||
package hwb1;
|
package hwb1;
|
||||||
|
|
||||||
import javacard.framework.*;
|
import javacard.framework.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applet class
|
* Applet class
|
||||||
*
|
*
|
||||||
* @author <user>
|
* @author <user>
|
||||||
*/
|
*/
|
||||||
public class MyApplet extends Applet {
|
public class MyApplet extends Applet {
|
||||||
|
final static short SW_PIN_VERIFICATION_REQUIRED = 0x6301;
|
||||||
|
final static byte PIN_TRY_LIMIT =(byte)0x03;
|
||||||
|
final static byte MAX_PIN_SIZE =(byte)0x08;
|
||||||
private byte[] authorName = new byte[] { 'M', 'a', 'n', 'u', 'e', 'l' };
|
private byte[] authorName = new byte[] { 'M', 'a', 'n', 'u', 'e', 'l' };
|
||||||
private byte[] storage = new byte[] {};
|
private byte[] storage = new byte[] {};
|
||||||
|
private OwnerPIN pin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs this applet.
|
* Installs this applet.
|
||||||
*
|
*
|
||||||
|
* @param buffer the array containing installation parameters
|
||||||
|
* @param bOffset the starting offset in bArray
|
||||||
|
* @param bLength the length in bytes of the parameter data in bArray
|
||||||
|
*/
|
||||||
|
public static void install(byte[] buffer, short offset, byte length) {
|
||||||
|
byte aidLength = buffer[offset];
|
||||||
|
|
||||||
|
short controlInfoOffset = (short)(offset + 1 + aidLength);
|
||||||
|
byte controlInfoLength = buffer[controlInfoOffset];
|
||||||
|
|
||||||
|
short dataOffset = (short)(controlInfoOffset + 1 + controlInfoLength);
|
||||||
|
byte dataLength = buffer[dataOffset];
|
||||||
|
|
||||||
|
new MyApplet(buffer, (short)(dataOffset + 1), dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only this class's install method should create the applet object.
|
||||||
|
*
|
||||||
* @param bArray the array containing installation parameters
|
* @param bArray the array containing installation parameters
|
||||||
* @param bOffset the starting offset in bArray
|
* @param bOffset the starting offset in bArray
|
||||||
* @param bLength the length in bytes of the parameter data in bArray
|
* @param bLength the length in bytes of the parameter data in bArray
|
||||||
*/
|
*/
|
||||||
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
protected MyApplet(byte[] appletData, short dataOffset, byte dataLength) {
|
||||||
new MyApplet();
|
pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
|
||||||
|
pin.update(appletData, dataOffset, dataLength);
|
||||||
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean select() {
|
||||||
* Only this class's install method should create the applet object.
|
if (pin.getTriesRemaining() == 0) {
|
||||||
*/
|
return false;
|
||||||
protected MyApplet() {
|
} else {
|
||||||
register();
|
return super.select();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deselect() {
|
||||||
|
super.deselect();
|
||||||
|
pin.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,8 +81,20 @@ public class MyApplet extends Applet {
|
||||||
if (buffer[ISO7816.OFFSET_CLA] != (byte)0x80) {
|
if (buffer[ISO7816.OFFSET_CLA] != (byte)0x80) {
|
||||||
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
|
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
|
||||||
} else {
|
} else {
|
||||||
|
boolean authenticationRequired = false;
|
||||||
byte instruction = buffer[ISO7816.OFFSET_INS];
|
byte instruction = buffer[ISO7816.OFFSET_INS];
|
||||||
|
|
||||||
|
switch (instruction) {
|
||||||
|
case 0x04:
|
||||||
|
case 0x02:
|
||||||
|
authenticationRequired = !pin.isValidated();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authenticationRequired) {
|
||||||
|
ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
|
||||||
|
}
|
||||||
|
else {
|
||||||
switch (instruction) {
|
switch (instruction) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
case 0x04:
|
case 0x04:
|
||||||
|
@ -81,10 +125,15 @@ public class MyApplet extends Applet {
|
||||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 0x20:
|
||||||
|
length = apdu.setIncomingAndReceive();
|
||||||
|
pin.check(buffer, (short) ISO7816.OFFSET_CDATA, (byte)length);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue