diff --git a/.classpath b/.classpath index a66b0c3..67de96a 100644 --- a/.classpath +++ b/.classpath @@ -1,13 +1,12 @@ - - - - + + + - + diff --git a/.gitignore b/.gitignore index 82f5734..8e8d3ec 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /cov-int /ext/launch4j /esteid.jar +/lib/*.jar diff --git a/build.xml b/build.xml index c0b3b8d..024523e 100644 --- a/build.xml +++ b/build.xml @@ -1,16 +1,55 @@ ANT build file for EstEID hacking + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - + - + @@ -19,21 +58,18 @@ - + - - - - - - - - - + + + + + + diff --git a/fake.ca b/fake.ca new file mode 100644 index 0000000..de2b2d5 Binary files /dev/null and b/fake.ca differ diff --git a/lib/applet-playground.jar b/lib/applet-playground.jar deleted file mode 100644 index cad629c..0000000 Binary files a/lib/applet-playground.jar and /dev/null differ diff --git a/lib/bcpkix-jdk15on-153.jar b/lib/bcpkix-jdk15on-153.jar deleted file mode 100644 index 1037629..0000000 Binary files a/lib/bcpkix-jdk15on-153.jar and /dev/null differ diff --git a/lib/bcprov-jdk15on-153.jar b/lib/bcprov-jdk15on-153.jar deleted file mode 100644 index c9fbafb..0000000 Binary files a/lib/bcprov-jdk15on-153.jar and /dev/null differ diff --git a/lib/gp.jar b/lib/gp.jar index 241d900..4fbe6cd 100644 Binary files a/lib/gp.jar and b/lib/gp.jar differ diff --git a/lib/jnasmartcardio.jar b/lib/jnasmartcardio.jar deleted file mode 100644 index 8669f04..0000000 Binary files a/lib/jnasmartcardio.jar and /dev/null differ diff --git a/lib/jopt-simple-4.8.jar b/lib/jopt-simple-4.8.jar deleted file mode 100644 index 1870f9e..0000000 Binary files a/lib/jopt-simple-4.8.jar and /dev/null differ diff --git a/lib/vjcre.jar b/lib/vjcre.jar index bbea03c..6b9dd59 100644 Binary files a/lib/vjcre.jar and b/lib/vjcre.jar differ diff --git a/src/esteidhacker/CLI.java b/src/esteidhacker/CLI.java index 4b0ec68..bcc2960 100644 --- a/src/esteidhacker/CLI.java +++ b/src/esteidhacker/CLI.java @@ -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; @@ -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); @@ -126,7 +126,7 @@ 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"); @@ -134,7 +134,7 @@ private static OptionSet parseArguments(String argv[]) throws IOException { 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"); @@ -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); @@ -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 @@ -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); diff --git a/src/esteidhacker/EstEID.java b/src/esteidhacker/EstEID.java index 3aa21d8..a29cd6c 100644 --- a/src/esteidhacker/EstEID.java +++ b/src/esteidhacker/EstEID.java @@ -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 @@ -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(); @@ -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(); } @@ -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() { diff --git a/src/esteidhacker/FakeEstEID.java b/src/esteidhacker/FakeEstEIDManager.java similarity index 96% rename from src/esteidhacker/FakeEstEID.java rename to src/esteidhacker/FakeEstEIDManager.java index 07d248e..d02ff59 100644 --- a/src/esteidhacker/FakeEstEID.java +++ b/src/esteidhacker/FakeEstEIDManager.java @@ -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 @@ -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", " ", " ", " "}; @@ -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;