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/output/YAMLTestWriter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java') diff --git a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java index dfc6813..1ec132d 100644 --- a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java @@ -7,6 +7,7 @@ import cz.crcs.ectester.common.util.ByteUtil; 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 java.io.PrintStream; import java.security.Key; @@ -92,7 +93,13 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { @Override protected Map deviceObject(TestSuite suite) { - //TODO + if (suite instanceof StandaloneTestSuite) { + StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; + Map result = new HashMap<>(); + result.put("type", "library"); + result.put("name", standaloneSuite.getLibrary().name()); + return result; + } return null; } } -- cgit v1.2.3-70-g09d2 From 89ddc1ec043075dbd19c2ec0bcd77b9b83302837 Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 25 Apr 2018 14:10:23 +0200 Subject: Add ECTester version to test run output. --- src/cz/crcs/ectester/reader/ECTesterReader.java | 4 ++-- src/cz/crcs/ectester/reader/output/TextTestWriter.java | 2 ++ src/cz/crcs/ectester/reader/output/XMLTestWriter.java | 2 ++ src/cz/crcs/ectester/reader/output/YAMLTestWriter.java | 2 ++ src/cz/crcs/ectester/standalone/ECTesterStandalone.java | 4 ++-- src/cz/crcs/ectester/standalone/output/TextTestWriter.java | 6 +++++- src/cz/crcs/ectester/standalone/output/XMLTestWriter.java | 2 ++ src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java | 2 ++ 8 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java') diff --git a/src/cz/crcs/ectester/reader/ECTesterReader.java b/src/cz/crcs/ectester/reader/ECTesterReader.java index 84c0439..e982721 100644 --- a/src/cz/crcs/ectester/reader/ECTesterReader.java +++ b/src/cz/crcs/ectester/reader/ECTesterReader.java @@ -66,9 +66,9 @@ public class ECTesterReader { private Config cfg; private Options opts = new Options(); - private static final String VERSION = "v0.2.0"; + public static final String VERSION = "v0.2.0"; private static final String DESCRIPTION = "ECTesterReader " + VERSION + ", a javacard Elliptic Curve Cryptography support tester/utility."; - private static final String LICENSE = "MIT Licensed\nCopyright (c) 2016-2017 Petr Svenda "; + private static final String LICENSE = "MIT Licensed\nCopyright (c) 2016-2018 Petr Svenda "; private static final String CLI_HEADER = "\n" + DESCRIPTION + "\n\n"; private static final String CLI_FOOTER = "\n" + LICENSE; diff --git a/src/cz/crcs/ectester/reader/output/TextTestWriter.java b/src/cz/crcs/ectester/reader/output/TextTestWriter.java index cc168de..1dd21ae 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.ECTesterReader; import cz.crcs.ectester.reader.response.Response; import cz.crcs.ectester.reader.test.CardTestSuite; import cz.crcs.ectester.reader.test.CommandTestable; @@ -41,6 +42,7 @@ public class TextTestWriter extends BaseTextTestWriter { if (suite instanceof CardTestSuite) { CardTestSuite cardSuite = (CardTestSuite) suite; StringBuilder sb = new StringBuilder(); + sb.append("═══ ECTester version: " + ECTesterReader.VERSION).append(System.lineSeparator()); sb.append("═══ Card ATR: ").append(ByteUtil.bytesToHex(cardSuite.getCard().getATR().getBytes(), false)).append(System.lineSeparator()); try { CardMngr.CPLC cplc = cardSuite.getCard().getCPLC(); diff --git a/src/cz/crcs/ectester/reader/output/XMLTestWriter.java b/src/cz/crcs/ectester/reader/output/XMLTestWriter.java index ebe07a6..14b7763 100644 --- a/src/cz/crcs/ectester/reader/output/XMLTestWriter.java +++ b/src/cz/crcs/ectester/reader/output/XMLTestWriter.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.ECTesterReader; import cz.crcs.ectester.reader.command.Command; import cz.crcs.ectester.reader.response.Response; import cz.crcs.ectester.reader.test.CardTestSuite; @@ -113,6 +114,7 @@ public class XMLTestWriter extends BaseXMLTestWriter { CardTestSuite cardSuite = (CardTestSuite) suite; Element result = doc.createElement("device"); result.setAttribute("type", "card"); + result.setAttribute("ectester", ECTesterReader.VERSION); result.appendChild(cplcElement(cardSuite.getCard())); Element atr = doc.createElement("ATR"); diff --git a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java index 4f83ca8..4c908cc 100644 --- a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.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.ECTesterReader; import cz.crcs.ectester.reader.command.Command; import cz.crcs.ectester.reader.response.Response; import cz.crcs.ectester.reader.test.CardTestSuite; @@ -88,6 +89,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { CardTestSuite cardSuite = (CardTestSuite) suite; Map result = new HashMap<>(); result.put("type", "card"); + result.put("ectester", ECTesterReader.VERSION); result.put("cplc", cplcObject(cardSuite.getCard())); result.put("ATR", ByteUtil.bytesToHex(cardSuite.getCard().getATR().getBytes(), false)); return result; diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java index caf99ae..5f2a420 100644 --- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java +++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java @@ -70,9 +70,9 @@ public class ECTesterStandalone { private Options opts = new Options(); private TreeParser optParser; private TreeCommandLine cli; - private static final String VERSION = "v0.2.0"; + public static final String VERSION = "v0.2.0"; private static final String DESCRIPTION = "ECTesterStandalone " + VERSION + ", an Elliptic Curve Cryptography support tester/utility."; - private static final String LICENSE = "MIT Licensed\nCopyright (c) 2016-2017 Petr Svenda "; + private static final String LICENSE = "MIT Licensed\nCopyright (c) 2016-2018 Petr Svenda "; private static final String CLI_HEADER = "\n" + DESCRIPTION + "\n\n"; private static final String CLI_FOOTER = "\n" + LICENSE; diff --git a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java index 716451b..26e1b1a 100644 --- a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java @@ -3,6 +3,7 @@ package cz.crcs.ectester.standalone.output; 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 java.io.PrintStream; @@ -25,7 +26,10 @@ public class TextTestWriter extends BaseTextTestWriter { protected String deviceString(TestSuite suite) { if (suite instanceof StandaloneTestSuite) { StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; - return standaloneSuite.getLibrary().name(); + StringBuilder sb = new StringBuilder(); + sb.append("═══ ECTester version: " + ECTesterStandalone.VERSION).append(System.lineSeparator()); + sb.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 63838cb..2a35ce3 100644 --- a/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java @@ -4,6 +4,7 @@ import cz.crcs.ectester.common.output.BaseXMLTestWriter; 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; @@ -118,6 +119,7 @@ public class XMLTestWriter extends BaseXMLTestWriter { StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; Element result = doc.createElement("device"); result.setAttribute("type", "library"); + result.setAttribute("ectester", ECTesterStandalone.VERSION); Element name = doc.createElement("name"); name.setTextContent(standaloneSuite.getLibrary().name()); diff --git a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java index 1ec132d..c452133 100644 --- a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java @@ -4,6 +4,7 @@ import cz.crcs.ectester.common.output.BaseYAMLTestWriter; 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; @@ -97,6 +98,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; Map result = new HashMap<>(); result.put("type", "library"); + result.put("ectester", ECTesterStandalone.VERSION); result.put("name", standaloneSuite.getLibrary().name()); return result; } -- 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/output/YAMLTestWriter.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 From 298ffc18e590d07eb04d2c5c2b1d553f8fba71bd Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 28 May 2018 21:45:19 +0200 Subject: Implement tracking and writing of exceptions in standalone tests. --- .../ectester/common/output/BaseYAMLTestWriter.java | 8 +++--- .../ectester/reader/output/YAMLTestWriter.java | 15 +++++------ .../ectester/standalone/output/TextTestWriter.java | 20 ++++++++++++--- .../ectester/standalone/output/XMLTestWriter.java | 17 +++++++++++- .../ectester/standalone/output/YAMLTestWriter.java | 30 ++++++++++++++++------ .../standalone/test/base/KeyAgreementTestable.java | 11 +++----- .../standalone/test/base/KeyGeneratorTestable.java | 3 +-- .../standalone/test/base/SignatureTestable.java | 21 ++++++--------- .../standalone/test/base/StandaloneTestable.java | 11 ++++++++ 9 files changed, 89 insertions(+), 47 deletions(-) (limited to 'src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java') diff --git a/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java b/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java index c274cf2..609e46d 100644 --- a/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java +++ b/src/cz/crcs/ectester/common/output/BaseYAMLTestWriter.java @@ -25,8 +25,8 @@ public abstract class BaseYAMLTestWriter implements TestWriter { @Override public void begin(TestSuite suite) { output.println("---"); - testRun = new HashMap<>(); - testSuite = new HashMap<>(); + testRun = new LinkedHashMap<>(); + testSuite = new LinkedHashMap<>(); tests = new LinkedList<>(); testSuite.put("name", suite.getName()); testSuite.put("desc", suite.getDescription()); @@ -59,7 +59,7 @@ public abstract class BaseYAMLTestWriter implements TestWriter { } private Map resultObject(Result result) { - Map resultObject = new HashMap<>(); + Map resultObject = new LinkedHashMap<>(); resultObject.put("ok", result.ok()); resultObject.put("value", result.getValue().name()); resultObject.put("cause", causeObject(result.getCause())); @@ -107,7 +107,7 @@ public abstract class BaseYAMLTestWriter implements TestWriter { options.setPrettyFlow(true); Yaml yaml = new Yaml(options); - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); result.put("testRun", testRun); String out = yaml.dump(result); diff --git a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java index 4c908cc..820521d 100644 --- a/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/reader/output/YAMLTestWriter.java @@ -13,10 +13,7 @@ import cz.crcs.ectester.reader.test.CommandTestable; import javax.smartcardio.CardException; import java.io.PrintStream; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Jan Jancar johny@neuromancer.sk @@ -27,7 +24,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map commandObject(Command c) { - Map commandObj = new HashMap<>(); + Map commandObj = new LinkedHashMap<>(); if (c == null) { return commandObj; } @@ -37,7 +34,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map responseObject(Response r) { - Map responseObj = new HashMap<>(); + Map responseObj = new LinkedHashMap<>(); if (r == null) { return responseObj; } @@ -58,7 +55,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { protected Map testableObject(Testable t) { if (t instanceof CommandTestable) { CommandTestable cmd = (CommandTestable) t; - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); result.put("type", "command"); result.put("command", commandObject(cmd.getCommand())); result.put("response", responseObject(cmd.getResponse())); @@ -68,7 +65,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map cplcObject(CardMngr card) { - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); try { CardMngr.CPLC cplc = card.getCPLC(); if (!cplc.values().isEmpty()) { @@ -87,7 +84,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { protected Map deviceObject(TestSuite suite) { if (suite instanceof CardTestSuite) { CardTestSuite cardSuite = (CardTestSuite) suite; - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); result.put("type", "card"); result.put("ectester", ECTesterReader.VERSION); result.put("cplc", cplcObject(cardSuite.getCard())); diff --git a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java index 691bea8..2e29b07 100644 --- a/src/cz/crcs/ectester/standalone/output/TextTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/TextTestWriter.java @@ -4,10 +4,9 @@ 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.base.*; +import cz.crcs.ectester.standalone.test.base.StandaloneTestable; import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite; -import javax.crypto.KeyAgreement; import java.io.PrintStream; /** @@ -18,10 +17,25 @@ public class TextTestWriter extends BaseTextTestWriter { super(output); } + private String causeString(Object cause) { + if (cause == null) { + return ""; + } else if (cause instanceof Exception) { + Exception ex = ((Exception) cause); + return " -> " + ex.getClass().getCanonicalName() + " : " + ex.getMessage(); + } else { + return cause.toString(); + } + } + @Override protected String testableString(Testable t) { if (t instanceof StandaloneTestable) { - return ((StandaloneTestable)t).getStage().name(); + StandaloneTestable testable = (StandaloneTestable) t; + String stage = testable.getStage().name(); + String exception = causeString(testable.getException()); + String errorCause = causeString(testable.errorCause()); + return stage + exception + errorCause; } return ""; } diff --git a/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java index 9332759..1458a12 100644 --- a/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/XMLTestWriter.java @@ -104,10 +104,22 @@ public class XMLTestWriter extends BaseXMLTestWriter { return result; } + private String causeObject(Object cause) { + if (cause == null) { + return ""; + } else if (cause instanceof Exception) { + Exception ex = ((Exception) cause); + return ex.getClass().getCanonicalName() + " : " + ex.getMessage(); + } else { + return cause.toString(); + } + } + @Override protected Element testableElement(Testable t) { Element result = doc.createElement("test"); if (t instanceof StandaloneTestable) { + StandaloneTestable testable = (StandaloneTestable) t; if (t instanceof KeyGeneratorTestable) { result.setAttribute("type", "key-pair-generator"); result.appendChild(kgtElement((KeyGeneratorTestable) t)); @@ -118,7 +130,10 @@ public class XMLTestWriter extends BaseXMLTestWriter { result.setAttribute("type", "signature"); result.appendChild(sigElement((SignatureTestable) t)); } - result.appendChild(stageElement((StandaloneTestable) t)); + result.appendChild(stageElement(testable)); + Element exception = doc.createElement("exception"); + exception.setTextContent(causeObject(testable.getException()) + causeObject(testable.errorCause())); + result.appendChild(exception); } return result; } diff --git a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java index 0926b98..433624a 100644 --- a/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java +++ b/src/cz/crcs/ectester/standalone/output/YAMLTestWriter.java @@ -16,6 +16,7 @@ import java.security.Key; import java.security.PrivateKey; import java.security.PublicKey; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; /** @@ -27,7 +28,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map keyObject(Key key) { - Map kObject = new HashMap<>(); + Map kObject = new LinkedHashMap<>(); if (key == null) { return kObject; } @@ -38,7 +39,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map kaObject(KeyAgreementTestable kat) { - Map katObject = new HashMap<>(); + Map katObject = new LinkedHashMap<>(); katObject.put("algo", kat.getKa().getAlgorithm()); katObject.put("secret", ByteUtil.bytesToHex(kat.getSecret())); @@ -51,10 +52,10 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map kgtObject(KeyGeneratorTestable kgt) { - Map kgtObject = new HashMap<>(); + Map kgtObject = new LinkedHashMap<>(); kgtObject.put("algo", kgt.getKpg().getAlgorithm()); - Map keypair = new HashMap<>(); + Map keypair = new LinkedHashMap<>(); if (kgt.getKeyPair() != null) { PublicKey pkey = kgt.getKeyPair().getPublic(); Map pubObject = keyObject(pkey); @@ -70,17 +71,29 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { } private Map sigObject(SignatureTestable sig) { - Map sigObject = new HashMap<>(); + Map sigObject = new LinkedHashMap<>(); sigObject.put("algo", sig.getSig().getAlgorithm()); sigObject.put("verified", sig.getVerified()); sigObject.put("raw", ByteUtil.bytesToHex(sig.getSignature())); return sigObject; } + private String causeObject(Object cause) { + if (cause == null) { + return ""; + } else if (cause instanceof Exception) { + Exception ex = ((Exception) cause); + return ex.getClass().getCanonicalName() + " : " + ex.getMessage(); + } else { + return cause.toString(); + } + } + @Override protected Map testableObject(Testable t) { - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); if (t instanceof StandaloneTestable) { + StandaloneTestable testable = (StandaloneTestable) t; if (t instanceof KeyGeneratorTestable) { result.put("type", "key-pair-generator"); result.put("key-pair-generator", kgtObject((KeyGeneratorTestable) t)); @@ -91,7 +104,8 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { result.put("type", "signature"); result.put("signature", sigObject((SignatureTestable) t)); } - result.put("stage", ((StandaloneTestable)t).getStage().name()); + result.put("stage", testable.getStage().name()); + result.put("exception", causeObject(testable.getException()) + causeObject(testable.errorCause())); } return result; } @@ -100,7 +114,7 @@ public class YAMLTestWriter extends BaseYAMLTestWriter { protected Map deviceObject(TestSuite suite) { if (suite instanceof StandaloneTestSuite) { StandaloneTestSuite standaloneSuite = (StandaloneTestSuite) suite; - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); result.put("type", "library"); result.put("ectester", ECTesterStandalone.VERSION); result.put("name", standaloneSuite.getLibrary().name()); diff --git a/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java index ffcfc67..1447373 100644 --- a/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java +++ b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java @@ -87,8 +87,7 @@ public class KeyAgreementTestable extends StandaloneTestable> extends BaseTestable { protected T stage; + protected Exception exception; public T getStage() { return stage; } + + public Exception getException() { + return exception; + } + + protected void failOnException(Exception ex) { + ok = false; + hasRun = true; + exception = ex; + } } -- cgit v1.2.3-70-g09d2