Skip to content

Commit

Permalink
Add support for sending arbitrary APDU-s with -a/--apdu XX:XX:XX:XX:XX
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Nov 16, 2014
1 parent 77bc4bb commit 65e4767
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/openkms/gp/GPTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.CardTerminals.State;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.TerminalFactory;

import joptsimple.OptionException;
Expand All @@ -34,6 +35,7 @@ public class GPTool {
private final static String CMD_LOAD = "load";
private final static String CMD_UNLOCK = "unlock";
private final static String CMD_MAKE_DEFAULT = "make-default";
private final static String CMD_APDU = "apdu";

private final static String OPT_DELETEDEPS = "deletedeps";
private final static String OPT_DEFAULT = "default";
Expand All @@ -54,7 +56,6 @@ public class GPTool {
private final static String OPT_VERBOSE = "verbose";
private final static String OPT_REINSTALL = "reinstall";
private final static String OPT_VIRGIN = "virgin";

private final static String OPT_MODE = "mode";

private final static String OPT_MAC = "mac";
Expand All @@ -81,6 +82,7 @@ public static void main(String[] argv) throws Exception {
parser.acceptsAll(Arrays.asList("r", OPT_READER), "Use specific reader").withRequiredArg();
parser.acceptsAll(Arrays.asList("l", CMD_LIST), "List the contents of the card");
parser.acceptsAll(Arrays.asList("i", CMD_INFO), "Show information");
parser.acceptsAll(Arrays.asList("a", CMD_APDU), "Send raw APDU (hex)").withRequiredArg();
parser.accepts(OPT_VERSION, "Show information about the program");

// Special options
Expand Down Expand Up @@ -132,7 +134,7 @@ public static void main(String[] argv) throws Exception {
try {
args = parser.parse(argv);
// Try to fetch all values so that format is checked before usage
for (String s: parser.recognizedOptions().keySet()) {args.valueOf(s);}
for (String s: parser.recognizedOptions().keySet()) {args.valuesOf(s);}
} catch (OptionException e) {
if (e.getCause() != null) {
System.err.println(e.getMessage() + ": " + e.getCause().getMessage());
Expand Down Expand Up @@ -263,6 +265,14 @@ else if (args.has(OPT_EMV))
System.out.println();
}

// Send all raw APDU-s to the default-selected application of the card
if (args.has(CMD_APDU)) {
for (Object s: args.valuesOf(CMD_APDU)) {
CommandAPDU c = new CommandAPDU(GPUtils.stringToByteArray((String)s));
card.getBasicChannel().transmit(c);
}
}

// Talk to the card manager (can be null)
gp.select((AID) args.valueOf(OPT_SDAID));

Expand Down

0 comments on commit 65e4767

Please sign in to comment.