From df3a0cbc285d9a34760034e186d7c7535375df5a Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 5 Feb 2018 17:26:24 +0100 Subject: Show library name in test suite output in standalone testing. --- src/cz/crcs/ectester/standalone/test/SignatureTestable.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/cz/crcs/ectester/standalone/test/SignatureTestable.java') diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java index e434337..7b26af7 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java +++ b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java @@ -10,6 +10,9 @@ import java.security.SignatureException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; +/** + * @author Jan Jancar johny@neuromancer.sk + */ public class SignatureTestable extends BaseTestable { private Signature sig; private ECPrivateKey signKey; -- cgit v1.2.3-70-g09d2 From 22e4cfaf40a259be007bddc7b5cd765390de1c11 Mon Sep 17 00:00:00 2001 From: J08nY Date: Sat, 10 Feb 2018 19:59:41 +0100 Subject: Handle exceptions in Tests and TestSuites grafeully. --- .../ectester/common/output/BaseTextTestWriter.java | 27 ++- .../ectester/common/output/BaseXMLTestWriter.java | 57 ++++- .../ectester/common/output/BaseYAMLTestWriter.java | 21 +- src/cz/crcs/ectester/common/output/TestWriter.java | 17 ++ src/cz/crcs/ectester/common/test/CompoundTest.java | 102 +++++++-- src/cz/crcs/ectester/common/test/Result.java | 6 +- src/cz/crcs/ectester/common/test/SimpleTest.java | 6 + src/cz/crcs/ectester/common/test/Test.java | 44 ++-- .../crcs/ectester/common/test/TestException.java | 7 +- src/cz/crcs/ectester/common/test/TestSuite.java | 22 +- .../ectester/common/test/TestSuiteException.java | 13 ++ src/cz/crcs/ectester/common/test/Testable.java | 2 +- src/cz/crcs/ectester/common/util/CardUtil.java | 14 ++ src/cz/crcs/ectester/reader/ECTesterReader.java | 5 +- src/cz/crcs/ectester/reader/command/Command.java | 241 ++++++++++++++------- .../ectester/reader/output/TextTestWriter.java | 6 +- .../crcs/ectester/reader/output/XMLTestWriter.java | 11 + .../ectester/reader/output/YAMLTestWriter.java | 7 + src/cz/crcs/ectester/reader/response/Response.java | 194 +++-------------- .../ectester/reader/test/CardWrongCurvesSuite.java | 5 +- src/cz/crcs/ectester/reader/test/CommandTest.java | 18 +- .../crcs/ectester/reader/test/CommandTestable.java | 2 +- .../crcs/ectester/reader/test/PerformanceTest.java | 6 +- .../ectester/standalone/ECTesterStandalone.java | 2 +- .../ectester/standalone/test/KeyAgreementTest.java | 10 - .../standalone/test/KeyAgreementTestable.java | 2 +- .../ectester/standalone/test/KeyGeneratorTest.java | 9 - .../standalone/test/KeyGeneratorTestable.java | 2 +- .../ectester/standalone/test/SignatureTest.java | 10 - .../standalone/test/SignatureTestable.java | 2 +- 30 files changed, 491 insertions(+), 379 deletions(-) create mode 100644 src/cz/crcs/ectester/common/test/TestSuiteException.java (limited to 'src/cz/crcs/ectester/standalone/test/SignatureTestable.java') 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 deviceObject(TestSuite suite); + private Map resultObject(Result result) { + Map resultObject = new HashMap<>(); + resultObject.put("ok", result.ok()); + resultObject.put("value", result.getValue().name()); + resultObject.put("cause", result.getCause()); + return resultObject; + } + private Map testObject(Test t) { Map testObj; if (t instanceof CompoundTest) { @@ -48,7 +56,7 @@ public abstract class BaseYAMLTestWriter implements TestWriter { testObj = new HashMap<>(); testObj.put("type", "compound"); List> 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 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; } @@ -74,6 +78,11 @@ public abstract class BaseYAMLTestWriter implements TestWriter { tests.add(testObject(t)); } + @Override + public void outputError(Test t, Throwable cause) { + tests.add(testObject(t)); + } + @Override public void end() { DumperOptions options = new DumperOptions(); 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 callback; + private Function resultCallback; + private Consumer runCallback; private Test[] tests; private String description = ""; - private CompoundTest(Function callback, Test... tests) { - this.callback = callback; + private final static Consumer RUN_ALL = tests -> { + for (Test t : tests) { + t.run(); + } + }; + + private CompoundTest(Function resultCallback, Consumer runCallback, Test... tests) { + this.resultCallback = resultCallback; + this.runCallback = runCallback; this.tests = Arrays.stream(tests).filter(Objects::nonNull).toArray(Test[]::new); } - private CompoundTest(Function callback, String descripiton, Test... tests) { - this(callback, tests); + private CompoundTest(Function callback, Consumer runCallback, String descripiton, Test... tests) { + this(callback, runCallback, tests); this.description = descripiton; } public static CompoundTest function(Function callback, Test... tests) { - return new CompoundTest(callback, tests); + return new CompoundTest(callback, RUN_ALL, tests); } public static CompoundTest function(Function 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 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 commandObject(Command c) { Map 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 responseObject(Response r) { Map 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 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 { private CommandTest(CommandTestable command, TestCallback callback) { @@ -28,8 +29,7 @@ public class CommandTest extends SimpleTest { return new CommandTest(command, new TestCallback() { @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); } }); @@ -55,22 +55,12 @@ public class CommandTest extends SimpleTest { return testable.getResponse(); } - @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 { } @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 { 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 { 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 { 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 { 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(); -- cgit v1.2.3-70-g09d2 From ff6be88e469608a67945a274ec2180aee3f3ccd2 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 28 May 2018 18:37:01 +0200 Subject: Handle exceptions in standalone testables better. --- src/cz/crcs/ectester/common/test/Result.java | 20 +++- .../crcs/ectester/reader/test/CommandTestable.java | 1 - .../ectester/standalone/test/KeyAgreementTest.java | 3 +- .../ectester/standalone/test/KeyGeneratorTest.java | 4 +- .../standalone/test/KeyGeneratorTestable.java | 26 ++++-- .../ectester/standalone/test/SignatureTest.java | 3 +- .../standalone/test/SignatureTestable.java | 101 ++++++++++++--------- 7 files changed, 93 insertions(+), 65 deletions(-) (limited to 'src/cz/crcs/ectester/standalone/test/SignatureTestable.java') diff --git a/src/cz/crcs/ectester/common/test/Result.java b/src/cz/crcs/ectester/common/test/Result.java index 5d15a60..a978021 100644 --- a/src/cz/crcs/ectester/common/test/Result.java +++ b/src/cz/crcs/ectester/common/test/Result.java @@ -49,18 +49,24 @@ public class Result { * A result value of a Test. */ public enum Value { - SUCCESS(true), - FAILURE(false), - UXSUCCESS(false), - XFAILURE(true), - ERROR(false); + SUCCESS(true, "Expected success."), + FAILURE(false, "Unexpected failure."), + UXSUCCESS(false, "Unexpected success."), + XFAILURE(true, "Expected failure."), + ERROR(false, "Error."); private boolean ok; + private String desc; Value(boolean ok) { this.ok = ok; } + Value(boolean ok, String desc) { + this(ok); + this.desc = desc; + } + public static Value fromExpected(ExpectedValue expected, boolean successful) { switch (expected) { case SUCCESS: @@ -83,6 +89,10 @@ public class Result { public boolean ok() { return ok; } + + public String description() { + return desc; + } } /** diff --git a/src/cz/crcs/ectester/reader/test/CommandTestable.java b/src/cz/crcs/ectester/reader/test/CommandTestable.java index e3dbd05..f670534 100644 --- a/src/cz/crcs/ectester/reader/test/CommandTestable.java +++ b/src/cz/crcs/ectester/reader/test/CommandTestable.java @@ -28,7 +28,6 @@ public class CommandTestable extends BaseTestable { @Override public void run() { - try { response = command.send(); } catch (CardException e) { diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java index 7672c4b..33c7385 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java +++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java @@ -31,7 +31,8 @@ public class KeyAgreementTest extends SimpleTest { return new KeyAgreementTest(ka, new TestCallback() { @Override public Result apply(KeyAgreementTestable keyAgreementTestable) { - return new Result(Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error())); + Result.Value value = Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error()); + return new Result(value, value.description()); } }); } diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java index a27c088..02b81a4 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java +++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.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 @@ -17,7 +16,8 @@ public class KeyGeneratorTest extends SimpleTest { return new KeyGeneratorTest(kg, new TestCallback() { @Override public Result apply(KeyGeneratorTestable keyGenerationTestable) { - return new Result(Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error())); + Result.Value value = Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error()); + return new Result(value, value.description()); } }); } diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java index 353e87a..774c3ec 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java +++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java @@ -1,7 +1,6 @@ package cz.crcs.ectester.standalone.test; import cz.crcs.ectester.common.test.BaseTestable; -import cz.crcs.ectester.common.test.TestException; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; @@ -42,18 +41,25 @@ public class KeyGeneratorTestable extends BaseTestable { @Override public void run() { try { - if (spec != null) { - kpg.initialize(spec); - } else if (keysize != 0) { - kpg.initialize(keysize); + try { + if (spec != null) { + kpg.initialize(spec); + } else if (keysize != 0) { + kpg.initialize(keysize); + } + } catch (InvalidAlgorithmParameterException e) { + hasRun = true; + ok = false; + return; } - } catch (InvalidAlgorithmParameterException e) { - hasRun = true; + kp = kpg.genKeyPair(); + ok = true; + + } catch (Exception ex) { ok = false; - return; + error = true; + errorCause = ex; } - kp = kpg.genKeyPair(); hasRun = true; - ok = true; } } diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/SignatureTest.java index 74c06f0..481d289 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTest.java +++ b/src/cz/crcs/ectester/standalone/test/SignatureTest.java @@ -16,7 +16,8 @@ public class SignatureTest extends SimpleTest { return new SignatureTest(kg, new TestCallback() { @Override public Result apply(SignatureTestable signatureTestable) { - return new Result(Result.Value.fromExpected(expected, signatureTestable.ok(), signatureTestable.error())); + Result.Value value = Result.Value.fromExpected(expected, signatureTestable.ok(), signatureTestable.error()); + return new Result(value, value.description()); } }); } diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java index c77e9c5..6bc9b30 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java +++ b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java @@ -57,54 +57,65 @@ public class SignatureTestable extends BaseTestable { @Override public void run() { - if (kgt != null) { - signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate(); - verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic(); - } - - try { - sig.initSign(signKey); - } catch (InvalidKeyException e) { - throw new TestException(e); - } - - try { - sig.update(data); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - - try { - signature = sig.sign(); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - - try { - sig.initVerify(verifyKey); - } catch (InvalidKeyException e) { - throw new TestException(e); - } - - try { - sig.update(data); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - try { - verified = sig.verify(signature); - } catch (SignatureException e) { + if (kgt != null) { + signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate(); + verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic(); + } + + try { + sig.initSign(signKey); + } catch (InvalidKeyException e) { + ok = false; + hasRun = true; + return; + } + + try { + sig.update(data); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + try { + signature = sig.sign(); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + try { + sig.initVerify(verifyKey); + } catch (InvalidKeyException e) { + ok = false; + hasRun = true; + return; + } + + try { + sig.update(data); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + try { + verified = sig.verify(signature); + } catch (SignatureException e) { + ok = false; + hasRun = true; + } + + ok = true; + } catch (Exception ex) { ok = false; - hasRun = true; + error = true; + errorCause = ex; } - ok = true; hasRun = true; } } -- cgit v1.2.3-70-g09d2 From a4e52b21b1dad5f96df409c44e5b4d611bba01b9 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 28 May 2018 20:06:18 +0200 Subject: Implement tracking of stage of execution of standalone testables. - Output this stage in all the formats. --- .gitignore | 1 + src/cz/crcs/ectester/common/test/BaseTestable.java | 1 + .../ectester/standalone/ECTesterStandalone.java | 4 +- .../ectester/standalone/output/TextTestWriter.java | 10 +- .../ectester/standalone/output/XMLTestWriter.java | 36 ++++-- .../ectester/standalone/output/YAMLTestWriter.java | 30 +++-- .../ectester/standalone/test/KeyAgreementTest.java | 48 -------- .../standalone/test/KeyAgreementTestable.java | 121 ------------------ .../ectester/standalone/test/KeyGeneratorTest.java | 33 ----- .../standalone/test/KeyGeneratorTestable.java | 65 ---------- .../ectester/standalone/test/SignatureTest.java | 33 ----- .../standalone/test/SignatureTestable.java | 121 ------------------ .../standalone/test/StandaloneDefaultSuite.java | 77 ------------ .../standalone/test/StandaloneTestSuite.java | 25 ---- .../standalone/test/base/KeyAgreementTest.java | 48 ++++++++ .../standalone/test/base/KeyAgreementTestable.java | 129 ++++++++++++++++++++ .../standalone/test/base/KeyGeneratorTest.java | 33 +++++ .../standalone/test/base/KeyGeneratorTestable.java | 71 +++++++++++ .../standalone/test/base/SignatureTest.java | 33 +++++ .../standalone/test/base/SignatureTestable.java | 135 +++++++++++++++++++++ .../standalone/test/base/StandaloneTestable.java | 14 +++ .../test/suites/StandaloneDefaultSuite.java | 101 +++++++++++++++ .../test/suites/StandaloneTestSuite.java | 25 ++++ 23 files changed, 640 insertions(+), 554 deletions(-) delete mode 100644 src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java delete mode 100644 src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java delete mode 100644 src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java delete mode 100644 src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java delete mode 100644 src/cz/crcs/ectester/standalone/test/SignatureTest.java delete mode 100644 src/cz/crcs/ectester/standalone/test/SignatureTestable.java delete mode 100644 src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java delete mode 100644 src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/KeyAgreementTest.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/SignatureTest.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java create mode 100644 src/cz/crcs/ectester/standalone/test/base/StandaloneTestable.java create mode 100644 src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java create mode 100644 src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java (limited to 'src/cz/crcs/ectester/standalone/test/SignatureTestable.java') diff --git a/.gitignore b/.gitignore index aecbbec..d05e75d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ /dist/*.invalid /dist/*.twist /dist/*.degenerate +/dist/*.edge-cases /dist/*.xml # Built binaries in /src. diff --git a/src/cz/crcs/ectester/common/test/BaseTestable.java b/src/cz/crcs/ectester/common/test/BaseTestable.java index 979b2a4..4863abc 100644 --- a/src/cz/crcs/ectester/common/test/BaseTestable.java +++ b/src/cz/crcs/ectester/common/test/BaseTestable.java @@ -34,5 +34,6 @@ public abstract class BaseTestable implements Testable { hasRun = false; ok = false; error = false; + errorCause = null; } } diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java index 56dde42..392d604 100644 --- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java +++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java @@ -36,8 +36,8 @@ import cz.crcs.ectester.standalone.libs.*; import cz.crcs.ectester.standalone.output.TextTestWriter; import cz.crcs.ectester.standalone.output.XMLTestWriter; import cz.crcs.ectester.standalone.output.YAMLTestWriter; -import cz.crcs.ectester.standalone.test.StandaloneDefaultSuite; -import cz.crcs.ectester.standalone.test.StandaloneTestSuite; +import cz.crcs.ectester.standalone.test.suites.StandaloneDefaultSuite; +import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; diff --git a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java index 26e1b1a..691bea8 100644 --- a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java @@ -4,8 +4,10 @@ import cz.crcs.ectester.common.output.BaseTextTestWriter; import cz.crcs.ectester.common.test.TestSuite; import cz.crcs.ectester.common.test.Testable; import cz.crcs.ectester.standalone.ECTesterStandalone; -import cz.crcs.ectester.standalone.test.StandaloneTestSuite; +import cz.crcs.ectester.standalone.test.base.*; +import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite; +import javax.crypto.KeyAgreement; import java.io.PrintStream; /** @@ -18,7 +20,9 @@ public class TextTestWriter extends BaseTextTestWriter { @Override protected String testableString(Testable t) { - //TODO + if (t instanceof StandaloneTestable) { + return ((StandaloneTestable)t).getStage().name(); + } return ""; } @@ -28,7 +32,7 @@ public class TextTestWriter extends BaseTextTestWriter { StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; StringBuilder sb = new StringBuilder(); sb.append("═══ ECTester version: " + ECTesterStandalone.VERSION).append(System.lineSeparator()); - sb.append("═══ " + standaloneSuite.getLibrary().name()).append(System.lineSeparator()); + sb.append("═══ ").append(standaloneSuite.getLibrary().name()).append(System.lineSeparator()); return sb.toString(); } return ""; diff --git a/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java index 2a35ce3..9332759 100644 --- a/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java @@ -5,10 +5,11 @@ 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.standalone.ECTesterStandalone; -import cz.crcs.ectester.standalone.test.KeyAgreementTestable; -import cz.crcs.ectester.standalone.test.KeyGeneratorTestable; -import cz.crcs.ectester.standalone.test.SignatureTestable; -import cz.crcs.ectester.standalone.test.StandaloneTestSuite; +import cz.crcs.ectester.standalone.test.base.KeyAgreementTestable; +import cz.crcs.ectester.standalone.test.base.KeyGeneratorTestable; +import cz.crcs.ectester.standalone.test.base.SignatureTestable; +import cz.crcs.ectester.standalone.test.base.StandaloneTestable; +import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite; import org.w3c.dom.Element; import javax.xml.parsers.ParserConfigurationException; @@ -97,18 +98,27 @@ public class XMLTestWriter extends BaseXMLTestWriter { return sigElem; } + private Element stageElement(StandaloneTestable t) { + Element result = doc.createElement("stage"); + result.setTextContent(t.getStage().name()); + return result; + } + @Override protected Element testableElement(Testable t) { Element result = doc.createElement("test"); - if (t instanceof KeyGeneratorTestable) { - result.setAttribute("type", "key-pair-generator"); - result.appendChild(kgtElement((KeyGeneratorTestable) t)); - } else if (t instanceof KeyAgreementTestable) { - result.setAttribute("type", "key-agreement"); - result.appendChild(kaElement((KeyAgreementTestable) t)); - } else if (t instanceof SignatureTestable) { - result.setAttribute("type", "signature"); - result.appendChild(sigElement((SignatureTestable) t)); + if (t instanceof StandaloneTestable) { + if (t instanceof KeyGeneratorTestable) { + result.setAttribute("type", "key-pair-generator"); + result.appendChild(kgtElement((KeyGeneratorTestable) t)); + } else if (t instanceof KeyAgreementTestable) { + result.setAttribute("type", "key-agreement"); + result.appendChild(kaElement((KeyAgreementTestable) t)); + } else if (t instanceof SignatureTestable) { + result.setAttribute("type", "signature"); + result.appendChild(sigElement((SignatureTestable) t)); + } + result.appendChild(stageElement((StandaloneTestable) t)); } return result; } diff --git a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java index c452133..0926b98 100644 --- a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java @@ -5,10 +5,11 @@ 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.standalone.ECTesterStandalone; -import cz.crcs.ectester.standalone.test.KeyAgreementTestable; -import cz.crcs.ectester.standalone.test.KeyGeneratorTestable; -import cz.crcs.ectester.standalone.test.SignatureTestable; -import cz.crcs.ectester.standalone.test.StandaloneTestSuite; +import cz.crcs.ectester.standalone.test.base.KeyAgreementTestable; +import cz.crcs.ectester.standalone.test.base.KeyGeneratorTestable; +import cz.crcs.ectester.standalone.test.base.SignatureTestable; +import cz.crcs.ectester.standalone.test.base.StandaloneTestable; +import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite; import java.io.PrintStream; import java.security.Key; @@ -79,15 +80,18 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { @Override protected Map testableObject(Testable t) { Map result = new HashMap<>(); - if (t instanceof KeyGeneratorTestable) { - result.put("type", "key-pair-generator"); - result.put("key-pair-generator", kgtObject((KeyGeneratorTestable) t)); - } else if (t instanceof KeyAgreementTestable) { - result.put("type", "key-agreement"); - result.put("key-agreement", kaObject((KeyAgreementTestable) t)); - } else if (t instanceof SignatureTestable) { - result.put("type", "signature"); - result.put("signature", sigObject((SignatureTestable) t)); + if (t instanceof StandaloneTestable) { + if (t instanceof KeyGeneratorTestable) { + result.put("type", "key-pair-generator"); + result.put("key-pair-generator", kgtObject((KeyGeneratorTestable) t)); + } else if (t instanceof KeyAgreementTestable) { + result.put("type", "key-agreement"); + result.put("key-agreement", kaObject((KeyAgreementTestable) t)); + } else if (t instanceof SignatureTestable) { + result.put("type", "signature"); + result.put("signature", sigObject((SignatureTestable) t)); + } + result.put("stage", ((StandaloneTestable)t).getStage().name()); } return result; } diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java deleted file mode 100644 index 33c7385..0000000 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java +++ /dev/null @@ -1,48 +0,0 @@ -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 java.util.Arrays; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class KeyAgreementTest extends SimpleTest { - private KeyAgreementTest(KeyAgreementTestable ka, TestCallback callback) { - super(ka, callback); - } - - public static KeyAgreementTest match(KeyAgreementTestable ka, byte[] expectedSecret) { - return new KeyAgreementTest(ka, new TestCallback() { - @Override - public Result apply(KeyAgreementTestable ka) { - if (Arrays.equals(ka.getSecret(), expectedSecret)) { - return new Result(Result.Value.SUCCESS, "The KeyAgreement result matched the expected derived secret."); - } else { - return new Result(Result.Value.FAILURE, "The KeyAgreement result did not match the expected derived secret."); - } - } - }); - } - - public static KeyAgreementTest expect(KeyAgreementTestable ka, Result.ExpectedValue expected) { - return new KeyAgreementTest(ka, new TestCallback() { - @Override - public Result apply(KeyAgreementTestable keyAgreementTestable) { - Result.Value value = Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error()); - return new Result(value, value.description()); - } - }); - } - - public static KeyAgreementTest function(KeyAgreementTestable ka, TestCallback callback) { - return new KeyAgreementTest(ka, callback); - } - - @Override - public String getDescription() { - return "KeyAgreement " + testable.getKa().getAlgorithm(); - } -} diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java deleted file mode 100644 index aac2127..0000000 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java +++ /dev/null @@ -1,121 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; - -import javax.crypto.KeyAgreement; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.ECParameterSpec; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class KeyAgreementTestable extends BaseTestable { - private KeyAgreement ka; - private ECPrivateKey privateKey; - private ECPublicKey publicKey; - private KeyGeneratorTestable kgtPrivate; - private KeyGeneratorTestable kgtPublic; - private AlgorithmParameterSpec spec; - private byte[] secret; - - public KeyAgreementTestable(KeyAgreement ka, ECPrivateKey privateKey, ECPublicKey publicKey) { - this.ka = ka; - this.privateKey = privateKey; - this.publicKey = publicKey; - } - - public KeyAgreementTestable(KeyAgreement ka, ECPrivateKey privateKey, ECPublicKey publicKey, ECParameterSpec spec) { - this(ka, privateKey, publicKey); - this.spec = spec; - } - - public KeyAgreementTestable(KeyAgreement ka, KeyGeneratorTestable kgt, ECPrivateKey privateKey, ECParameterSpec spec) { - this(ka, privateKey, null, spec); - this.kgtPublic = kgt; - } - - public KeyAgreementTestable(KeyAgreement ka, ECPublicKey publicKey, KeyGeneratorTestable kgt, ECParameterSpec spec) { - this(ka, null, publicKey, spec); - this.kgtPrivate = kgt; - } - - public KeyAgreementTestable(KeyAgreement ka, KeyGeneratorTestable privKgt, KeyGeneratorTestable pubKgt, ECParameterSpec spec) { - this(ka, (ECPrivateKey) null, null, spec); - this.kgtPrivate = privKgt; - this.kgtPublic = pubKgt; - } - - public KeyAgreement getKa() { - return ka; - } - - public ECPublicKey getPublicKey() { - return publicKey; - } - - public ECPrivateKey getPrivateKey() { - return privateKey; - } - - public byte[] getSecret() { - if (!hasRun) { - return null; - } - return secret; - } - - @Override - public void run() { - try { - if (kgtPrivate != null) { - privateKey = (ECPrivateKey) kgtPrivate.getKeyPair().getPrivate(); - } - - if (kgtPublic != null) { - publicKey = (ECPublicKey) kgtPublic.getKeyPair().getPublic(); - } - - try { - if (spec != null) { - ka.init(privateKey, spec); - } else { - ka.init(privateKey); - } - } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { - ok = false; - error = false; - hasRun = true; - return; - } - - try { - ka.doPhase(publicKey, true); - } catch (IllegalStateException | InvalidKeyException e) { - ok = false; - error = false; - hasRun = true; - return; - } - - try { - secret = ka.generateSecret(); - } catch (IllegalStateException | UnsupportedOperationException isex) { - ok = false; - error = false; - hasRun = true; - return; - } - - ok = true; - } catch (Exception ex) { - ok = false; - error = true; - errorCause = ex; - } - hasRun = true; - } -} diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java deleted file mode 100644 index 02b81a4..0000000 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class KeyGeneratorTest extends SimpleTest { - private KeyGeneratorTest(KeyGeneratorTestable kg, TestCallback callback) { - super(kg, callback); - } - - public static KeyGeneratorTest expect(KeyGeneratorTestable kg, Result.ExpectedValue expected) { - return new KeyGeneratorTest(kg, new TestCallback() { - @Override - public Result apply(KeyGeneratorTestable keyGenerationTestable) { - Result.Value value = Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error()); - return new Result(value, value.description()); - } - }); - } - - public static KeyGeneratorTest function(KeyGeneratorTestable ka, TestCallback callback) { - return new KeyGeneratorTest(ka, callback); - } - - @Override - public String getDescription() { - return "KeyPairGenerator " + testable.getKpg().getAlgorithm(); - } -} diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java deleted file mode 100644 index 774c3ec..0000000 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java +++ /dev/null @@ -1,65 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; - -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.spec.ECParameterSpec; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class KeyGeneratorTestable extends BaseTestable { - private KeyPair kp; - private KeyPairGenerator kpg; - private int keysize = 0; - private ECParameterSpec spec = null; - - public KeyGeneratorTestable(KeyPairGenerator kpg) { - this.kpg = kpg; - } - - public KeyGeneratorTestable(KeyPairGenerator kpg, int keysize) { - this.kpg = kpg; - this.keysize = keysize; - } - - public KeyGeneratorTestable(KeyPairGenerator kpg, ECParameterSpec spec) { - this.kpg = kpg; - this.spec = spec; - } - - public KeyPairGenerator getKpg() { - return kpg; - } - - public KeyPair getKeyPair() { - return kp; - } - - @Override - public void run() { - try { - try { - if (spec != null) { - kpg.initialize(spec); - } else if (keysize != 0) { - kpg.initialize(keysize); - } - } catch (InvalidAlgorithmParameterException e) { - hasRun = true; - ok = false; - return; - } - kp = kpg.genKeyPair(); - ok = true; - - } catch (Exception ex) { - ok = false; - error = true; - errorCause = ex; - } - hasRun = true; - } -} diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/SignatureTest.java deleted file mode 100644 index 481d289..0000000 --- a/src/cz/crcs/ectester/standalone/test/SignatureTest.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class SignatureTest extends SimpleTest { - private SignatureTest(SignatureTestable sig, TestCallback callback) { - super(sig, callback); - } - - public static SignatureTest expect(SignatureTestable kg, Result.ExpectedValue expected) { - return new SignatureTest(kg, new TestCallback() { - @Override - public Result apply(SignatureTestable signatureTestable) { - Result.Value value = Result.Value.fromExpected(expected, signatureTestable.ok(), signatureTestable.error()); - return new Result(value, value.description()); - } - }); - } - - public static SignatureTest function(SignatureTestable ka, TestCallback callback) { - return new SignatureTest(ka, callback); - } - - @Override - public String getDescription() { - return "Signature " + testable.getSig().getAlgorithm(); - } -} diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java deleted file mode 100644 index 6bc9b30..0000000 --- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java +++ /dev/null @@ -1,121 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; -import cz.crcs.ectester.common.test.TestException; - -import java.security.InvalidKeyException; -import java.security.SecureRandom; -import java.security.Signature; -import java.security.SignatureException; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class SignatureTestable extends BaseTestable { - private Signature sig; - private ECPrivateKey signKey; - private ECPublicKey verifyKey; - private KeyGeneratorTestable kgt; - private byte[] data; - private byte[] signature; - private boolean verified; - - public SignatureTestable(Signature sig, ECPrivateKey signKey, ECPublicKey verifyKey, byte[] data) { - this.sig = sig; - this.signKey = signKey; - this.verifyKey = verifyKey; - this.data = data; - if (data == null) { - SecureRandom random = new SecureRandom(); - this.data = new byte[32]; - random.nextBytes(this.data); - } - } - - public SignatureTestable(Signature sig, KeyGeneratorTestable kgt, byte[] data) { - this(sig, null, null, data); - this.kgt = kgt; - } - - public Signature getSig() { - return sig; - } - - public byte[] getData() { - return data; - } - - public byte[] getSignature() { - return signature; - } - - public boolean getVerified() { - return verified; - } - - @Override - public void run() { - try { - if (kgt != null) { - signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate(); - verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic(); - } - - try { - sig.initSign(signKey); - } catch (InvalidKeyException e) { - ok = false; - hasRun = true; - return; - } - - try { - sig.update(data); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - - try { - signature = sig.sign(); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - - try { - sig.initVerify(verifyKey); - } catch (InvalidKeyException e) { - ok = false; - hasRun = true; - return; - } - - try { - sig.update(data); - } catch (SignatureException e) { - ok = false; - hasRun = true; - return; - } - - try { - verified = sig.verify(signature); - } catch (SignatureException e) { - ok = false; - hasRun = true; - } - - ok = true; - } catch (Exception ex) { - ok = false; - error = true; - errorCause = ex; - } - hasRun = true; - } -} diff --git a/src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java b/src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java deleted file mode 100644 index 572449a..0000000 --- a/src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java +++ /dev/null @@ -1,77 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.cli.TreeCommandLine; -import cz.crcs.ectester.common.ec.EC_Curve; -import cz.crcs.ectester.common.output.TestWriter; -import cz.crcs.ectester.common.test.Result; -import cz.crcs.ectester.data.EC_Store; -import cz.crcs.ectester.standalone.ECTesterStandalone; -import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; -import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; -import cz.crcs.ectester.standalone.consts.SignatureIdent; -import cz.crcs.ectester.standalone.libs.ECLibrary; - -import javax.crypto.KeyAgreement; -import java.security.KeyPairGenerator; -import java.security.Signature; -import java.security.spec.ECParameterSpec; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class StandaloneDefaultSuite extends StandaloneTestSuite { - - public StandaloneDefaultSuite(TestWriter writer, ECTesterStandalone.Config cfg, TreeCommandLine cli) { - super(writer, cfg, cli, "default", "The default test suite run basic support of ECDH and ECDSA."); - } - - @Override - protected void runTests() throws Exception { - String kpgAlgo = cli.getOptionValue("test.kpg-type", "EC"); - String kaAlgo = cli.getOptionValue("test.ka-type"); - String sigAlgo = cli.getOptionValue("test.sig-type"); - - KeyPairGeneratorIdent kpgIdent = cfg.selected.getKPGs().stream() - .filter((ident) -> ident.contains(kpgAlgo)) - .findFirst().get(); - KeyPairGenerator kpg = kpgIdent.getInstance(cfg.selected.getProvider()); - - KeyGeneratorTestable kgtOne; - KeyGeneratorTestable kgtOther; - ECParameterSpec spec = null; - if (cli.hasOption("test.bits")) { - int bits = Integer.parseInt(cli.getOptionValue("test.bits")); - kgtOne = new KeyGeneratorTestable(kpg, bits); - kgtOther = new KeyGeneratorTestable(kpg, bits); - } else if (cli.hasOption("test.named-curve")) { - String curveName = cli.getOptionValue("test.named-curve"); - EC_Curve curve = EC_Store.getInstance().getObject(EC_Curve.class, curveName); - if (curve == null) { - System.err.println("Curve not found: " + curveName); - return; - } - spec = curve.toSpec(); - kgtOne = new KeyGeneratorTestable(kpg, spec); - kgtOther = new KeyGeneratorTestable(kpg, spec); - } else { - kgtOne = new KeyGeneratorTestable(kpg); - kgtOther = new KeyGeneratorTestable(kpg); - } - - doTest(KeyGeneratorTest.expect(kgtOne, Result.ExpectedValue.SUCCESS)); - doTest(KeyGeneratorTest.expect(kgtOther, Result.ExpectedValue.SUCCESS)); - - for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) { - if (kaAlgo == null || kaIdent.contains(kaAlgo)) { - KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider()); - doTest(KeyAgreementTest.expect(new KeyAgreementTestable(ka, kgtOne, kgtOther, spec), Result.ExpectedValue.SUCCESS)); - } - } - for (SignatureIdent sigIdent : cfg.selected.getSigs()) { - if (sigAlgo == null || sigIdent.contains(sigAlgo)) { - Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); - doTest(SignatureTest.expect(new SignatureTestable(sig, kgtOne, null), Result.ExpectedValue.SUCCESS)); - } - } - } -} diff --git a/src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java b/src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java deleted file mode 100644 index 2949d52..0000000 --- a/src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java +++ /dev/null @@ -1,25 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.cli.TreeCommandLine; -import cz.crcs.ectester.common.output.TestWriter; -import cz.crcs.ectester.common.test.TestSuite; -import cz.crcs.ectester.standalone.ECTesterStandalone; -import cz.crcs.ectester.standalone.libs.ProviderECLibrary; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public abstract class StandaloneTestSuite extends TestSuite { - TreeCommandLine cli; - ECTesterStandalone.Config cfg; - - public StandaloneTestSuite(TestWriter writer, ECTesterStandalone.Config cfg, TreeCommandLine cli, String name, String description) { - super(writer, name, description); - this.cfg = cfg; - this.cli = cli; - } - - public ProviderECLibrary getLibrary() { - return cfg.selected; - } -} diff --git a/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTest.java new file mode 100644 index 0000000..8297d76 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTest.java @@ -0,0 +1,48 @@ +package cz.crcs.ectester.standalone.test.base; + +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.common.test.SimpleTest; +import cz.crcs.ectester.common.test.TestCallback; + +import java.util.Arrays; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyAgreementTest extends SimpleTest { + private KeyAgreementTest(KeyAgreementTestable ka, TestCallback callback) { + super(ka, callback); + } + + public static KeyAgreementTest match(KeyAgreementTestable ka, byte[] expectedSecret) { + return new KeyAgreementTest(ka, new TestCallback() { + @Override + public Result apply(KeyAgreementTestable ka) { + if (Arrays.equals(ka.getSecret(), expectedSecret)) { + return new Result(Result.Value.SUCCESS, "The KeyAgreement result matched the expected derived secret."); + } else { + return new Result(Result.Value.FAILURE, "The KeyAgreement result did not match the expected derived secret."); + } + } + }); + } + + public static KeyAgreementTest expect(KeyAgreementTestable ka, Result.ExpectedValue expected) { + return new KeyAgreementTest(ka, new TestCallback() { + @Override + public Result apply(KeyAgreementTestable keyAgreementTestable) { + Result.Value value = Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error()); + return new Result(value, value.description()); + } + }); + } + + public static KeyAgreementTest function(KeyAgreementTestable ka, TestCallback callback) { + return new KeyAgreementTest(ka, callback); + } + + @Override + public String getDescription() { + return "KeyAgreement " + testable.getKa().getAlgorithm(); + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java new file mode 100644 index 0000000..ffcfc67 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java @@ -0,0 +1,129 @@ +package cz.crcs.ectester.standalone.test.base; + +import javax.crypto.KeyAgreement; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.ECParameterSpec; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyAgreementTestable extends StandaloneTestable { + private KeyAgreement ka; + private ECPrivateKey privateKey; + private ECPublicKey publicKey; + private KeyGeneratorTestable kgtPrivate; + private KeyGeneratorTestable kgtPublic; + private AlgorithmParameterSpec spec; + private byte[] secret; + + public KeyAgreementTestable(KeyAgreement ka, ECPrivateKey privateKey, ECPublicKey publicKey) { + this.ka = ka; + this.privateKey = privateKey; + this.publicKey = publicKey; + } + + public KeyAgreementTestable(KeyAgreement ka, ECPrivateKey privateKey, ECPublicKey publicKey, ECParameterSpec spec) { + this(ka, privateKey, publicKey); + this.spec = spec; + } + + public KeyAgreementTestable(KeyAgreement ka, KeyGeneratorTestable kgt, ECPrivateKey privateKey, ECParameterSpec spec) { + this(ka, privateKey, null, spec); + this.kgtPublic = kgt; + } + + public KeyAgreementTestable(KeyAgreement ka, ECPublicKey publicKey, KeyGeneratorTestable kgt, ECParameterSpec spec) { + this(ka, null, publicKey, spec); + this.kgtPrivate = kgt; + } + + public KeyAgreementTestable(KeyAgreement ka, KeyGeneratorTestable privKgt, KeyGeneratorTestable pubKgt, ECParameterSpec spec) { + this(ka, (ECPrivateKey) null, null, spec); + this.kgtPrivate = privKgt; + this.kgtPublic = pubKgt; + } + + public KeyAgreement getKa() { + return ka; + } + + public ECPublicKey getPublicKey() { + return publicKey; + } + + public ECPrivateKey getPrivateKey() { + return privateKey; + } + + public byte[] getSecret() { + if (!hasRun) { + return null; + } + return secret; + } + + @Override + public void run() { + try { + stage = KeyAgreementStage.GetPrivate; + if (kgtPrivate != null) { + privateKey = (ECPrivateKey) kgtPrivate.getKeyPair().getPrivate(); + } + + stage = KeyAgreementStage.GetPublic; + if (kgtPublic != null) { + publicKey = (ECPublicKey) kgtPublic.getKeyPair().getPublic(); + } + + stage = KeyAgreementStage.Init; + try { + if (spec != null) { + ka.init(privateKey, spec); + } else { + ka.init(privateKey); + } + } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { + ok = false; + hasRun = true; + return; + } + + stage = KeyAgreementStage.DoPhase; + try { + ka.doPhase(publicKey, true); + } catch (IllegalStateException | InvalidKeyException e) { + ok = false; + hasRun = true; + return; + } + + stage = KeyAgreementStage.GenerateSecret; + try { + secret = ka.generateSecret(); + } catch (IllegalStateException | UnsupportedOperationException isex) { + ok = false; + hasRun = true; + return; + } + + ok = true; + } catch (Exception ex) { + ok = false; + error = true; + errorCause = ex; + } + hasRun = true; + } + + public enum KeyAgreementStage { + GetPrivate, + GetPublic, + Init, + DoPhase, + GenerateSecret + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java new file mode 100644 index 0000000..b232456 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java @@ -0,0 +1,33 @@ +package cz.crcs.ectester.standalone.test.base; + +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.common.test.SimpleTest; +import cz.crcs.ectester.common.test.TestCallback; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyGeneratorTest extends SimpleTest { + private KeyGeneratorTest(KeyGeneratorTestable kg, TestCallback callback) { + super(kg, callback); + } + + public static KeyGeneratorTest expect(KeyGeneratorTestable kg, Result.ExpectedValue expected) { + return new KeyGeneratorTest(kg, new TestCallback() { + @Override + public Result apply(KeyGeneratorTestable keyGenerationTestable) { + Result.Value value = Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error()); + return new Result(value, value.description()); + } + }); + } + + public static KeyGeneratorTest function(KeyGeneratorTestable ka, TestCallback callback) { + return new KeyGeneratorTest(ka, callback); + } + + @Override + public String getDescription() { + return "KeyPairGenerator " + testable.getKpg().getAlgorithm(); + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java new file mode 100644 index 0000000..b561b8b --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java @@ -0,0 +1,71 @@ +package cz.crcs.ectester.standalone.test.base; + +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.spec.ECParameterSpec; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyGeneratorTestable extends StandaloneTestable { + private KeyPair kp; + private KeyPairGenerator kpg; + private int keysize = 0; + private ECParameterSpec spec = null; + + public KeyGeneratorTestable(KeyPairGenerator kpg) { + this.kpg = kpg; + } + + public KeyGeneratorTestable(KeyPairGenerator kpg, int keysize) { + this.kpg = kpg; + this.keysize = keysize; + } + + public KeyGeneratorTestable(KeyPairGenerator kpg, ECParameterSpec spec) { + this.kpg = kpg; + this.spec = spec; + } + + public KeyPairGenerator getKpg() { + return kpg; + } + + public KeyPair getKeyPair() { + return kp; + } + + @Override + public void run() { + try { + stage = KeyGeneratorStage.Init; + try { + if (spec != null) { + kpg.initialize(spec); + } else if (keysize != 0) { + kpg.initialize(keysize); + } + } catch (InvalidAlgorithmParameterException e) { + ok = false; + hasRun = true; + return; + } + + stage = KeyGeneratorStage.GenKeyPair; + kp = kpg.genKeyPair(); + + ok = true; + } catch (Exception ex) { + ok = false; + error = true; + errorCause = ex; + } + hasRun = true; + } + + public enum KeyGeneratorStage { + Init, + GenKeyPair + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/base/SignatureTest.java new file mode 100644 index 0000000..d8b3e0f --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/SignatureTest.java @@ -0,0 +1,33 @@ +package cz.crcs.ectester.standalone.test.base; + +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.common.test.SimpleTest; +import cz.crcs.ectester.common.test.TestCallback; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class SignatureTest extends SimpleTest { + private SignatureTest(SignatureTestable sig, TestCallback callback) { + super(sig, callback); + } + + public static SignatureTest expect(SignatureTestable kg, Result.ExpectedValue expected) { + return new SignatureTest(kg, new TestCallback() { + @Override + public Result apply(SignatureTestable signatureTestable) { + Result.Value value = Result.Value.fromExpected(expected, signatureTestable.ok(), signatureTestable.error()); + return new Result(value, value.description()); + } + }); + } + + public static SignatureTest function(SignatureTestable ka, TestCallback callback) { + return new SignatureTest(ka, callback); + } + + @Override + public String getDescription() { + return "Signature " + testable.getSig().getAlgorithm(); + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java new file mode 100644 index 0000000..873757b --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java @@ -0,0 +1,135 @@ +package cz.crcs.ectester.standalone.test.base; + +import java.security.InvalidKeyException; +import java.security.SecureRandom; +import java.security.Signature; +import java.security.SignatureException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class SignatureTestable extends StandaloneTestable { + private Signature sig; + private ECPrivateKey signKey; + private ECPublicKey verifyKey; + private KeyGeneratorTestable kgt; + private byte[] data; + private byte[] signature; + private boolean verified; + + public SignatureTestable(Signature sig, ECPrivateKey signKey, ECPublicKey verifyKey, byte[] data) { + this.sig = sig; + this.signKey = signKey; + this.verifyKey = verifyKey; + this.data = data; + if (data == null) { + SecureRandom random = new SecureRandom(); + this.data = new byte[64]; + random.nextBytes(this.data); + } + } + + public SignatureTestable(Signature sig, KeyGeneratorTestable kgt, byte[] data) { + this(sig, null, null, data); + this.kgt = kgt; + } + + public Signature getSig() { + return sig; + } + + public byte[] getData() { + return data; + } + + public byte[] getSignature() { + return signature; + } + + public boolean getVerified() { + return verified; + } + + @Override + public void run() { + try { + stage = SignatureStage.GetKeys; + if (kgt != null) { + signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate(); + verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic(); + } + + stage = SignatureStage.InitSign; + try { + sig.initSign(signKey); + } catch (InvalidKeyException e) { + ok = false; + hasRun = true; + return; + } + + stage = SignatureStage.UpdateSign; + try { + sig.update(data); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + stage = SignatureStage.Sign; + try { + signature = sig.sign(); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + stage = SignatureStage.InitVerify; + try { + sig.initVerify(verifyKey); + } catch (InvalidKeyException e) { + ok = false; + hasRun = true; + return; + } + + stage = SignatureStage.UpdateVerify; + try { + sig.update(data); + } catch (SignatureException e) { + ok = false; + hasRun = true; + return; + } + + stage = SignatureStage.Verify; + try { + verified = sig.verify(signature); + } catch (SignatureException e) { + ok = false; + hasRun = true; + } + + ok = true; + } catch (Exception ex) { + ok = false; + error = true; + errorCause = ex; + } + hasRun = true; + } + + public enum SignatureStage { + GetKeys, + InitSign, + UpdateSign, + Sign, + InitVerify, + UpdateVerify, + Verify + } +} diff --git a/src/cz/crcs/ectester/standalone/test/base/StandaloneTestable.java b/src/cz/crcs/ectester/standalone/test/base/StandaloneTestable.java new file mode 100644 index 0000000..8654e94 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/base/StandaloneTestable.java @@ -0,0 +1,14 @@ +package cz.crcs.ectester.standalone.test.base; + +import cz.crcs.ectester.common.test.BaseTestable; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public abstract class StandaloneTestable> extends BaseTestable { + protected T stage; + + public T getStage() { + return stage; + } +} diff --git a/src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java b/src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java new file mode 100644 index 0000000..e030664 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java @@ -0,0 +1,101 @@ +package cz.crcs.ectester.standalone.test.suites; + +import cz.crcs.ectester.common.cli.TreeCommandLine; +import cz.crcs.ectester.common.ec.EC_Curve; +import cz.crcs.ectester.common.output.TestWriter; +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.data.EC_Store; +import cz.crcs.ectester.standalone.ECTesterStandalone; +import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; +import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; +import cz.crcs.ectester.standalone.consts.SignatureIdent; +import cz.crcs.ectester.standalone.test.base.*; + +import javax.crypto.KeyAgreement; +import java.security.KeyPairGenerator; +import java.security.Signature; +import java.security.spec.ECParameterSpec; +import java.util.Optional; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class StandaloneDefaultSuite extends StandaloneTestSuite { + + public StandaloneDefaultSuite(TestWriter writer, ECTesterStandalone.Config cfg, TreeCommandLine cli) { + super(writer, cfg, cli, "default", "The default test suite run basic support of ECDH and ECDSA."); + } + + @Override + protected void runTests() throws Exception { + String kpgAlgo = cli.getOptionValue("test.kpg-type"); + String kaAlgo = cli.getOptionValue("test.ka-type"); + String sigAlgo = cli.getOptionValue("test.sig-type"); + + + KeyPairGeneratorIdent kpgIdent; + if (kpgAlgo == null) { + // try EC, if not, fail with: need to specify kpg algo. + Optional kpgIdentOpt = cfg.selected.getKPGs().stream() + .filter((ident) -> ident.contains("EC")) + .findFirst(); + if (kpgIdentOpt.isPresent()) { + kpgIdent = kpgIdentOpt.get(); + } else { + System.err.println("The default KeyPairGenerator algorithm type of \"EC\" was not found. Need to specify a type."); + return; + } + } else { + // try the specified, if not, fail with: wrong kpg algo/not found. + Optional kpgIdentOpt = cfg.selected.getKPGs().stream() + .filter((ident) -> ident.contains(kpgAlgo)) + .findFirst(); + if (kpgIdentOpt.isPresent()) { + kpgIdent = kpgIdentOpt.get(); + } else { + System.err.println("The KeyPairGenerator algorithm type of \"" + kpgAlgo + "\" was not found."); + return; + } + } + + KeyPairGenerator kpg = kpgIdent.getInstance(cfg.selected.getProvider()); + + KeyGeneratorTestable kgtOne; + KeyGeneratorTestable kgtOther; + ECParameterSpec spec = null; + if (cli.hasOption("test.bits")) { + int bits = Integer.parseInt(cli.getOptionValue("test.bits")); + kgtOne = new KeyGeneratorTestable(kpg, bits); + kgtOther = new KeyGeneratorTestable(kpg, bits); + } else if (cli.hasOption("test.named-curve")) { + String curveName = cli.getOptionValue("test.named-curve"); + EC_Curve curve = EC_Store.getInstance().getObject(EC_Curve.class, curveName); + if (curve == null) { + System.err.println("Curve not found: " + curveName); + return; + } + spec = curve.toSpec(); + kgtOne = new KeyGeneratorTestable(kpg, spec); + kgtOther = new KeyGeneratorTestable(kpg, spec); + } else { + kgtOne = new KeyGeneratorTestable(kpg); + kgtOther = new KeyGeneratorTestable(kpg); + } + + doTest(KeyGeneratorTest.expect(kgtOne, Result.ExpectedValue.SUCCESS)); + doTest(KeyGeneratorTest.expect(kgtOther, Result.ExpectedValue.SUCCESS)); + + for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) { + if (kaAlgo == null || kaIdent.contains(kaAlgo)) { + KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider()); + doTest(KeyAgreementTest.expect(new KeyAgreementTestable(ka, kgtOne, kgtOther, spec), Result.ExpectedValue.SUCCESS)); + } + } + for (SignatureIdent sigIdent : cfg.selected.getSigs()) { + if (sigAlgo == null || sigIdent.contains(sigAlgo)) { + Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); + doTest(SignatureTest.expect(new SignatureTestable(sig, kgtOne, null), Result.ExpectedValue.SUCCESS)); + } + } + } +} diff --git a/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java new file mode 100644 index 0000000..c01f8cd --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java @@ -0,0 +1,25 @@ +package cz.crcs.ectester.standalone.test.suites; + +import cz.crcs.ectester.common.cli.TreeCommandLine; +import cz.crcs.ectester.common.output.TestWriter; +import cz.crcs.ectester.common.test.TestSuite; +import cz.crcs.ectester.standalone.ECTesterStandalone; +import cz.crcs.ectester.standalone.libs.ProviderECLibrary; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public abstract class StandaloneTestSuite extends TestSuite { + TreeCommandLine cli; + ECTesterStandalone.Config cfg; + + public StandaloneTestSuite(TestWriter writer, ECTesterStandalone.Config cfg, TreeCommandLine cli, String name, String description) { + super(writer, name, description); + this.cfg = cfg; + this.cli = cli; + } + + public ProviderECLibrary getLibrary() { + return cfg.selected; + } +} -- cgit v1.2.3-70-g09d2