Compare commits
No commits in common. "0633e5c7671329357c9b030bda1dbc9de94dc28a" and "5d679cccc1e678b2974d92457de3b40c5d713729" have entirely different histories.
0633e5c767
...
5d679cccc1
9 changed files with 38 additions and 157 deletions
31
.vscode/tasks.json
vendored
31
.vscode/tasks.json
vendored
|
@ -1,31 +0,0 @@
|
||||||
{
|
|
||||||
// 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,4 +1,2 @@
|
||||||
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 --params %PIN% -f
|
gp --install %~dp0..\javacard\%PACKAGE%.cap -f
|
||||||
|
|
|
@ -6,22 +6,6 @@ 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
|
||||||
|
|
||||||
|
@ -43,7 +27,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 800400000003
|
send_apdu -sc 0 -APDU 8004000003
|
||||||
|
|
||||||
card_disconnect
|
card_disconnect
|
||||||
release_context
|
release_context
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
// 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;
|
|
|
@ -1,3 +0,0 @@
|
||||||
SET CARD_ROOT=%~dp0..\card
|
|
||||||
call %CARD_ROOT%\e222.cmd
|
|
||||||
call %CARD_ROOT%\delete.cmd
|
|
|
@ -1,5 +0,0 @@
|
||||||
@echo off
|
|
||||||
SET CARD_ROOT=%~dp0..\card
|
|
||||||
call %CARD_ROOT%\e222.cmd
|
|
||||||
call %CARD_ROOT%\c222.cmd
|
|
||||||
call %CARD_ROOT%\install.cmd
|
|
|
@ -1,4 +0,0 @@
|
||||||
@echo off
|
|
||||||
SET CARD_ROOT=%~dp0..\card
|
|
||||||
call %CARD_ROOT%\e222.cmd
|
|
||||||
call %CARD_ROOT%\list.cmd
|
|
|
@ -1,4 +0,0 @@
|
||||||
@echo off
|
|
||||||
SET CARD_ROOT=%~dp0..\card
|
|
||||||
call %CARD_ROOT%\e222.cmd
|
|
||||||
call %CARD_ROOT%\test.cmd
|
|
|
@ -6,65 +6,33 @@
|
||||||
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
|
||||||
*/
|
*/
|
||||||
protected MyApplet(byte[] appletData, short dataOffset, byte dataLength) {
|
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
||||||
pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
|
new MyApplet();
|
||||||
pin.update(appletData, dataOffset, dataLength);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only this class's install method should create the applet object.
|
||||||
|
*/
|
||||||
|
protected MyApplet() {
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean select() {
|
|
||||||
if (pin.getTriesRemaining() == 0) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return super.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deselect() {
|
|
||||||
super.deselect();
|
|
||||||
pin.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes an incoming APDU.
|
* Processes an incoming APDU.
|
||||||
*
|
*
|
||||||
|
@ -81,58 +49,41 @@ 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) {
|
switch (instruction) {
|
||||||
case 0x04:
|
case 0x00:
|
||||||
case 0x02:
|
case 0x04:
|
||||||
authenticationRequired = !pin.isValidated();
|
byte[] response;
|
||||||
break;
|
length = apdu.setOutgoing();
|
||||||
}
|
|
||||||
|
|
||||||
if (authenticationRequired) {
|
if (instruction == 0x00) {
|
||||||
ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
|
response = authorName;
|
||||||
}
|
length = (short)response.length;
|
||||||
else {
|
} else {
|
||||||
switch (instruction) {
|
response = storage;
|
||||||
case 0x00:
|
|
||||||
case 0x04:
|
|
||||||
byte[] response;
|
|
||||||
length = apdu.setOutgoing();
|
|
||||||
|
|
||||||
if (instruction == 0x00) {
|
if (length > response.length) {
|
||||||
response = authorName;
|
ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 | response.length));
|
||||||
length = (short)response.length;
|
}
|
||||||
} else {
|
}
|
||||||
response = storage;
|
|
||||||
|
|
||||||
if (length > response.length) {
|
apdu.setOutgoingLength(length);
|
||||||
ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 | response.length));
|
apdu.sendBytesLong(response, (short) 0, length);
|
||||||
}
|
break;
|
||||||
}
|
case 0x02:
|
||||||
|
length = apdu.setIncomingAndReceive();
|
||||||
|
storage = new byte[length];
|
||||||
|
|
||||||
apdu.setOutgoingLength(length);
|
if (length > 20) {
|
||||||
apdu.sendBytesLong(response, (short) 0, length);
|
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
|
||||||
break;
|
} else {
|
||||||
case 0x02:
|
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
||||||
length = apdu.setIncomingAndReceive();
|
}
|
||||||
storage = new byte[length];
|
break;
|
||||||
|
default:
|
||||||
if (length > 20) {
|
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||||
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
|
break;
|
||||||
} else {
|
|
||||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x20:
|
|
||||||
length = apdu.setIncomingAndReceive();
|
|
||||||
pin.check(buffer, (short) ISO7816.OFFSET_CDATA, (byte)length);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
||||||
|
|
Loading…
Reference in a new issue