diff options
| author | J08nY | 2018-11-07 11:20:06 +0100 |
|---|---|---|
| committer | J08nY | 2018-11-07 11:20:06 +0100 |
| commit | f0ae5fdc1ba778acc922d5269a5523a88ca97976 (patch) | |
| tree | deeb293db93e31a2ca260c64c02d7b9782788e3c | |
| parent | c676bacffd1305e1efc49b34d87ffd0a0a695ea7 (diff) | |
| download | ECTester-f0ae5fdc1ba778acc922d5269a5523a88ca97976.tar.gz ECTester-f0ae5fdc1ba778acc922d5269a5523a88ca97976.tar.zst ECTester-f0ae5fdc1ba778acc922d5269a5523a88ca97976.zip | |
| -rw-r--r-- | README.md | 155 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/ECTesterReader.java | 24 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/response/Response.java | 7 |
3 files changed, 119 insertions, 67 deletions
@@ -34,71 +34,84 @@ See `java -jar ECTesterReader.jar -h` for more. ### Options ``` - -dsa,--ecdsa <count> Sign data with ECDSA, [count] times. - -t,--test <test_suite> Test ECC support. [test_suite]: - - default: - - invalid: - - compression: - - twist: - - degenerate: - - cofactor: - - wrong: - - composite: - - test-vectors: - -dh,--ecdh <count> Do EC KeyAgreement (ECDH...), [count] - times. - -e,--export Export the defaut curve parameters of - the card(if any). - -V,--version Print version info. - -ln,--list-named <what> Print the list of supported named - curves and keys. - -h,--help Print help. - - -a,--all Test all curve sizes. - -b,--bit-size <bits> Set curve size. - - -fp,--prime-field Use a prime field. - -f2m,--binary-field Use a binary field. - - -c,--curve <curve_file> Use curve from file <curve_file> - (field,a,b,gx,gy,r,k). - -nc,--named-curve <cat/id> Use a named curve, from CurveDB: - <cat/id> - -u,--custom Use a custom curve (applet-side - embedded, SECG curves). - -npub,--named-public <cat/id> Use public key from KeyDB: <cat/id> - -pub,--public <pubkey_file> Use public key from file <pubkey_file> - (wx,wy). - -priv,--private <privkey_file> Use private key from file - <privkey_file> (s). - -npriv,--named-private <cat/id> Use private key from KeyDB: <cat/id> - -k,--key <key_file> Use keyPair from file <key_file> - (wx,wy,s). - -nk,--named-key <cat/id> Use keyPair from KeyDB: <cat/id> + -V,--version Print version info. + -h,--help Print help. + -ln,--list-named <what> Print the list of supported named + curves and keys, (CurveDB and KeyDB). + -ls,--list-suites List supported test suites. + -e,--export Export the defaut curve parameters + of the card(if any). + -g,--generate <amount> Generate <amount> of EC keys. + -t,--test <test_suite[:from[:to]]> Test ECC support. Optionally specify + a test number to run only a part of + a test suite. <test_suite>: + - default + - compression + - invalid + - twist + - degenerate + - cofactor + - wrong + - signature + - composite + - test-vectors + - edge-cases + - miscellaneous + -dh,--ecdh <count> Do EC KeyAgreement (ECDH...), + [count] times. + -dsa,--ecdsa <count> Sign data with ECDSA, [count] times. + -nf,--info Get applet info. - -i,--input <input_file> Input from file <input_file>, for ECDSA - signing. - -o,--output <output_file> Output into file <output_file>. - -l,--log <log_file> Log output into file [log_file]. - -v,--verbose Turn on verbose logging. - --format <format> Output format to use. One of: - text,yml,xml. - -f,--fresh Generate fresh keys (set domain - parameters before every generation). - --cleanup Send the cleanup command trigerring - JCSystem.requestObjectDeletion() - after some operations. - -s,--simulate Simulate a card with jcardsim instead - of using a terminal. - -y,--yes Accept all warnings and prompts. - - -ka,--ka-type <type> Set KeyAgreement object [type], - corresponds to JC.KeyAgreement - constants. - -sig,--sig-type <type> Set Signature object [type], - corresponds to JC.Signature constants. - -C,--color Print stuff with color, requires ANSI - terminal. + -b,--bit-size <bits> Set curve size. + -fp,--prime-field Use a prime field. + -f2m,--binary-field Use a binary field. + + -nc,--named-curve <cat/id> Use a named curve, from CurveDB: + <cat/id> + -c,--curve <curve_file> Use curve from file <curve_file> + (field,a,b,gx,gy,r,k). + -u,--custom Use a custom curve (applet-side + embedded, SECG curves). + + -npub,--named-public <cat/id> Use public key from KeyDB: <cat/id> + -pub,--public <pubkey_file> Use public key from file + <pubkey_file> (wx,wy). + + -npriv,--named-private <cat/id> Use private key from KeyDB: <cat/id> + -priv,--private <privkey_file> Use private key from file + <privkey_file> (s). + + -nk,--named-key <cat/id> Use KeyPair from KeyDB: <cat/id> + -k,--key <key_file> Use KeyPair from file <key_file> + (wx,wy,s). + + -i,--input <input_file> Input from file <input_file>, for + ECDSA signing. + -o,--output <output_file> Output into file <output_file>. The + file can be prefixed by the format + (one of text,yml,xml), such as: + xml:<output_file>. + -l,--log <log_file> Log output into file [log_file]. + -v,--verbose Turn on verbose logging. + --format <format> Output format to use. One of: + text,yml,xml. + + -f,--fresh Generate fresh keys (set domain + parameters before every generation). + --cleanup Send the cleanup command trigerring + JCSystem.requestObjectDeletion() + after some operations. + -s,--simulate Simulate a card with jcardsim + instead of using a terminal. + -y,--yes Accept all warnings and prompts. + -ka,--ka-type <type> Set KeyAgreement object [type], + corresponds to JavaCard KeyAgreement + constants. + -sig,--sig-type <type> Set Signature object [type], + corresponds to JavaCard Signature + constants. + -C,--color Print stuff with color, requires + ANSI terminal. ``` ### Actions @@ -160,6 +173,20 @@ For example: For more info about the curves and curve categories see [CURVES](docs/CURVES.md). +#### List test suites +`-ls / --list-suites` + +Lists the implemented test suites and gives their short description. + +#### Get applet info +`-nf / --info` + +Get and print ECTester applet info from an applet installed on a card. Outputs: + - ECTester applet version + - ECTester APDU support + - JavaCard API version + - JavaCard cleanup support + ### Example Snippet below shows running the default test suite while simulating(`-s`), so using JCardSim. diff --git a/src/cz/crcs/ectester/reader/ECTesterReader.java b/src/cz/crcs/ectester/reader/ECTesterReader.java index c3c0e13..1359dc2 100644 --- a/src/cz/crcs/ectester/reader/ECTesterReader.java +++ b/src/cz/crcs/ectester/reader/ECTesterReader.java @@ -37,10 +37,12 @@ import cz.crcs.ectester.reader.output.FileTestWriter; import cz.crcs.ectester.reader.output.ResponseWriter; import cz.crcs.ectester.reader.response.Response; import cz.crcs.ectester.reader.test.*; +import javacard.framework.ISO7816; import javacard.security.KeyPair; import org.apache.commons.cli.*; import javax.smartcardio.CardException; +import javax.smartcardio.ResponseAPDU; import javax.xml.parsers.ParserConfigurationException; import java.io.*; import java.net.URL; @@ -141,7 +143,12 @@ public class ECTesterReader { System.err.println(Colors.error("Failed to connect to card.")); System.exit(1); } - cardManager.send(SELECT_ECTESTERAPPLET); + ResponseAPDU selectResp = cardManager.send(SELECT_ECTESTERAPPLET); + if ((short) selectResp.getSW() != ISO7816.SW_NO_ERROR) { + System.err.println(Colors.error("Failed to select ECTester applet, is it installed?")); + cardManager.disconnectFromCard(); + System.exit(1); + } } // Setup logger and respWriter @@ -159,6 +166,8 @@ public class ECTesterReader { ecdh(); } else if (cli.hasOption("ecdsa")) { ecdsa(); + } else if (cli.hasOption("info")) { + info(); } //disconnect @@ -231,6 +240,8 @@ public class ECTesterReader { * -dh / --ecdh [count]] * -dsa / --ecdsa [count] * -ln / --list-named [obj] + * -ls / --list-suites + * -nfo / --info * * Options: * -b / --bit-size <b> // -a / --all @@ -271,12 +282,13 @@ public class ECTesterReader { actions.addOption(Option.builder("V").longOpt("version").desc("Print version info.").build()); actions.addOption(Option.builder("h").longOpt("help").desc("Print help.").build()); actions.addOption(Option.builder("ln").longOpt("list-named").desc("Print the list of supported named curves and keys.").hasArg().argName("what").optionalArg(true).build()); + actions.addOption(Option.builder("ls").longOpt("list-suites").desc("List supported test suites.").build()); actions.addOption(Option.builder("e").longOpt("export").desc("Export the defaut curve parameters of the card(if any).").build()); actions.addOption(Option.builder("g").longOpt("generate").desc("Generate <amount> of EC keys.").hasArg().argName("amount").optionalArg(true).build()); actions.addOption(Option.builder("t").longOpt("test").desc("Test ECC support. Optionally specify a test number to run only a part of a test suite. <test_suite>:\n- default:\n- compression:\n- invalid:\n- twist:\n- degenerate:\n- cofactor:\n- wrong:\n- signature:\n- composite:\n- test-vectors:\n- edge-cases:\n- miscellaneous:").hasArg().argName("test_suite[:from[:to]]").optionalArg(true).build()); actions.addOption(Option.builder("dh").longOpt("ecdh").desc("Do EC KeyAgreement (ECDH...), [count] times.").hasArg().argName("count").optionalArg(true).build()); actions.addOption(Option.builder("dsa").longOpt("ecdsa").desc("Sign data with ECDSA, [count] times.").hasArg().argName("count").optionalArg(true).build()); - actions.addOption(Option.builder("ls").longOpt("list-suites").desc("List supported test suites.").build()); + actions.addOption(Option.builder("nf").longOpt("info").desc("Get applet info.").build()); opts.addOptionGroup(actions); @@ -346,6 +358,14 @@ public class ECTesterReader { } } + private void info() throws CardException { + Response.GetInfo info = new Command.GetInfo(cardManager).send(); + System.out.println(String.format("ECTester applet version: %s", info.getVersion())); + System.out.println(String.format("ECTester applet APDU support: %s", (info.getBase() == ECTesterApplet.BASE_221) ? "basic" : "extended length")); + System.out.println(String.format("JavaCard API version: %.1f", info.getJavaCardVersion())); + System.out.println(String.format("JavaCard supports system cleanup: %s", info.getCleanupSupport())); + } + /** * Exports default card/simulation EC domain parameters to output file. * diff --git a/src/cz/crcs/ectester/reader/response/Response.java b/src/cz/crcs/ectester/reader/response/Response.java index b0cd0f8..afac1bc 100644 --- a/src/cz/crcs/ectester/reader/response/Response.java +++ b/src/cz/crcs/ectester/reader/response/Response.java @@ -461,7 +461,12 @@ public abstract class Response { public float getJavaCardVersion() { byte major = (byte) (jcVersion >> 8); byte minor = (byte) (jcVersion & 0xff); - int minorSize = (int) Math.ceil(Math.log10(minor)); + int minorSize; + if (minor == 0) { + minorSize = 1; + } else { + minorSize = (int) Math.ceil(Math.log10(minor)); + } return (major + ((float) (minor) / (minorSize * 10))); } |
