aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2018-02-10 19:59:41 +0100
committerJ08nY2018-02-10 19:59:41 +0100
commit22e4cfaf40a259be007bddc7b5cd765390de1c11 (patch)
tree7b7429f1215ee9e47efa4b7b2eb688c88b1cc22a
parentab80803c561d05407144ffb5f1c4d45d698fec0b (diff)
downloadECTester-22e4cfaf40a259be007bddc7b5cd765390de1c11.tar.gz
ECTester-22e4cfaf40a259be007bddc7b5cd765390de1c11.tar.zst
ECTester-22e4cfaf40a259be007bddc7b5cd765390de1c11.zip
-rw-r--r--src/cz/crcs/ectester/common/output/BaseTextTestWriter.java27
-rw-r--r--src/cz/crcs/ectester/common/output/BaseXMLTestWriter.java57
-rw-r--r--src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java21
-rw-r--r--src/cz/crcs/ectester/common/output/TestWriter.java17
-rw-r--r--src/cz/crcs/ectester/common/test/CompoundTest.java102
-rw-r--r--src/cz/crcs/ectester/common/test/Result.java6
-rw-r--r--src/cz/crcs/ectester/common/test/SimpleTest.java6
-rw-r--r--src/cz/crcs/ectester/common/test/Test.java44
-rw-r--r--src/cz/crcs/ectester/common/test/TestException.java7
-rw-r--r--src/cz/crcs/ectester/common/test/TestSuite.java22
-rw-r--r--src/cz/crcs/ectester/common/test/TestSuiteException.java13
-rw-r--r--src/cz/crcs/ectester/common/test/Testable.java2
-rw-r--r--src/cz/crcs/ectester/common/util/CardUtil.java14
-rw-r--r--src/cz/crcs/ectester/reader/ECTesterReader.java5
-rw-r--r--src/cz/crcs/ectester/reader/command/Command.java241
-rw-r--r--src/cz/crcs/ectester/reader/output/TextTestWriter.java6
-rw-r--r--src/cz/crcs/ectester/reader/output/XMLTestWriter.java11
-rw-r--r--src/cz/crcs/ectester/reader/output/YAMLTestWriter.java7
-rw-r--r--src/cz/crcs/ectester/reader/response/Response.java194
-rw-r--r--src/cz/crcs/ectester/reader/test/CardWrongCurvesSuite.java5
-rw-r--r--src/cz/crcs/ectester/reader/test/CommandTest.java18
-rw-r--r--src/cz/crcs/ectester/reader/test/CommandTestable.java2
-rw-r--r--src/cz/crcs/ectester/reader/test/PerformanceTest.java6
-rw-r--r--src/cz/crcs/ectester/standalone/ECTesterStandalone.java2
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java10
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java2
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java9
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java2
-rw-r--r--src/cz/crcs/ectester/standalone/test/SignatureTest.java10
-rw-r--r--src/cz/crcs/ectester/standalone/test/SignatureTestable.java2
30 files changed, 491 insertions, 379 deletions
diff --git a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
index 29eb671..f29d28e 100644
--- a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
+++ b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java
@@ -28,11 +28,10 @@ public abstract class BaseTextTestWriter implements TestWriter {
protected abstract String deviceString(TestSuite suite);
private String testString(Test t, String prefix) {
- if (!t.hasRun()) {
- return null;
- }
boolean compound = t instanceof CompoundTest;
+ Result result = t.getResult();
+
StringBuilder out = new StringBuilder();
out.append(t.ok() ? " OK " : "NOK ");
out.append(compound ? "┳ " : "━ ");
@@ -40,14 +39,14 @@ public abstract class BaseTextTestWriter implements TestWriter {
String widthSpec = "%-" + String.valueOf(width) + "s";
out.append(String.format(widthSpec, t.getDescription()));
out.append(" ┃ ");
- out.append(String.format("%-9s", t.getResultValue().name()));
+ out.append(String.format("%-9s", result.getValue().name()));
out.append(" ┃ ");
if (compound) {
CompoundTest test = (CompoundTest) t;
- out.append(test.getResultCause());
+ out.append(result.getCause().toString());
out.append(System.lineSeparator());
- Test[] tests = test.getTests();
+ Test[] tests = test.getStartedTests();
for (int i = 0; i < tests.length; ++i) {
if (i == tests.length - 1) {
out.append(prefix).append(" ┗ ");
@@ -76,6 +75,22 @@ public abstract class BaseTextTestWriter implements TestWriter {
output.flush();
}
+ private String errorString(Throwable error) {
+ StringBuilder sb = new StringBuilder();
+ for (Throwable t = error; t != null; t = t.getCause()) {
+ sb.append("═══ ").append(t.toString()).append(" ═══");
+ sb.append(System.lineSeparator());
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public void outputError(Test t, Throwable cause) {
+ output.println(testString(t, ""));
+ output.print(errorString(cause));
+ output.flush();
+ }
+
@Override
public void end() {
}
diff --git a/src/cz/crcs/ectester/common/output/BaseXMLTestWriter.java b/src/cz/crcs/ectester/common/output/BaseXMLTestWriter.java
index f3e9411..5d6d53d 100644
--- a/src/cz/crcs/ectester/common/output/BaseXMLTestWriter.java
+++ b/src/cz/crcs/ectester/common/output/BaseXMLTestWriter.java
@@ -24,6 +24,7 @@ public abstract class BaseXMLTestWriter implements TestWriter {
private DocumentBuilder db;
protected Document doc;
private Node root;
+ private Node tests;
public BaseXMLTestWriter(OutputStream output) throws ParserConfigurationException {
this.output = output;
@@ -40,19 +41,55 @@ public abstract class BaseXMLTestWriter implements TestWriter {
root = rootElem;
doc.appendChild(root);
root.appendChild(deviceElement(suite));
+ tests = doc.createElement("tests");
+ root.appendChild(tests);
}
protected abstract Element testableElement(Testable t);
protected abstract Element deviceElement(TestSuite suite);
+ private String causeString(Object cause) {
+ if (cause == null) {
+ return "null";
+ } else if (cause instanceof String) {
+ return (String) cause;
+ } else if (cause instanceof Throwable) {
+ StringBuilder sb = new StringBuilder();
+ for (Throwable t = (Throwable) cause; t != null; t = t.getCause()) {
+ sb.append(t.toString());
+ sb.append(System.lineSeparator());
+ }
+ return sb.toString();
+ } else {
+ return cause.toString();
+ }
+ }
+
+ private Element resultElement(Result result) {
+ Element resultElem = doc.createElement("result");
+
+ Element ok = doc.createElement("ok");
+ ok.setTextContent(String.valueOf(result.ok()));
+ Element value = doc.createElement("value");
+ value.setTextContent(result.getValue().name());
+ Element cause = doc.createElement("cause");
+ cause.setTextContent(causeString(cause));
+
+ resultElem.appendChild(ok);
+ resultElem.appendChild(value);
+ resultElem.appendChild(cause);
+
+ return resultElem;
+ }
+
private Element testElement(Test t) {
Element testElem;
if (t instanceof CompoundTest) {
CompoundTest test = (CompoundTest) t;
testElem = doc.createElement("test");
testElem.setAttribute("type", "compound");
- for (Test innerTest : test.getTests()) {
+ for (Test innerTest : test.getStartedTests()) {
testElem.appendChild(testElement(innerTest));
}
} else {
@@ -64,16 +101,7 @@ public abstract class BaseXMLTestWriter implements TestWriter {
description.setTextContent(t.getDescription());
testElem.appendChild(description);
- Element result = doc.createElement("result");
- Element ok = doc.createElement("ok");
- ok.setTextContent(String.valueOf(t.ok()));
- Element value = doc.createElement("value");
- value.setTextContent(t.getResultValue().name());
- Element cause = doc.createElement("cause");
- cause.setTextContent(t.getResultCause());
- result.appendChild(ok);
- result.appendChild(value);
- result.appendChild(cause);
+ Element result = resultElement(t.getResult());
testElem.appendChild(result);
return testElem;
@@ -83,7 +111,12 @@ public abstract class BaseXMLTestWriter implements TestWriter {
public void outputTest(Test t) {
if (!t.hasRun())
return;
- root.appendChild(testElement(t));
+ tests.appendChild(testElement(t));
+ }
+
+ @Override
+ public void outputError(Test t, Throwable cause) {
+ tests.appendChild(testElement(t));
}
@Override
diff --git a/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java b/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java
index 0769e83..1e13082 100644
--- a/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java
+++ b/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java
@@ -41,6 +41,14 @@ public abstract class BaseYAMLTestWriter implements TestWriter {
abstract protected Map<String, Object> deviceObject(TestSuite suite);
+ private Map<String, Object> resultObject(Result result) {
+ Map<String, Object> resultObject = new HashMap<>();
+ resultObject.put("ok", result.ok());
+ resultObject.put("value", result.getValue().name());
+ resultObject.put("cause", result.getCause());
+ return resultObject;
+ }
+
private Map<String, Object> testObject(Test t) {
Map<String, Object> testObj;
if (t instanceof CompoundTest) {
@@ -48,7 +56,7 @@ public abstract class BaseYAMLTestWriter implements TestWriter {
testObj = new HashMap<>();
testObj.put("type", "compound");
List<Map<String, Object>> innerTests = new LinkedList<>();
- for (Test innerTest : test.getTests()) {
+ for (Test innerTest : test.getStartedTests()) {
innerTests.add(testObject(innerTest));
}
testObj.put("tests", innerTests);
@@ -58,11 +66,7 @@ public abstract class BaseYAMLTestWriter implements TestWriter {
}
testObj.put("desc", t.getDescription());
- Map<String, Object> result = new HashMap<>();
- result.put("ok", t.ok());
- result.put("value", t.getResultValue().name());
- result.put("cause", t.getResultCause());
- testObj.put("result", result);
+ testObj.put("result", resultObject(t.getResult()));
return testObj;
}
@@ -75,6 +79,11 @@ public abstract class BaseYAMLTestWriter implements TestWriter {
}
@Override
+ public void outputError(Test t, Throwable cause) {
+ tests.add(testObject(t));
+ }
+
+ @Override
public void end() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
diff --git a/src/cz/crcs/ectester/common/output/TestWriter.java b/src/cz/crcs/ectester/common/output/TestWriter.java
index 0ecfd5a..5fa7f67 100644
--- a/src/cz/crcs/ectester/common/output/TestWriter.java
+++ b/src/cz/crcs/ectester/common/output/TestWriter.java
@@ -7,9 +7,26 @@ import cz.crcs.ectester.common.test.TestSuite;
* @author Jan Jancar johny@neuromancer.sk
*/
public interface TestWriter {
+ /**
+ * @param suite
+ */
void begin(TestSuite suite);
+ /**
+ *
+ * @param t
+ */
void outputTest(Test t);
+ /**
+ *
+ * @param t
+ * @param cause
+ */
+ void outputError(Test t, Throwable cause);
+
+ /**
+ *
+ */
void end();
}
diff --git a/src/cz/crcs/ectester/common/test/CompoundTest.java b/src/cz/crcs/ectester/common/test/CompoundTest.java
index 69122b0..4b1df16 100644
--- a/src/cz/crcs/ectester/common/test/CompoundTest.java
+++ b/src/cz/crcs/ectester/common/test/CompoundTest.java
@@ -2,6 +2,7 @@ package cz.crcs.ectester.common.test;
import java.util.Arrays;
import java.util.Objects;
+import java.util.function.Consumer;
import java.util.function.Function;
/**
@@ -10,26 +11,34 @@ import java.util.function.Function;
* @author Jan Jancar johny@neuromancer.sk
*/
public class CompoundTest extends Test {
- private Function<Test[], Result> callback;
+ private Function<Test[], Result> resultCallback;
+ private Consumer<Test[]> runCallback;
private Test[] tests;
private String description = "";
- private CompoundTest(Function<Test[], Result> callback, Test... tests) {
- this.callback = callback;
+ private final static Consumer<Test[]> RUN_ALL = tests -> {
+ for (Test t : tests) {
+ t.run();
+ }
+ };
+
+ private CompoundTest(Function<Test[], Result> resultCallback, Consumer<Test[]> runCallback, Test... tests) {
+ this.resultCallback = resultCallback;
+ this.runCallback = runCallback;
this.tests = Arrays.stream(tests).filter(Objects::nonNull).toArray(Test[]::new);
}
- private CompoundTest(Function<Test[], Result> callback, String descripiton, Test... tests) {
- this(callback, tests);
+ private CompoundTest(Function<Test[], Result> callback, Consumer<Test[]> runCallback, String descripiton, Test... tests) {
+ this(callback, runCallback, tests);
this.description = descripiton;
}
public static CompoundTest function(Function<Test[], Result> callback, Test... tests) {
- return new CompoundTest(callback, tests);
+ return new CompoundTest(callback, RUN_ALL, tests);
}
public static CompoundTest function(Function<Test[], Result> callback, String description, Test... tests) {
- return new CompoundTest(callback, description, tests);
+ return new CompoundTest(callback, RUN_ALL, description, tests);
}
public static CompoundTest all(Result.ExpectedValue what, Test... all) {
@@ -40,7 +49,7 @@ public class CompoundTest extends Test {
}
}
return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result.");
- }, all);
+ }, RUN_ALL, all);
}
public static CompoundTest all(Result.ExpectedValue what, String description, Test... all) {
@@ -49,7 +58,31 @@ public class CompoundTest extends Test {
return result;
}
- public static CompoundTest any(Result.ExpectedValue what, Test... any) {
+ public static CompoundTest greedyAll(Result.ExpectedValue what, Test... all) {
+ return new CompoundTest((tests) -> {
+ for (Test test : tests) {
+ if (!Result.Value.fromExpected(what, test.ok()).ok()) {
+ return new Result(Result.Value.FAILURE, "Some sub-tests did not have the expected result.");
+ }
+ }
+ return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result.");
+ }, (tests) -> {
+ for (Test t : tests) {
+ t.run();
+ if (!t.ok()) {
+ break;
+ }
+ }
+ }, all);
+ }
+
+ public static CompoundTest greedyAll(Result.ExpectedValue what, String description, Test... all) {
+ CompoundTest result = CompoundTest.greedyAll(what, all);
+ result.setDescription(description);
+ return result;
+ }
+
+ public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) {
return new CompoundTest((tests) -> {
for (Test test : tests) {
if (Result.Value.fromExpected(what, test.ok()).ok()) {
@@ -57,9 +90,33 @@ public class CompoundTest extends Test {
}
}
return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result.");
+ }, (tests) -> {
+ for (Test t : tests) {
+ t.run();
+ if (t.ok()) {
+ break;
+ }
+ }
}, any);
}
+ public static CompoundTest greedyAny(Result.ExpectedValue what, String description, Test... any) {
+ CompoundTest result = CompoundTest.greedyAny(what, any);
+ result.setDescription(description);
+ return result;
+ }
+
+ public static CompoundTest any(Result.ExpectedValue what, Test... any) {
+ return new CompoundTest((tests) -> {
+ for (Test test : tests) {
+ if (Result.Value.fromExpected(what, test.ok()).ok()) {
+ return new Result(Result.Value.SUCCESS, "Some sub-tests did have the expected result.");
+ }
+ }
+ return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result.");
+ }, RUN_ALL, any);
+ }
+
public static CompoundTest any(Result.ExpectedValue what, String description, Test... any) {
CompoundTest result = CompoundTest.any(what, any);
result.setDescription(description);
@@ -74,7 +131,7 @@ public class CompoundTest extends Test {
}
}
return new Result(Result.Value.SUCCESS, "All sub-tests matched the expected mask.");
- }, masked);
+ }, RUN_ALL, masked);
}
public static CompoundTest mask(Result.ExpectedValue[] results, String description, Test... masked) {
@@ -84,20 +141,25 @@ public class CompoundTest extends Test {
}
public Test[] getTests() {
- return tests;
+ return tests.clone();
}
- @Override
- public void run() throws TestException {
- if (hasRun)
- return;
+ public Test[] getRunTests() {
+ return Arrays.stream(tests).filter(Test::hasRun).toArray(Test[]::new);
+ }
- for (Test test : tests) {
- test.run();
- }
+ public Test[] getStartedTests() {
+ return Arrays.stream(tests).filter(Test::hasStarted).toArray(Test[]::new);
+ }
- result = callback.apply(tests);
- this.hasRun = true;
+ public Test[] getSkippedTests() {
+ return Arrays.stream(tests).filter((test) -> !test.hasRun()).toArray(Test[]::new);
+ }
+
+ @Override
+ protected void runSelf() {
+ runCallback.accept(tests);
+ result = resultCallback.apply(tests);
}
public void setDescription(String description) {
diff --git a/src/cz/crcs/ectester/common/test/Result.java b/src/cz/crcs/ectester/common/test/Result.java
index 11fcb4d..5d15a60 100644
--- a/src/cz/crcs/ectester/common/test/Result.java
+++ b/src/cz/crcs/ectester/common/test/Result.java
@@ -8,13 +8,13 @@ package cz.crcs.ectester.common.test;
public class Result {
private Value value;
- private String cause;
+ private Object cause;
public Result(Value value) {
this.value = value;
}
- public Result(Value value, String cause) {
+ public Result(Value value, Object cause) {
this(value);
this.cause = cause;
}
@@ -23,7 +23,7 @@ public class Result {
return value;
}
- public String getCause() {
+ public Object getCause() {
return cause;
}
diff --git a/src/cz/crcs/ectester/common/test/SimpleTest.java b/src/cz/crcs/ectester/common/test/SimpleTest.java
index f68320a..85f1072 100644
--- a/src/cz/crcs/ectester/common/test/SimpleTest.java
+++ b/src/cz/crcs/ectester/common/test/SimpleTest.java
@@ -16,4 +16,10 @@ public abstract class SimpleTest<T extends BaseTestable> extends Test {
public T getTestable() {
return testable;
}
+
+ @Override
+ protected void runSelf() {
+ testable.run();
+ result = callback.apply(testable);
+ }
}
diff --git a/src/cz/crcs/ectester/common/test/Test.java b/src/cz/crcs/ectester/common/test/Test.java
index 3d0baf6..868fd22 100644
--- a/src/cz/crcs/ectester/common/test/Test.java
+++ b/src/cz/crcs/ectester/common/test/Test.java
@@ -9,31 +9,15 @@ import static cz.crcs.ectester.common.test.Result.Value;
*/
public abstract class Test implements Testable {
protected boolean hasRun;
+ protected boolean hasStarted;
protected Result result;
public Result getResult() {
- if (!hasRun) {
- return null;
- }
return result;
}
- public Value getResultValue() {
- if (!hasRun) {
- return null;
- }
- return result.getValue();
- }
-
- public String getResultCause() {
- if (!hasRun) {
- return null;
- }
- return result.getCause();
- }
-
public boolean ok() {
- if (!hasRun) {
+ if (result == null) {
return true;
}
return result.ok();
@@ -41,7 +25,7 @@ public abstract class Test implements Testable {
@Override
public boolean error() {
- if (!hasRun) {
+ if (result == null) {
return false;
}
return result.compareTo(Value.ERROR);
@@ -52,15 +36,35 @@ public abstract class Test implements Testable {
return hasRun;
}
+ public boolean hasStarted() {
+ return hasStarted;
+ }
+
@Override
public void reset() {
hasRun = false;
+ hasStarted = false;
result = null;
}
public abstract String getDescription();
@Override
- public abstract void run() throws TestException;
+ public void run() {
+ if (hasRun)
+ return;
+ try {
+ hasStarted = true;
+ runSelf();
+ hasRun = true;
+ } catch (TestException e) {
+ result = new Result(Value.ERROR, e);
+ throw e;
+ } catch (Exception e) {
+ result = new Result(Value.ERROR, e);
+ throw new TestException(e);
+ }
+ }
+ protected abstract void runSelf();
}
diff --git a/src/cz/crcs/ectester/common/test/TestException.java b/src/cz/crcs/ectester/common/test/TestException.java
index 008e9f6..291a073 100644
--- a/src/cz/crcs/ectester/common/test/TestException.java
+++ b/src/cz/crcs/ectester/common/test/TestException.java
@@ -2,11 +2,12 @@ package cz.crcs.ectester.common.test;
/**
* A TestException is an Exception that can be thrown during the running of a Testable,
- * or a TestSuite. It means that the Testable/TestSuite encountered an unexpected error
- * during it's run which points to an error in ECTester or it's runtime environment.cd
+ * or a Test. It means that the Testable/TestSuite encountered an unexpected error
+ * and has to terminate.
+ *
* @author Jan Jancar johny@neuromancer.sk
*/
-public class TestException extends Exception {
+public class TestException extends RuntimeException {
public TestException(Throwable e) {
super(e);
}
diff --git a/src/cz/crcs/ectester/common/test/TestSuite.java b/src/cz/crcs/ectester/common/test/TestSuite.java
index 2de0b9c..ca1b199 100644
--- a/src/cz/crcs/ectester/common/test/TestSuite.java
+++ b/src/cz/crcs/ectester/common/test/TestSuite.java
@@ -9,6 +9,7 @@ public abstract class TestSuite {
protected String name;
protected String description;
protected TestWriter writer;
+ private Test running;
public TestSuite(TestWriter writer, String name, String description) {
this.writer = writer;
@@ -16,12 +17,18 @@ public abstract class TestSuite {
this.description = description;
}
- public void run() throws TestException {
+ /**
+ *
+ */
+ public void run() {
writer.begin(this);
try {
runTests();
+ } catch (TestException e) {
+ writer.outputError(running, e);
} catch (Exception e) {
- throw new TestException(e);
+ writer.end();
+ throw new TestSuiteException(e);
}
writer.end();
}
@@ -33,8 +40,10 @@ public abstract class TestSuite {
* @return The test that was run.
* @throws TestException
*/
- protected Test runTest(Test t) throws TestException {
+ protected Test runTest(Test t) {
+ running = t;
t.run();
+ running = null;
return t;
}
@@ -45,12 +54,15 @@ public abstract class TestSuite {
* @return The test that was run.
* @throws TestException
*/
- protected Test doTest(Test t) throws TestException {
- t.run();
+ protected Test doTest(Test t) {
+ runTest(t);
writer.outputTest(t);
return t;
}
+ /**
+ *
+ */
protected abstract void runTests() throws Exception;
public String getName() {
diff --git a/src/cz/crcs/ectester/common/test/TestSuiteException.java b/src/cz/crcs/ectester/common/test/TestSuiteException.java
new file mode 100644
index 0000000..cc3cfda
--- /dev/null
+++ b/src/cz/crcs/ectester/common/test/TestSuiteException.java
@@ -0,0 +1,13 @@
+package cz.crcs.ectester.common.test;
+
+/**
+ * An unexpected exception was thrown while running a TestSuite, outside Test
+ * or a Testable.
+ *
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public class TestSuiteException extends RuntimeException {
+ public TestSuiteException(Throwable e) {
+ super(e);
+ }
+}
diff --git a/src/cz/crcs/ectester/common/test/Testable.java b/src/cz/crcs/ectester/common/test/Testable.java
index 33c9485..ea1380a 100644
--- a/src/cz/crcs/ectester/common/test/Testable.java
+++ b/src/cz/crcs/ectester/common/test/Testable.java
@@ -29,5 +29,5 @@ public interface Testable {
*
* @throws TestException If an unexpected exception/error is encountered.
*/
- void run() throws TestException;
+ void run();
}
diff --git a/src/cz/crcs/ectester/common/util/CardUtil.java b/src/cz/crcs/ectester/common/util/CardUtil.java
index dbe53be..7d7bb78 100644
--- a/src/cz/crcs/ectester/common/util/CardUtil.java
+++ b/src/cz/crcs/ectester/common/util/CardUtil.java
@@ -281,4 +281,18 @@ public class CardUtil {
return "";
}
}
+
+ public static String getParameterString(short params) {
+ String what = "";
+ if (params == EC_Consts.PARAMETERS_DOMAIN_F2M || params == EC_Consts.PARAMETERS_DOMAIN_FP) {
+ what = "curve";
+ } else if (params == EC_Consts.PARAMETER_W) {
+ what = "pubkey";
+ } else if (params == EC_Consts.PARAMETER_S) {
+ what = "privkey";
+ } else if (params == EC_Consts.PARAMETERS_KEYPAIR) {
+ what = "keypair";
+ }
+ return what;
+ }
}
diff --git a/src/cz/crcs/ectester/reader/ECTesterReader.java b/src/cz/crcs/ectester/reader/ECTesterReader.java
index e05f9be..22621ef 100644
--- a/src/cz/crcs/ectester/reader/ECTesterReader.java
+++ b/src/cz/crcs/ectester/reader/ECTesterReader.java
@@ -179,7 +179,7 @@ public class ECTesterReader {
System.err.println("File " + fnfe.getMessage() + " not found.");
} catch (ParseException | IOException ex) {
System.err.println(ex.getMessage());
- } catch (CardException | TestException ex) {
+ } catch (CardException ex) {
if (logger != null)
logger.println(ex.getMessage());
ex.printStackTrace();
@@ -394,10 +394,9 @@ public class ECTesterReader {
/**
* Tests Elliptic curve support for a given curve/curves.
*
- * @throws CardException if APDU transmission fails
* @throws IOException if an IO error occurs when writing to key file.
*/
- private void test() throws IOException, TestException, ParserConfigurationException {
+ private void test() throws IOException, ParserConfigurationException {
TestWriter writer = null;
if (cfg.format == null) {
writer = new TextTestWriter(logger.getPrintStream());
diff --git a/src/cz/crcs/ectester/reader/command/Command.java b/src/cz/crcs/ectester/reader/command/Command.java
index eefbc27..5e025d8 100644
--- a/src/cz/crcs/ectester/reader/command/Command.java
+++ b/src/cz/crcs/ectester/reader/command/Command.java
@@ -2,15 +2,16 @@ package cz.crcs.ectester.reader.command;
import cz.crcs.ectester.applet.ECTesterApplet;
import cz.crcs.ectester.applet.EC_Consts;
+import cz.crcs.ectester.common.ec.EC_Curve;
+import cz.crcs.ectester.common.ec.EC_Key;
+import cz.crcs.ectester.common.ec.EC_Keypair;
+import cz.crcs.ectester.common.ec.EC_Params;
import cz.crcs.ectester.common.util.ByteUtil;
+import cz.crcs.ectester.common.util.CardUtil;
import cz.crcs.ectester.data.EC_Store;
import cz.crcs.ectester.reader.CardMngr;
import cz.crcs.ectester.reader.ECTesterReader;
import cz.crcs.ectester.reader.response.Response;
-import cz.crcs.ectester.common.ec.EC_Curve;
-import cz.crcs.ectester.common.ec.EC_Key;
-import cz.crcs.ectester.common.ec.EC_Keypair;
-import cz.crcs.ectester.common.ec.EC_Params;
import javacard.security.KeyPair;
import javax.smartcardio.CardException;
@@ -46,6 +47,8 @@ public abstract class Command {
return result;
}
+ public abstract String getDescription();
+
/**
* @param keyPair which keyPair/s (local/remote) to set curve domain parameters on
@@ -179,111 +182,117 @@ public abstract class Command {
return new Command.Set(cardManager, keyPair, EC_Consts.CURVE_external, params, data);
}
-
/**
*
*/
- public static class Allocate extends Command {
- private byte keyPair;
- private short keyLength;
- private byte keyClass;
+ public static class AllocateKeyAgreement extends Command {
+ private byte kaType;
/**
- * Creates the INS_ALLOCATE instruction.
+ * Creates the INS_ALLOCATE_KA instruction.
*
* @param cardManager cardManager to send APDU through
- * @param keyPair which keyPair to use, local/remote (KEYPAIR_* | ...)
- * @param keyLength key length to set
- * @param keyClass key class to allocate
+ * @param kaType which type of KeyAgreement to use
*/
- public Allocate(CardMngr cardManager, byte keyPair, short keyLength, byte keyClass) {
+ public AllocateKeyAgreement(CardMngr cardManager, byte kaType) {
super(cardManager);
- this.keyPair = keyPair;
- this.keyLength = keyLength;
- this.keyClass = keyClass;
-
- byte[] data = new byte[]{0, 0, keyClass};
- ByteUtil.setShort(data, 0, keyLength);
- this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE, keyPair, 0x00, data);
+ this.kaType = kaType;
+ byte[] data = new byte[]{kaType};
+ this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE_KA, 0x00, 0x00, data);
}
@Override
- public Response.Allocate send() throws CardException {
+ public Response.AllocateKeyAgreement send() throws CardException {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Allocate(response, elapsed, keyPair, keyLength, keyClass);
+ return new Response.AllocateKeyAgreement(response, getDescription(), elapsed, kaType);
}
@Override
- public String toString() {
- return "Allocate";
+ public String getDescription() {
+ return String.format("Allocate KeyAgreement(%s) object", CardUtil.getKATypeString(kaType));
}
}
/**
*
*/
- public static class AllocateKeyAgreement extends Command {
- private byte kaType;
+ public static class AllocateSignature extends Command {
+ private byte sigType;
/**
- * Creates the INS_ALLOCATE_KA instruction.
+ * Creates the INS_ALLOCATE_SIG instruction.
*
* @param cardManager cardManager to send APDU through
- * @param kaType which type of KeyAgreement to use
+ * @param sigType which type of Signature to use
*/
- public AllocateKeyAgreement(CardMngr cardManager, byte kaType) {
+ public AllocateSignature(CardMngr cardManager, byte sigType) {
super(cardManager);
- this.kaType = kaType;
- byte[] data = new byte[]{kaType};
- this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE_KA, 0x00, 0x00, data);
+ this.sigType = sigType;
+ byte[] data = new byte[]{sigType};
+ this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE_SIG, 0x00, 0x00, data);
}
@Override
- public Response.AllocateKeyAgreement send() throws CardException {
+ public Response.AllocateSignature send() throws CardException {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.AllocateKeyAgreement(response, elapsed, kaType);
+ return new Response.AllocateSignature(response, getDescription(), elapsed, sigType);
}
@Override
- public String toString() {
- return "AllocateKeyAgreement";
+ public String getDescription() {
+ return String.format("Allocate Signature(%s) object", CardUtil.getSigTypeString(sigType));
}
}
/**
*
*/
- public static class AllocateSignature extends Command {
- private byte sigType;
+ public static class Allocate extends Command {
+ private byte keyPair;
+ private short keyLength;
+ private byte keyClass;
/**
- * Creates the INS_ALLOCATE_SIG instruction.
+ * Creates the INS_ALLOCATE instruction.
*
* @param cardManager cardManager to send APDU through
- * @param sigType which type of Signature to use
+ * @param keyPair which keyPair to use, local/remote (KEYPAIR_* | ...)
+ * @param keyLength key length to set
+ * @param keyClass key class to allocate
*/
- public AllocateSignature(CardMngr cardManager, byte sigType) {
+ public Allocate(CardMngr cardManager, byte keyPair, short keyLength, byte keyClass) {
super(cardManager);
- this.sigType = sigType;
- byte[] data = new byte[]{sigType};
- this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE_SIG, 0x00, 0x00, data);
+ this.keyPair = keyPair;
+ this.keyLength = keyLength;
+ this.keyClass = keyClass;
+
+ byte[] data = new byte[]{0, 0, keyClass};
+ ByteUtil.setShort(data, 0, keyLength);
+ this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ALLOCATE, keyPair, 0x00, data);
}
@Override
- public Response.AllocateSignature send() throws CardException {
+ public Response.Allocate send() throws CardException {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.AllocateSignature(response, elapsed, sigType);
+ return new Response.Allocate(response, getDescription(), elapsed, keyPair, keyLength, keyClass);
}
@Override
- public String toString() {
- return "AllocateSignature";
+ public String getDescription() {
+ String field = keyClass == KeyPair.ALG_EC_FP ? "ALG_EC_FP" : "ALG_EC_F2M";
+ String key;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ key = "both keypairs";
+ } else {
+ key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Allocate %s %db %s", key, keyLength, field);
}
}
@@ -309,12 +318,18 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Clear(response, elapsed, keyPair);
+ return new Response.Clear(response, getDescription(), elapsed, keyPair);
}
@Override
- public String toString() {
- return "Clear";
+ public String getDescription() {
+ String key;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ key = "both keypairs";
+ } else {
+ key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Clear %s", key);
}
}
@@ -358,12 +373,32 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Set(response, elapsed, keyPair, curve, params);
+ return new Response.Set(response, getDescription(), elapsed, keyPair, curve, params);
}
@Override
- public String toString() {
- return "Set";
+ public String getDescription() {
+ String name;
+ switch (curve) {
+ case EC_Consts.CURVE_default:
+ name = "default";
+ break;
+ case EC_Consts.CURVE_external:
+ name = "external";
+ break;
+ default:
+ name = "custom";
+ break;
+ }
+ String what = CardUtil.getParameterString(params);
+
+ String pair;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ pair = "both keypairs";
+ } else {
+ pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Set %s %s parameters on %s", name, what, pair);
}
}
@@ -402,12 +437,20 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Corrupt(response, elapsed, keyPair, key, params, corruption);
+ return new Response.Corrupt(response, getDescription(), elapsed, keyPair, key, params, corruption);
}
@Override
- public String toString() {
- return "Corrupt";
+ public String getDescription() {
+ String corrupt = CardUtil.getCorruption(corruption);
+
+ String pair;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ pair = "both keypairs";
+ } else {
+ pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Corrupt params of %s, %s", pair, corrupt);
}
}
@@ -435,12 +478,18 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Generate(response, elapsed, keyPair);
+ return new Response.Generate(response, getDescription(), elapsed, keyPair);
}
@Override
- public String toString() {
- return "Generate";
+ public String getDescription() {
+ String key;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ key = "both keypairs";
+ } else {
+ key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Generate %s", key);
}
}
@@ -477,12 +526,26 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Export(response, elapsed, keyPair, key, params);
+ return new Response.Export(response, getDescription(), elapsed, keyPair, key, params);
}
@Override
- public String toString() {
- return "Export";
+ public String getDescription() {
+ String what = CardUtil.getParameterString(params);
+
+ String source;
+ if (key == EC_Consts.KEY_BOTH) {
+ source = "both keys";
+ } else {
+ source = ((key == EC_Consts.KEY_PUBLIC) ? "public" : "private") + " key";
+ }
+ String pair;
+ if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
+ pair = "both keypairs";
+ } else {
+ pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
+ }
+ return String.format("Export %s params from %s of %s", what, source, pair);
}
}
@@ -514,7 +577,7 @@ public abstract class Command {
this.corruption = corruption;
this.type = type;
- byte[] data = new byte[]{export, 0,0, type};
+ byte[] data = new byte[]{export, 0, 0, type};
ByteUtil.setShort(data, 1, corruption);
this.cmd = new CommandAPDU(ECTesterApplet.CLA_ECTESTERAPPLET, ECTesterApplet.INS_ECDH, pubkey, privkey, data);
@@ -525,12 +588,23 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.ECDH(response, elapsed, pubkey, privkey, export, corruption, type);
+ return new Response.ECDH(response, getDescription(), elapsed, pubkey, privkey, export, corruption, type);
}
@Override
- public String toString() {
- return "ECDH";
+ public String getDescription() {
+ String algo = CardUtil.getKATypeString(type);
+
+ String pub = pubkey == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
+ String priv = privkey == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
+
+ String validity;
+ if (corruption == EC_Consts.CORRUPTION_NONE) {
+ validity = "unchanged";
+ } else {
+ validity = CardUtil.getCorruption(corruption);
+ }
+ return String.format("%s of %s pubkey and %s privkey(%s point)", algo, pub, priv, validity);
}
}
@@ -575,12 +649,22 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.ECDH(response, elapsed, ECTesterApplet.KEYPAIR_REMOTE, privkey, export, corruption, type);
+ return new Response.ECDH(response, getDescription(), elapsed, ECTesterApplet.KEYPAIR_REMOTE, privkey, export, corruption, type);
}
@Override
- public String toString() {
- return "ECDH_direct";
+ public String getDescription() {
+ String algo = CardUtil.getKATypeString(type);
+
+ String priv = privkey == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
+
+ String validity;
+ if (corruption == EC_Consts.CORRUPTION_NONE) {
+ validity = "unchanged";
+ } else {
+ validity = CardUtil.getCorruption(corruption);
+ }
+ return String.format("%s of external pubkey and %s privkey(%s point)", algo, priv, validity);
}
}
@@ -622,12 +706,15 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.ECDSA(response, elapsed, keyPair, sigType, export, raw);
+ return new Response.ECDSA(response, getDescription(), elapsed, keyPair, sigType, export, raw);
}
@Override
- public String toString() {
- return "ECDSA";
+ public String getDescription() {
+ String algo = CardUtil.getSigTypeString(sigType);
+ String key = keyPair == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
+ String data = raw == null ? "random" : "provided";
+ return String.format("%s with %s keypair(%s data)", algo, key, data);
}
}
@@ -650,12 +737,12 @@ public abstract class Command {
long elapsed = -System.nanoTime();
ResponseAPDU response = cardManager.send(cmd);
elapsed += System.nanoTime();
- return new Response.Cleanup(response, elapsed);
+ return new Response.Cleanup(response, getDescription(), elapsed);
}
@Override
- public String toString() {
- return "Cleanup";
+ public String getDescription() {
+ return "Request JCSystem object deletion";
}
}
}
diff --git a/src/cz/crcs/ectester/reader/output/TextTestWriter.java b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
index eb52937..cc168de 100644
--- a/src/cz/crcs/ectester/reader/output/TextTestWriter.java
+++ b/src/cz/crcs/ectester/reader/output/TextTestWriter.java
@@ -5,6 +5,7 @@ import cz.crcs.ectester.common.test.TestSuite;
import cz.crcs.ectester.common.test.Testable;
import cz.crcs.ectester.common.util.ByteUtil;
import cz.crcs.ectester.reader.CardMngr;
+import cz.crcs.ectester.reader.response.Response;
import cz.crcs.ectester.reader.test.CardTestSuite;
import cz.crcs.ectester.reader.test.CommandTestable;
@@ -27,7 +28,10 @@ public class TextTestWriter extends BaseTextTestWriter {
protected String testableString(Testable t) {
if (t instanceof CommandTestable) {
CommandTestable cmd = (CommandTestable) t;
- return writer.responseSuffix(cmd.getResponse());
+ Response response = cmd.getResponse();
+ if (response != null) {
+ return writer.responseSuffix(response);
+ }
}
return "";
}
diff --git a/src/cz/crcs/ectester/reader/output/XMLTestWriter.java b/src/cz/crcs/ectester/reader/output/XMLTestWriter.java
index d3674e8..ebe07a6 100644
--- a/src/cz/crcs/ectester/reader/output/XMLTestWriter.java
+++ b/src/cz/crcs/ectester/reader/output/XMLTestWriter.java
@@ -26,16 +26,27 @@ public class XMLTestWriter extends BaseXMLTestWriter {
private Element commandElement(Command c) {
Element commandElem = doc.createElement("command");
+ if (c == null) {
+ return commandElem;
+ }
Element apdu = doc.createElement("apdu");
apdu.setTextContent(ByteUtil.bytesToHex(c.getAPDU().getBytes()));
commandElem.appendChild(apdu);
+ Element description = doc.createElement("desc");
+ description.setTextContent(c.getDescription());
+ commandElem.appendChild(description);
+
return commandElem;
}
private Element responseElement(Response r) {
Element responseElem = doc.createElement("response");
+ if (r == null) {
+ return responseElem;
+ }
+
responseElem.setAttribute("successful", r.successful() ? "true" : "false");
Element apdu = doc.createElement("apdu");
diff --git a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java
index 199f2c0..4f83ca8 100644
--- a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java
+++ b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java
@@ -27,12 +27,19 @@ public class YAMLTestWriter extends BaseYAMLTestWriter {
private Map<String, Object> commandObject(Command c) {
Map<String, Object> commandObj = new HashMap<>();
+ if (c == null) {
+ return commandObj;
+ }
commandObj.put("apdu", ByteUtil.bytesToHex(c.getAPDU().getBytes()));
+ commandObj.put("desc", c.getDescription());
return commandObj;
}
private Map<String, Object> responseObject(Response r) {
Map<String, Object> responseObj = new HashMap<>();
+ if (r == null) {
+ return responseObj;
+ }
responseObj.put("successful", r.successful());
responseObj.put("apdu", ByteUtil.bytesToHex(r.getAPDU().getBytes()));
responseObj.put("natural_sw", Short.toUnsignedInt(r.getNaturalSW()));
diff --git a/src/cz/crcs/ectester/reader/response/Response.java b/src/cz/crcs/ectester/reader/response/Response.java
index 1ae59de..5a9a458 100644
--- a/src/cz/crcs/ectester/reader/response/Response.java
+++ b/src/cz/crcs/ectester/reader/response/Response.java
@@ -3,9 +3,7 @@ package cz.crcs.ectester.reader.response;
import cz.crcs.ectester.applet.ECTesterApplet;
import cz.crcs.ectester.applet.EC_Consts;
import cz.crcs.ectester.common.util.ByteUtil;
-import cz.crcs.ectester.common.util.CardUtil;
import javacard.framework.ISO7816;
-import javacard.security.KeyPair;
import javax.smartcardio.ResponseAPDU;
@@ -20,9 +18,11 @@ public abstract class Response {
private byte[][] params;
private boolean success = true;
private boolean error = false;
+ private String description;
- public Response(ResponseAPDU response, long time) {
+ public Response(ResponseAPDU response, String description, long time) {
this.resp = response;
+ this.description = description;
this.time = time;
}
@@ -127,7 +127,9 @@ public abstract class Response {
return this.error;
}
- public abstract String getDescription();
+ public String getDescription() {
+ return description;
+ }
/**
*
@@ -135,17 +137,12 @@ public abstract class Response {
public static class AllocateKeyAgreement extends Response {
private byte kaType;
- public AllocateKeyAgreement(ResponseAPDU response, long time, byte kaType) {
- super(response, time);
+ public AllocateKeyAgreement(ResponseAPDU response, String description, long time, byte kaType) {
+ super(response, description, time);
this.kaType = kaType;
parse(1, 0);
}
-
- @Override
- public String getDescription() {
- return String.format("Allocated KeyAgreement(%s) object", CardUtil.getKATypeString(this.kaType));
- }
}
/**
@@ -154,17 +151,12 @@ public abstract class Response {
public static class AllocateSignature extends Response {
private byte sigType;
- public AllocateSignature(ResponseAPDU response, long time, byte sigType) {
- super(response, time);
+ public AllocateSignature(ResponseAPDU response, String description, long time, byte sigType) {
+ super(response, description, time);
this.sigType = sigType;
parse(1, 0);
}
-
- @Override
- public String getDescription() {
- return String.format("Allocated Signature(%s) object", CardUtil.getSigTypeString(this.sigType));
- }
}
/**
@@ -175,8 +167,8 @@ public abstract class Response {
private short keyLength;
private byte keyClass;
- public Allocate(ResponseAPDU response, long time, byte keyPair, short keyLength, byte keyClass) {
- super(response, time);
+ public Allocate(ResponseAPDU response, String description, long time, byte keyPair, short keyLength, byte keyClass) {
+ super(response, description, time);
this.keyPair = keyPair;
this.keyLength = keyLength;
this.keyClass = keyClass;
@@ -186,18 +178,6 @@ public abstract class Response {
if ((keyPair & ECTesterApplet.KEYPAIR_REMOTE) != 0) pairs++;
parse(pairs, 0);
}
-
- @Override
- public String getDescription() {
- String field = keyClass == KeyPair.ALG_EC_FP ? "ALG_EC_FP" : "ALG_EC_F2M";
- String key;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- key = "both keypairs";
- } else {
- key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Allocated %s %db %s", key, keyLength, field);
- }
}
/**
@@ -206,8 +186,8 @@ public abstract class Response {
public static class Clear extends Response {
private byte keyPair;
- public Clear(ResponseAPDU response, long time, byte keyPair) {
- super(response, time);
+ public Clear(ResponseAPDU response, String description, long time, byte keyPair) {
+ super(response, description, time);
this.keyPair = keyPair;
int pairs = 0;
@@ -215,17 +195,6 @@ public abstract class Response {
if ((keyPair & ECTesterApplet.KEYPAIR_REMOTE) != 0) pairs++;
parse(pairs, 0);
}
-
- @Override
- public String getDescription() {
- String key;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- key = "both keypairs";
- } else {
- key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Cleared %s", key);
- }
}
/**
@@ -236,8 +205,8 @@ public abstract class Response {
private byte curve;
private short parameters;
- public Set(ResponseAPDU response, long time, byte keyPair, byte curve, short parameters) {
- super(response, time);
+ public Set(ResponseAPDU response, String description, long time, byte keyPair, byte curve, short parameters) {
+ super(response, description, time);
this.keyPair = keyPair;
this.curve = curve;
this.parameters = parameters;
@@ -248,41 +217,6 @@ public abstract class Response {
parse(pairs, 0);
}
-
- @Override
- public String getDescription() {
- String name;
- switch (curve) {
- case EC_Consts.CURVE_default:
- name = "default";
- break;
- case EC_Consts.CURVE_external:
- name = "external";
- break;
- default:
- name = "custom";
- break;
- }
- String what = "";
- if (parameters == EC_Consts.PARAMETERS_DOMAIN_F2M || parameters == EC_Consts.PARAMETERS_DOMAIN_FP) {
- what = "curve";
- } else if (parameters == EC_Consts.PARAMETER_W) {
- what = "pubkey";
- } else if (parameters == EC_Consts.PARAMETER_S) {
- what = "privkey";
- } else if (parameters == EC_Consts.PARAMETERS_KEYPAIR) {
- what = "keypair";
- }
-
- String pair;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- pair = "both keypairs";
- } else {
- pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Set %s %s parameters on %s", name, what, pair);
- }
-
}
/**
@@ -294,8 +228,8 @@ public abstract class Response {
private short params;
private short corruption;
- public Corrupt(ResponseAPDU response, long time, byte keyPair, byte key, short params, short corruption) {
- super(response, time);
+ public Corrupt(ResponseAPDU response, String description, long time, byte keyPair, byte key, short params, short corruption) {
+ super(response, description, time);
this.keyPair = keyPair;
this.key = key;
this.params = params;
@@ -307,19 +241,6 @@ public abstract class Response {
parse(pairs, 0);
}
-
- @Override
- public String getDescription() {
- String corrupt = CardUtil.getCorruption(corruption);
-
- String pair;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- pair = "both keypairs";
- } else {
- pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Corrupted params of %s, %s", pair, corrupt);
- }
}
/**
@@ -328,8 +249,8 @@ public abstract class Response {
public static class Generate extends Response {
private byte keyPair;
- public Generate(ResponseAPDU response, long time, byte keyPair) {
- super(response, time);
+ public Generate(ResponseAPDU response, String description, long time, byte keyPair) {
+ super(response, description, time);
this.keyPair = keyPair;
int generated = 0;
@@ -337,18 +258,6 @@ public abstract class Response {
if ((keyPair & ECTesterApplet.KEYPAIR_REMOTE) != 0) generated++;
parse(generated, 0);
}
-
- @Override
- public String getDescription() {
- String key;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- key = "both keypairs";
- } else {
- key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Generated %s", key);
- }
-
}
/**
@@ -359,8 +268,8 @@ public abstract class Response {
private byte key;
private short parameters;
- public Export(ResponseAPDU response, long time, byte keyPair, byte key, short parameters) {
- super(response, time);
+ public Export(ResponseAPDU response, String description, long time, byte keyPair, byte key, short parameters) {
+ super(response, description, time);
this.keyPair = keyPair;
this.key = key;
this.parameters = parameters;
@@ -440,23 +349,6 @@ public abstract class Response {
public byte[] getParameter(byte keyPair, short param) {
return getParam(getIndex(keyPair, param));
}
-
- @Override
- public String getDescription() {
- String source;
- if (key == EC_Consts.KEY_BOTH) {
- source = "both keys";
- } else {
- source = ((key == EC_Consts.KEY_PUBLIC) ? "public" : "private") + " key";
- }
- String pair;
- if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
- pair = "both keypairs";
- } else {
- pair = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
- }
- return String.format("Exported params from %s of %s", source, pair);
- }
}
/**
@@ -469,8 +361,8 @@ public abstract class Response {
private short corruption;
private byte type;
- public ECDH(ResponseAPDU response, long time, byte pubkey, byte privkey, byte export, short corruption, byte type) {
- super(response, time);
+ public ECDH(ResponseAPDU response, String description, long time, byte pubkey, byte privkey, byte export, short corruption, byte type) {
+ super(response, description, time);
this.pubkey = pubkey;
this.privkey = privkey;
this.export = export;
@@ -491,22 +383,6 @@ public abstract class Response {
public int secretLength() {
return getParamLength(0);
}
-
- @Override
- public String getDescription() {
- String algo = CardUtil.getKATypeString(type);
-
- String pub = pubkey == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
- String priv = privkey == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
-
- String validity;
- if (corruption == EC_Consts.CORRUPTION_NONE) {
- validity = "unchanged";
- } else {
- validity = CardUtil.getCorruption(corruption);
- }
- return String.format("%s of %s pubkey and %s privkey(%s point)", algo, pub, priv, validity);
- }
}
/**
@@ -518,8 +394,8 @@ public abstract class Response {
private byte export;
private byte[] raw;
- public ECDSA(ResponseAPDU response, long time, byte keyPair, byte sigType, byte export, byte[] raw) {
- super(response, time);
+ public ECDSA(ResponseAPDU response, String description, long time, byte keyPair, byte sigType, byte export, byte[] raw) {
+ super(response, description, time);
this.keyPair = keyPair;
this.sigType = sigType;
this.export = export;
@@ -535,14 +411,6 @@ public abstract class Response {
public byte[] getSignature() {
return getParam(0);
}
-
- @Override
- public String getDescription() {
- String algo = CardUtil.getSigTypeString(sigType);
- String key = keyPair == ECTesterApplet.KEYPAIR_LOCAL ? "local" : "remote";
- String data = raw == null ? "random" : "provided";
- return String.format("%s with %s keypair(%s data)", algo, key, data);
- }
}
/**
@@ -550,16 +418,10 @@ public abstract class Response {
*/
public static class Cleanup extends Response {
- public Cleanup(ResponseAPDU response, long time) {
- super(response, time);
+ public Cleanup(ResponseAPDU response, String description, long time) {
+ super(response, description, time);
parse(1, 0);
}
-
- @Override
- public String getDescription() {
- return "Requested JCSystem object deletion";
- }
-
}
}
diff --git a/src/cz/crcs/ectester/reader/test/CardWrongCurvesSuite.java b/src/cz/crcs/ectester/reader/test/CardWrongCurvesSuite.java
index 1c3ad94..4706bdd 100644
--- a/src/cz/crcs/ectester/reader/test/CardWrongCurvesSuite.java
+++ b/src/cz/crcs/ectester/reader/test/CardWrongCurvesSuite.java
@@ -8,7 +8,6 @@ import cz.crcs.ectester.common.output.TestWriter;
import cz.crcs.ectester.common.test.CompoundTest;
import cz.crcs.ectester.common.test.Result;
import cz.crcs.ectester.common.test.Test;
-import cz.crcs.ectester.common.test.TestException;
import cz.crcs.ectester.common.util.ByteUtil;
import cz.crcs.ectester.common.util.CardUtil;
import cz.crcs.ectester.common.util.ECUtil;
@@ -44,7 +43,7 @@ public class CardWrongCurvesSuite extends CardTestSuite {
List<Test> tests = new LinkedList<>();
Test key = runTest(CommandTest.expect(new Command.Allocate(this.card, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), Result.ExpectedValue.SUCCESS));
if (!key.ok()) {
- doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, "No support for " + curve.getBits() + "b " + CardUtil.getKeyTypeString(curve.getField()), key));
+ doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, "No support for " + curve.getBits() + "b " + CardUtil.getKeyTypeString(curve.getField()), key));
continue;
}
tests.add(key);
@@ -143,7 +142,7 @@ public class CardWrongCurvesSuite extends CardTestSuite {
*/
}
- private Test ecdhTest(Command setupCmd, String prepareDesc, String fullDesc) throws TestException {
+ private Test ecdhTest(Command setupCmd, String prepareDesc, String fullDesc) {
Test setup = runTest(CommandTest.expect(setupCmd, Result.ExpectedValue.FAILURE));
Test generate = runTest(CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_BOTH), Result.ExpectedValue.FAILURE));
Test preparePhase = runTest(CompoundTest.any(Result.ExpectedValue.SUCCESS, prepareDesc, setup, generate));
diff --git a/src/cz/crcs/ectester/reader/test/CommandTest.java b/src/cz/crcs/ectester/reader/test/CommandTest.java
index a08d820..d57dc17 100644
--- a/src/cz/crcs/ectester/reader/test/CommandTest.java
+++ b/src/cz/crcs/ectester/reader/test/CommandTest.java
@@ -3,13 +3,14 @@ package cz.crcs.ectester.reader.test;
import cz.crcs.ectester.common.test.Result;
import cz.crcs.ectester.common.test.SimpleTest;
import cz.crcs.ectester.common.test.TestCallback;
-import cz.crcs.ectester.common.test.TestException;
import cz.crcs.ectester.reader.command.Command;
import cz.crcs.ectester.reader.response.Response;
/**
* A simple test that runs one Command to get and evaluate one Response
* to get a Result and compare it with the expected one.
+ *
+ * @author Jan Jancar johny@neuromancer.sk
*/
public class CommandTest extends SimpleTest<CommandTestable> {
private CommandTest(CommandTestable command, TestCallback<CommandTestable> callback) {
@@ -28,8 +29,7 @@ public class CommandTest extends SimpleTest<CommandTestable> {
return new CommandTest(command, new TestCallback<CommandTestable>() {
@Override
public Result apply(CommandTestable commandTestable) {
- Response resp = commandTestable.getResponse();
- Result.Value resultValue = Result.Value.fromExpected(expected, resp.successful(), resp.error());
+ Result.Value resultValue = Result.Value.fromExpected(expected, commandTestable.ok(), commandTestable.error());
return new Result(resultValue, resultValue.ok() ? ok : nok);
}
});
@@ -56,21 +56,11 @@ public class CommandTest extends SimpleTest<CommandTestable> {
}
@Override
- public void run() throws TestException {
- if (hasRun)
- return;
-
- testable.run();
- result = callback.apply(testable);
- hasRun = true;
- }
-
- @Override
public String getDescription() {
if (hasRun) {
return testable.getResponse().getDescription();
} else {
- return testable.getCommand().toString();
+ return testable.getCommand().getDescription();
}
}
}
diff --git a/src/cz/crcs/ectester/reader/test/CommandTestable.java b/src/cz/crcs/ectester/reader/test/CommandTestable.java
index 3bb55bf..f670534 100644
--- a/src/cz/crcs/ectester/reader/test/CommandTestable.java
+++ b/src/cz/crcs/ectester/reader/test/CommandTestable.java
@@ -27,7 +27,7 @@ public class CommandTestable extends BaseTestable {
}
@Override
- public void run() throws TestException {
+ public void run() {
try {
response = command.send();
} catch (CardException e) {
diff --git a/src/cz/crcs/ectester/reader/test/PerformanceTest.java b/src/cz/crcs/ectester/reader/test/PerformanceTest.java
index 4a27bad..2e5f376 100644
--- a/src/cz/crcs/ectester/reader/test/PerformanceTest.java
+++ b/src/cz/crcs/ectester/reader/test/PerformanceTest.java
@@ -38,10 +38,7 @@ public class PerformanceTest extends SimpleTest<CommandTestable> {
}
@Override
- public void run() throws TestException {
- if (hasRun)
- return;
-
+ protected void runSelf() {
times = new long[count];
for (int i = 0; i < count; ++i) {
testable.run();
@@ -73,7 +70,6 @@ public class PerformanceTest extends SimpleTest<CommandTestable> {
mode = current_value;
}
}
- hasRun = true;
result = callback.apply(testable);
}
diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
index 5f335b9..498fce1 100644
--- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
+++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
@@ -120,7 +120,7 @@ public class ECTesterStandalone {
} catch (NoSuchAlgorithmException nsaex) {
System.err.println("Algorithm not supported by the selected library: " + nsaex.getMessage());
nsaex.printStackTrace();
- } catch (InvalidKeyException | SignatureException | TestException e) {
+ } catch (InvalidKeyException | SignatureException e) {
e.printStackTrace();
}
}
diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
index 5f697c4..7672c4b 100644
--- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
+++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
@@ -3,7 +3,6 @@ package cz.crcs.ectester.standalone.test;
import cz.crcs.ectester.common.test.Result;
import cz.crcs.ectester.common.test.SimpleTest;
import cz.crcs.ectester.common.test.TestCallback;
-import cz.crcs.ectester.common.test.TestException;
import java.util.Arrays;
@@ -45,13 +44,4 @@ public class KeyAgreementTest extends SimpleTest<KeyAgreementTestable> {
public String getDescription() {
return "KeyAgreement " + testable.getKa().getAlgorithm();
}
-
- @Override
- public void run() throws TestException {
- if (hasRun)
- return;
- testable.run();
- result = callback.apply(testable);
- hasRun = true;
- }
}
diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java
index de9356b..8a635e0 100644
--- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java
+++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java
@@ -70,7 +70,7 @@ public class KeyAgreementTestable extends BaseTestable {
}
@Override
- public void run() throws TestException {
+ public void run() {
if (kgtPrivate != null) {
privateKey = (ECPrivateKey) kgtPrivate.getKeyPair().getPrivate();
}
diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java
index 93273ca..a27c088 100644
--- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java
+++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java
@@ -30,13 +30,4 @@ public class KeyGeneratorTest extends SimpleTest<KeyGeneratorTestable> {
public String getDescription() {
return "KeyPairGenerator " + testable.getKpg().getAlgorithm();
}
-
- @Override
- public void run() throws TestException {
- if (hasRun)
- return;
- testable.run();
- result = callback.apply(testable);
- hasRun = true;
- }
}
diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java
index c2fec5a..353e87a 100644
--- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java
+++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java
@@ -40,7 +40,7 @@ public class KeyGeneratorTestable extends BaseTestable {
}
@Override
- public void run() throws TestException {
+ public void run() {
try {
if (spec != null) {
kpg.initialize(spec);
diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/SignatureTest.java
index 9746b91..74c06f0 100644
--- a/src/cz/crcs/ectester/standalone/test/SignatureTest.java
+++ b/src/cz/crcs/ectester/standalone/test/SignatureTest.java
@@ -3,7 +3,6 @@ package cz.crcs.ectester.standalone.test;
import cz.crcs.ectester.common.test.Result;
import cz.crcs.ectester.common.test.SimpleTest;
import cz.crcs.ectester.common.test.TestCallback;
-import cz.crcs.ectester.common.test.TestException;
/**
* @author Jan Jancar johny@neuromancer.sk
@@ -30,13 +29,4 @@ public class SignatureTest extends SimpleTest<SignatureTestable> {
public String getDescription() {
return "Signature " + testable.getSig().getAlgorithm();
}
-
- @Override
- public void run() throws TestException {
- if (hasRun)
- return;
- testable.run();
- result = callback.apply(testable);
- hasRun = true;
- }
}
diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
index 7b26af7..c77e9c5 100644
--- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
+++ b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
@@ -56,7 +56,7 @@ public class SignatureTestable extends BaseTestable {
}
@Override
- public void run() throws TestException {
+ public void run() {
if (kgt != null) {
signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate();
verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic();