Compare commits

..

15 commits

8 changed files with 222 additions and 1 deletions

5
.gitignore vendored
View file

@ -1,4 +1,3 @@
# ---> Eclipse
.metadata .metadata
bin/ bin/
tmp/ tmp/
@ -60,3 +59,7 @@ local.properties
# Typically, this file would be tracked if it contains build/dependency configurations: # Typically, this file would be tracked if it contains build/dependency configurations:
#.project #.project
# Java Card SDK
.gen/
deliverables/
apdu_scripts/

16
hwb1/.classpath Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path=".gen">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="Sample_Platform_HOME/lib/api_classic.jar">
<attributes>
<attribute name="javadoc_location" value="file:C:\Users\Manuel\Downloads\java_card_2023\java_card\java_card_kit_310_plus_sim\docs\api"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="Sample_Platform_HOME/lib/api_classic_annotations.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

29
hwb1/.javacard_project Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<entries>
<key>src/hwb1</key>
<value>
<entry>
<key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">IsJavaCardPackage</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">1</value>
</entry>
<entry>
<key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">AID</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">52C4C7C95C1337</value>
</entry>
</value>
</entries>
<entries>
<key>src/hwb1/MyApplet.java</key>
<value>
<entry>
<key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">AID</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">52C4C7C95C0420</value>
</entry>
<entry>
<key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">IsJavaCardApplet</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">1</value>
</entry>
</value>
</entries>
</root>

39
hwb1/.project Normal file
View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hwb1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.oracle.javacard.jcdk.core.projectbuild.JCDKCleanBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.oracle.javacard.jcdk.core.projectbuild.JCDKBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>com.oracle.javacard.jcdk.core.projectbuild.JCDKNature</nature>
</natures>
<filteredResources>
<filter>
<id>1697133027601</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View file

@ -0,0 +1,9 @@
-i
-classdir ..\bin
-applet 0x52:0xC4:0xC7:0xC9:0x5C:0x04:0x20 hwb1.MyApplet
-out CAP JCA EXP
-d ..\deliverables\hwb1
-debug
-target 3.1.0
hwb1
0x52:0xC4:0xC7:0xC9:0x5C:0x13:0x37 1.0

View file

@ -0,0 +1,5 @@
#Thu Oct 12 17:03:08 CEST 2023
SCRIPTGEN_NO_POWER_UP=false
SCRIPTGEN_NO_POWER_DOWN=true
SCRIPTGEN_NO_BANNER=false
SCRIPTGEN_NO_BEGIN_END=false

View file

@ -0,0 +1,22 @@
// Query Author Name
0x80 0x00 0x00 0x00 0x00 0x7F;
// Store Data
0x80 0x02 0x00 0x00 0x02 0xFF 0xFE 0x7F;
// Querying Data
0x80 0x04 0x00 0x00 0x00 0x01;
0x80 0x04 0x00 0x00 0x00 0x02;
// Triggering Unsupported Instruction Error
0x80 0x01 0x00 0x00 0x00 0x7F;
// Triggering Unsupported CLA Error
0x90 0x01 0x00 0x00 0x00 0x7F;
// Sending Too Many Bytes (> 20)
0x80 0x02 0x00 0x00 0x15 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x7F;
// Querying Incorrect Amount of Bytes
0x80 0x02 0x00 0x00 0x02 0xFF 0xFE 0x7F;
0x80 0x04 0x00 0x00 0x00 0x03;

View file

@ -0,0 +1,98 @@
/**
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
*
*/
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[] storage = new byte[] {};
/**
* Installs this applet.
*
* @param bArray 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[] bArray, short bOffset, byte bLength) {
new MyApplet();
}
/**
* Only this class's install method should create the applet object.
*/
protected MyApplet() {
register();
}
/**
* Processes an incoming APDU.
*
* @see APDU
* @param apdu the incoming APDU
*/
@Override
public void process(APDU apdu) {
short length;
byte[] buffer = apdu.getBuffer();
if (buffer[ISO7816.OFFSET_CLA] != (byte)0x80) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
} else {
byte instruction = buffer[ISO7816.OFFSET_INS];
switch (instruction) {
case 0x00:
case 0x04:
byte[] response;
length = apdu.setOutgoing();
if (instruction == 0x00) {
response = AuthorName;
length = (short)response.length;
} else {
response = storage;
if (length > response.length) {
ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 | response.length));
}
}
apdu.setOutgoingLength(length);
apdu.sendBytesLong(response, (short) 0, length);
break;
case 0x02:
length = apdu.setIncomingAndReceive();
storage = new byte[length];
if (length > 20) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
} else {
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
break;
}
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
}
}