Skip to content

Commit

Permalink
Build with Travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Jan 14, 2016
1 parent 591bb60 commit 6a47d9f
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 51 deletions.
9 changes: 4 additions & 5 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?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-153.jar"/>
<classpathentry kind="lib" path="lib/jopt-simple-4.8.jar"/>
<classpathentry kind="lib" path="lib/bcpkix-jdk15on-153.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk15on-154.jar"/>
<classpathentry kind="lib" path="lib/jopt-simple-4.9.jar"/>
<classpathentry kind="lib" path="lib/bcpkix-jdk15on-154.jar"/>
<classpathentry kind="lib" path="lib/gp.jar"/>
<classpathentry kind="lib" path="lib/vjcre.jar"/>
<classpathentry kind="lib" path="lib/applet-playground.jar"/>
<classpathentry kind="lib" path="lib/FakeEstEID.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/cov-int
/ext/launch4j
/esteid.jar
/lib/*.jar
66 changes: 51 additions & 15 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
<?xml version="1.0"?>
<project name="EstEID hacker" default="dist" basedir=".">
<description>ANT build file for EstEID hacking</description>
<target name="fetch" description="fetch the dependencies">
<mkdir dir="lib"/>
<!-- Remember to update .classpath as well! -->
<get src="https://repo1.maven.org/maven2/net/sf/jopt-simple/jopt-simple/4.9/jopt-simple-4.9.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="http://repo2.maven.org/maven2/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="http://repo2.maven.org/maven2/org/slf4j/slf4j-simple/1.7.13/slf4j-simple-1.7.13.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="http://downloads.bouncycastle.org/java/bcprov-jdk15on-154.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="http://downloads.bouncycastle.org/java/bcpkix-jdk15on-154.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="https://github.com/martinpaljak/apdu4j/releases/download/v0.0.15/apdu4j.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="https://github.com/martinpaljak/GlobalPlatformPro/releases/download/v0.3.5/gp.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="https://github.com/martinpaljak/vJCRE/releases/download/r1/vjcre.jar" dest="lib" verbose="true" skipexisting="true"/>
<get src="https://github.com/martinpaljak/esteid-applets/releases/download/v0.0.2/FakeEstEID.jar" dest="lib" verbose="true" skipexisting="true"/>

<checksum algorithm="SHA-256" file="lib/jopt-simple-4.9.jar" property="26c5856e954b5f864db76f13b86919b59c6eecf9fd930b96baa8884626baf2f5" verifyProperty="joptOK"/>
<checksum algorithm="SHA-256" file="lib/slf4j-api-1.7.13.jar" property="20d68d0c2e4fb984ffc164852b8b68df49a2b8716076f576881bcef7649a0e35" verifyProperty="slfjapiOK"/>
<checksum algorithm="SHA-256" file="lib/slf4j-simple-1.7.13.jar" property="4709c0b535057c6a9a794da9522b1291de9c72b6d61f41b7ecf63156bc7bee35" verifyProperty="slfjsimpleOK"/>
<checksum algorithm="SHA-256" file="lib/bcprov-jdk15on-154.jar" property="d0ae14598f9c528d2ab7bb8ed00e785a5440f692712cd362d69328aba25efb57" verifyProperty="bouncy1OK"/>
<checksum algorithm="SHA-256" file="lib/bcpkix-jdk15on-154.jar" property="d618dcfbf0337b91015b21d4b398175ae96382a82c7e1d6e8c657fcd236463c7" verifyProperty="bouncy2OK"/>
<checksum algorithm="SHA-256" file="lib/apdu4j.jar" property="d47ccc62324c2fcad1183596d77b2e6478f6136a8bf4c4b631fbc70ec3d659c2" verifyProperty="apduOK"/>
<checksum algorithm="SHA-256" file="lib/gp.jar" property="cbe9ba8a198b434aa63c5266f3f30302ab0b174d46fc94a35e46a08ed7a9ef9f" verifyProperty="gpOK"/>
<checksum algorithm="SHA-256" file="lib/vjcre.jar" property="20260d4c63d54eba540eb6eee931b9bff9df0ad97823841848126ea36c04e6b4" verifyProperty="vjcreOK"/>
<checksum algorithm="SHA-256" file="lib/FakeEstEID.jar" property="c6387f4750c286e3faf566bfac6acd53f46c327ee60f22e796700939c14bf2f5" verifyProperty="appletOK"/>
<fail message="Checksum failure">
<condition>
<or>
<isfalse value="${joptOK}"/>
<isfalse value="${slfjapiOK}"/>
<isfalse value="${slfjsimpleOK}"/>
<isfalse value="${bouncy1OK}"/>
<isfalse value="${bouncy2OK}"/>
<isfalse value="${apduOK}"/>
<isfalse value="${gpOK}"/>
<isfalse value="${vjcreOK}"/>
<isfalse value="${appletOK}"/>
</or>
</condition>
</fail>
</target>
<!-- Build the software -->
<path id="build.classpath">
<pathelement location="lib/bcprov-jdk15on-153.jar"/>
<pathelement location="lib/bcpkix-jdk15on-153.jar"/>
<pathelement location="lib/jopt-simple-4.8.jar"/>
<pathelement location="lib/bcprov-jdk15on-154.jar"/>
<pathelement location="lib/bcpkix-jdk15on-154.jar"/>
<pathelement location="lib/jopt-simple-4.9.jar"/>
<pathelement location="lib/apdu4j.jar"/>
<pathelement location="lib/gp.jar"/>
<pathelement location="lib/vjcre.jar"/>
<pathelement location="lib/applet-playground.jar"/>
<pathelement location="lib/FakeEstEID.jar"/>
</path>
<target name="compile" description="compile the source">
<target name="compile" description="compile the source" depends="fetch">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build" includeantruntime="false" excludes="**/tests/**" debug="true" debuglevel="lines,vars,source">
<compilerarg value="-Xlint"/>
Expand All @@ -19,21 +58,18 @@
</target>
<!-- Package it into a nice little JAR -->
<target name="dist" depends="compile" description="generate the distribution">
<jar manifest="Manifest.mf" destfile="esteid.jar" level="9" basedir="build">
<jar destfile="esteid.jar" level="9" basedir="build">
<fileset dir="src">
<include name="resources/*.pem"/>
</fileset>
</jar>
</target>
<!-- Wrap the JAR into .EXE for Windows users -->
<target name="windist" depends="dist" description="package as .exe">
<property name="launch4j.dir" location="ext/launch4j"/>
<taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask" classpath="${launch4j.dir}/launch4j.jar:${launch4j.dir}/lib/xstream.jar"/>
<launch4j>
<config headerType="console" outfile="esteid.exe" jar="esteid.jar" dontWrapJar="true" errTitle="EstEID hacker">
<jre minVersion="1.7.0"/>
</config>
</launch4j>
<target name="cmd" depends="compile" description="generate the local commandline utility">
<jar manifest="Manifest.mf" destfile="esteid.jar" level="9" basedir="build">
<fileset dir="src">
<include name="resources/*.pem"/>
</fileset>
</jar>
</target>
<!-- Clean the source tree -->
<target name="clean" description="clean up">
Expand Down
Binary file added fake.ca
Binary file not shown.
Binary file removed lib/applet-playground.jar
Binary file not shown.
Binary file removed lib/bcpkix-jdk15on-153.jar
Binary file not shown.
Binary file removed lib/bcprov-jdk15on-153.jar
Binary file not shown.
Binary file modified lib/gp.jar
Binary file not shown.
Binary file removed lib/jnasmartcardio.jar
Binary file not shown.
Binary file removed lib/jopt-simple-4.8.jar
Binary file not shown.
Binary file modified lib/vjcre.jar
Binary file not shown.
21 changes: 10 additions & 11 deletions src/esteidhacker/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import pro.javacard.applets.FakeEstEIDApplet;
import org.esteid.applet.FakeEstEID;
import pro.javacard.gp.GlobalPlatform;
import pro.javacard.vre.VJCREProvider;
import pro.javacard.vre.VRE;
Expand Down Expand Up @@ -111,7 +111,7 @@ private static OptionSet parseArguments(String argv[]) throws IOException {

parser.accepts(OPT_RELAX, "Relax some checks");

// FakeEstEIDCA interface
// FakeEstEIDManagerCA interface
parser.accepts(OPT_CA, "Use or generate a CA").withRequiredArg().ofType(File.class);
parser.accepts(OPT_RESIGN, "Re-sign cert (PEM) with CA").withRequiredArg().ofType(File.class);

Expand All @@ -126,15 +126,15 @@ private static OptionSet parseArguments(String argv[]) throws IOException {
parser.accepts(OPT_SIGNKEY, "Load sign key (PEM)").withRequiredArg().ofType(File.class);

// New card generation
parser.accepts(OPT_INSTALL, "Install FakeEstEID applet").withOptionalArg();
parser.accepts(OPT_INSTALL, "Install FakeEstEIDManager applet").withOptionalArg();
parser.accepts(OPT_NEW, "Populate a new \"Mari-Liis Männik\"");
parser.accepts(OPT_CHECK, "Check generated keys for consistency");

// Clone a card
parser.accepts(OPT_CLONE, "Clone the card");
parser.accepts(OPT_DATA, "Edit the personal data file");

parser.accepts(OPT_EMULATE, "Use FakeEstEIDApplet intance inside vJCRE");
parser.accepts(OPT_EMULATE, "Use FakeEstEIDManagerApplet intance inside vJCRE");
parser.accepts(OPT_TEST, "Run EstEID test-suite");
parser.accepts(OPT_TEST_CRYPTO, "Run only crypto tests");
parser.accepts(OPT_TEST_PINS, "Run only PIN tests");
Expand Down Expand Up @@ -228,12 +228,11 @@ public static void main(String argv[]) throws Exception {

try {
if (args.has(OPT_EMULATE)) {
// Load FakeEstEIDApplet into vJCRE emulator
// Load FakeEstEIDManagerApplet into vJCRE emulator
VRE vre = VRE.getInstance();
VRE.debugMode = false;

AID aid = AID.fromBytes(FakeEstEIDApplet.aid);
vre.load(FakeEstEIDApplet.class, aid);
AID aid = AID.fromBytes(FakeEstEIDManager.aid);
vre.load(FakeEstEIDManager.class, aid);
vre.install(aid, true);
// Establish connection to the applet
term = TerminalFactory.getInstance("PC/SC", vre, new VJCREProvider()).terminals().list().get(0);
Expand Down Expand Up @@ -281,12 +280,12 @@ public static void main(String argv[]) throws Exception {

// Disconnect
card.disconnect(true);
System.out.println("Enter card with FakeEstEID and press enter.");
System.out.println("Enter card with FakeEstEIDManager and press enter.");
System.console().readLine();

card = term.connect("*");
esteid = EstEID.getInstance(card.getBasicChannel());
FakeEstEID fake = FakeEstEID.getInstance(esteid);
FakeEstEIDManager fake = FakeEstEIDManager.getInstance(esteid);
fake.send_cert(authcert.getEncoded(), 1);
fake.send_cert(signcert.getEncoded(), 2);
// Generate random keys
Expand Down Expand Up @@ -333,7 +332,7 @@ else if (args.has(OPT_T1))
System.out.println("Type: " + esteid.getType());
}

FakeEstEID fake = FakeEstEID.getInstance(esteid);
FakeEstEIDManager fake = FakeEstEIDManager.getInstance(esteid);

if (args.has(OPT_AUTHCERT)) {
File f = (File) args.valueOf(OPT_AUTHCERT);
Expand Down
33 changes: 18 additions & 15 deletions src/esteidhacker/EstEID.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static void wrong_pin_check(EstEIDException e) throws WrongPINException {
// Some cards don't use 63CX but 630X :(
throw new WrongPINException(e.getSW());
} else {
throw e;
//throw e; // FIXME
}
}
// PIN handling
Expand Down Expand Up @@ -339,20 +339,22 @@ public String getPersonalData(PersonalData d) throws CardException {
}
}

// File handling
public byte[] select(int fid) throws CardException {
public static CommandAPDU select_apdu(int fid) {
byte [] fidbytes = new byte[2];
fidbytes[0] = (byte)(fid >> 8);
fidbytes[1] = (byte)(fid);

ResponseAPDU resp = null;
if (fid == FID_3F00) { // Select master file
resp = transmit(new CommandAPDU(0x00, INS_SELECT, 0x00, 0x0C));
return new CommandAPDU(0x00, INS_SELECT, 0x00, 0x0C);
} else if (fid == FID_EEEE) { // Select DF
resp = transmit(new CommandAPDU(0x00, INS_SELECT, 0x01, 0x0C, fidbytes));
return new CommandAPDU(0x00, INS_SELECT, 0x01, 0x0C, fidbytes);
} else { // Select EF
resp = transmit(new CommandAPDU(0x00, INS_SELECT, 0x02, 0x0C, fidbytes));
}
return new CommandAPDU(0x00, INS_SELECT, 0x02, 0x0C, fidbytes);
}
}
// File handling
public byte[] select(int fid) throws CardException {
ResponseAPDU resp = transmit(select_apdu(fid));
check(resp);
currentFID = fid;
return resp.getData();
Expand All @@ -376,8 +378,11 @@ public byte[] read_file(final int bytes) throws CardException {
return bb;
}

public static CommandAPDU read_record_apdu(byte recno) {
return new CommandAPDU(0x00, INS_READ_RECORD, recno, 0x04, 256);
}
public byte[] read_record(final byte recno) throws CardException {
ResponseAPDU r = transmit(new CommandAPDU(0x00, INS_READ_RECORD, recno, 0x04, 256));
ResponseAPDU r = transmit(read_record_apdu(recno));
return check(r).getData();
}

Expand Down Expand Up @@ -468,25 +473,23 @@ private static ResponseAPDU check(ResponseAPDU resp) throws EstEIDException {
}

@SuppressWarnings("serial")
public static class EstEIDException extends RuntimeException {
public static class EstEIDException extends CardException {
private int sw;
public EstEIDException(int sw) {
super("Card returned: 0x" + Integer.toHexString(sw).toUpperCase());
this.sw = sw;
}

public String toString() {
return "Card returned: 0x" + Integer.toHexString(sw).toUpperCase();
}
public int getSW() {
return sw;
}
}

@SuppressWarnings("serial")
public static class WrongPINException extends RuntimeException {
public static class WrongPINException extends EstEIDException {
private int sw;
public WrongPINException(int sw) {
this.sw = sw;
super(sw);
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2014-2015 Martin Paljak
* Copyright (C) 2014-2016 Martin Paljak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -49,7 +49,8 @@

import esteidhacker.EstEID.CardType;

public class FakeEstEID {
// Given a connection to a FakeEstEID applet, provides a higher level interface for the possibilities.
public class FakeEstEIDManager {

// Other fun constants
private static final String[] defaultDataFile = new String[] {"JÄNES-KARVANE", "SIILIPOISS", "Jesús MARIA", "G", "LOL", "01.01.0001", "10101010005", "A0000001", "31.12.2099", "TIIBET", "01.01.2014", "ALALINE", "SEE POLE PÄRIS KAART", " ", " ", " "};
Expand All @@ -58,13 +59,13 @@ public class FakeEstEID {

private final CardChannel channel;

private FakeEstEID(CardChannel c) {
private FakeEstEIDManager(CardChannel c) {
this.channel = c;
}

public static FakeEstEID getInstance(EstEID esteid) {
public static FakeEstEIDManager getInstance(EstEID esteid) {
if (esteid.getType() == CardType.AnyJavaCard || esteid.getType() == CardType.JavaCard2011) {
FakeEstEID fake = new FakeEstEID(esteid.channel);
FakeEstEIDManager fake = new FakeEstEIDManager(esteid.channel);
return fake;
}
return null;
Expand Down

0 comments on commit 6a47d9f

Please sign in to comment.