Skip to content

Commit

Permalink
Rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Jan 18, 2014
1 parent cff1a94 commit f6d5512
Show file tree
Hide file tree
Showing 19 changed files with 821 additions and 542 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/jnasmartcardio.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk15on-150.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions Manifest.mf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Manifest-Version: 1.0
Main-Class: openkms.gpj.GPJTool
Class-path: lib/bcprov-jdk15on-150.jar
Mame: openkms/gpj/
Sealed: true
File renamed without changes.
17 changes: 10 additions & 7 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?xml version="1.0"?>
<project name="GlobalPlatform Java" default="dist" basedir=".">
<description>ANT build file for GPJ</description>
<description>ANT build file for OpenKMS GlobalPlatform</description>
<property name="src" location="src"/>
<property name="build" location="bin"/>

<target name="init">
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init" description="compile the source">
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" source="1.6" target="1.6"/>
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" source="1.6" target="1.6" debug="true" debuglevel="lines,vars,source">
<compilerarg value="-Xlint"/>
<classpath>
<pathelement location="lib/jnasmartcardio.jar"/>
<pathelement location="lib/bcprov-jdk15on-150.jar"/>
</classpath>
</javac>
</target>

<target name="dist" depends="compile" description="generate the distribution">
<jar manifest="Manifest.mf" destfile="openkms-globalplatform.jar">
<jar manifest="Manifest.mf" destfile="openkms-globalplatform.jar" filesetmanifest="skip">
<fileset dir="${build}"/>
<zipgroupfileset file="lib/jnasmartcardio.jar"/>
</jar>
</target>

<target name="clean" description="clean up">
<delete dir="${build}"/>
<delete file="openkms-globalplatform.jar"/>
Expand Down
Binary file added lib/bcprov-jdk15on-150.jar
Binary file not shown.
Binary file added lib/jnasmartcardio.jar
Binary file not shown.
26 changes: 12 additions & 14 deletions src/openkms/gpj/AID.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Expand All @@ -28,51 +28,48 @@

public class AID {

public static final String GEMALTO = "GemaltoXpressPro";

public static Map<String, AID> SD_AIDS = new TreeMap<String, AID>();

static {
SD_AIDS.put("1OP201", new AID(new byte[] { (byte) 0xa0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00 }));
SD_AIDS.put("2GP211", new AID(new byte[] { (byte) 0xa0, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00 }));
SD_AIDS.put(GEMALTO, new AID(new byte[] { (byte) 0xa0, 0x00, 0x00, 0x00, 0x18, 0x43, 0x4D, 0x00 }));
SD_AIDS.put("OP201", new AID(new byte[] { (byte) 0xa0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00 }));
SD_AIDS.put("GP211", new AID(new byte[] { (byte) 0xa0, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00 }));
}

private byte[] aidBytes = null;

/**
* Construct an application identifier from a complete byte array.
*
*
* @param bytes
* complete application identifier
* @throws IllegalArgumentException
* if the length is outside the permitted range (5-16)
*
*
*/
public AID(byte[] bytes) {
this(bytes, 0, bytes.length);
}

/**
* Construct an application identifier from a part of a byte array.
*
*
* @param bytes
* @param offset
* start index of the application identifier
* @param length
* length
* @throws IllegalArgumentException
* if the length is outside the permitted range (5-16)
*
*
*/
public AID(byte[] bytes, int offset, int length) {
this(bytes, offset, length, true);
this(bytes, offset, length, false);
}

/**
* Construct an application identifier from a complete byte array, possibly
* ignoring length checking.
*
*
* @param bytes
* @param offset
* start index of the application identifier
Expand All @@ -86,11 +83,12 @@ public AID(byte[] bytes, int offset, int length) {
* if the length is outside the permitted range (5-16); if
* checkLength is false no check is performed and no exception
* thrown
*
*
*/
public AID(byte[] bytes, int offset, int length, boolean checkLength) throws IllegalArgumentException {
if (checkLength && (length < 5 || length > 16))
if (checkLength && ((length < 5) || (length > 16))) {
throw new IllegalArgumentException("AID's are between 5 and 16 bytes");
}
aidBytes = new byte[length];
System.arraycopy(bytes, offset, aidBytes, 0, length);
}
Expand Down
18 changes: 10 additions & 8 deletions src/openkms/gpj/AIDRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Expand All @@ -29,7 +29,7 @@
/**
* Convenience class managing a vector of {@link AIDRegistryEntry
* AIDRegistryEntries} with search functionality.
*
*
* Implements {@code Iterable<AIDRegistryEntry} to permit foreach loops such as
* {@code for(AIDRegistryEntry e : registry) ...}.
*/
Expand All @@ -39,7 +39,7 @@ public class AIDRegistry implements Iterable<AIDRegistryEntry> {

/**
* Add one entry to this registry.
*
*
* @param entry
*/
public void add(AIDRegistryEntry entry) {
Expand All @@ -48,7 +48,7 @@ public void add(AIDRegistryEntry entry) {

/**
* Returns an iterator that iterates over all entries in this registry.
*
*
* @return iterator
*/
public Iterator<AIDRegistryEntry> iterator() {
Expand All @@ -57,28 +57,30 @@ public Iterator<AIDRegistryEntry> iterator() {

/**
* Returns a list of all packages in this registry.
*
*
* @return a list of all packages
*/
public List<AIDRegistryEntry> allPackages() {
List<AIDRegistryEntry> res = new ArrayList<AIDRegistryEntry>();
for (AIDRegistryEntry e : entries) {
if (e.isPackage())
if (e.isPackage()) {
res.add(e);
}
}
return res;
}

/**
* Returns a list of all applets in this registry.
*
*
* @return a list of all applets
*/
public List<AIDRegistryEntry> allApplets() {
List<AIDRegistryEntry> res = new ArrayList<AIDRegistryEntry>();
for (AIDRegistryEntry e : entries) {
if (e.isApplet())
if (e.isApplet()) {
res.add(e);
}
}
return res;
}
Expand Down
50 changes: 26 additions & 24 deletions src/openkms/gpj/AIDRegistryEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Expand All @@ -27,7 +27,7 @@

/**
* One entry in the card registry.
*
*
* Describes one entry of the card registry, consisting of
* <UL>
* <LI>application ID (as {@link AID})
Expand All @@ -36,7 +36,7 @@
* <LI>the list of ?? (as array of {@link AID AID's}
* <LI>and the kind
* </UL>
*
*
*/
public class AIDRegistryEntry {

Expand All @@ -48,7 +48,7 @@ public static enum Kind {

/**
* Convert a kind into a three letter string.
*
*
* @return a three letter abbreviation
*/
public String toShortString() {
Expand All @@ -68,19 +68,19 @@ public String toShortString() {
}
}

private AID aid;
private final AID aid;

private int lifeCycleState;
private final int lifeCycleState;

private int privileges;
private final int privileges;

private List<AID> executableAIDS;
private final List<AID> executableAIDS;

private Kind kind;
private final Kind kind;

/**
* Create a new entry.
*
*
* @param aid
* the application ID
* @param lifeCycleState
Expand All @@ -98,7 +98,7 @@ public AIDRegistryEntry(AID aid, int lifeCycleState, int privileges, Kind kind)

/**
* Add an executable application ID to this entry.
*
*
* @param aid
* application ID
*/
Expand All @@ -108,7 +108,7 @@ public void addExecutableAID(AID aid) {

/**
* Return the application ID of this entry.
*
*
* @return application ID
*/
public AID getAID() {
Expand All @@ -117,7 +117,7 @@ public AID getAID() {

/**
* Return the life cycle state of this entry.
*
*
* @return live cycle state
*/
public int getLifeCycleState() {
Expand All @@ -126,7 +126,7 @@ public int getLifeCycleState() {

/**
* Return the priveledges of this entry.
*
*
* @return priveledges, encoded into an int
*/
public int getPrivileges() {
Expand All @@ -135,7 +135,7 @@ public int getPrivileges() {

/**
* Return the kind of this entry.
*
*
* @return kind
*/
public Kind getKind() {
Expand All @@ -144,16 +144,16 @@ public Kind getKind() {

/**
* Return true if this entry describes a package.
*
*
* @return true if this entry is a package
*/
public boolean isPackage() {
return kind == Kind.ExecutableLoadFilesAndModules || kind == Kind.ExecutableLoadFiles;
return (kind == Kind.ExecutableLoadFilesAndModules) || (kind == Kind.ExecutableLoadFiles);
}

/**
* Return true if this entry describes an applet.
*
*
* @return true if this entry is an applet
*/
public boolean isApplet() {
Expand All @@ -162,7 +162,7 @@ public boolean isApplet() {

/**
* Return all executable application ID's of this entry.
*
*
* @return application ID's
*/
public List<AID> getExecutableAIDs() {
Expand All @@ -173,7 +173,7 @@ public List<AID> getExecutableAIDs() {

/**
* Return a string representation of this entry.
*
*
* @return description
*/
public String toString() {
Expand Down Expand Up @@ -210,6 +210,8 @@ public String getLifeCycleString() {
return "SELECTABLE";
} else if (lifeCycleState > 0x83) {
return "LOCKED";
} else {
return "ERROR";
}
case ExecutableLoadFilesAndModules:
if (lifeCycleState == 0x1) {
Expand All @@ -236,9 +238,9 @@ public String getLifeCycleString() {

public String getPrivilegesString() {
ArrayList<String> privs = new ArrayList<String>();

int r = privileges;

if (r == 0) {
privs.add("(NONE)");
} else {
Expand Down Expand Up @@ -270,12 +272,12 @@ public String getPrivilegesString() {
}
result += privs.get(i);
}

// TODO: Wait until actual cards discovered
if (r>0) {
result += " " + Integer.toHexString(r);
}

return result.trim();
}
}
Loading

0 comments on commit f6d5512

Please sign in to comment.