diff options
Diffstat (limited to 'src')
14 files changed, 145 insertions, 60 deletions
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<String, Object> testableObject(Testable t) { Map<String, Object> 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/base/KeyAgreementTest.java index 33c7385..8297d76 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java +++ b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTest.java @@ -1,4 +1,4 @@ -package cz.crcs.ectester.standalone.test; +package cz.crcs.ectester.standalone.test.base; import cz.crcs.ectester.common.test.Result; import cz.crcs.ectester.common.test.SimpleTest; diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java index aac2127..ffcfc67 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java +++ b/src/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java @@ -1,6 +1,4 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; +package cz.crcs.ectester.standalone.test.base; import javax.crypto.KeyAgreement; import java.security.InvalidAlgorithmParameterException; @@ -13,7 +11,7 @@ import java.security.spec.ECParameterSpec; /** * @author Jan Jancar johny@neuromancer.sk */ -public class KeyAgreementTestable extends BaseTestable { +public class KeyAgreementTestable extends StandaloneTestable<KeyAgreementTestable.KeyAgreementStage> { private KeyAgreement ka; private ECPrivateKey privateKey; private ECPublicKey publicKey; @@ -71,14 +69,17 @@ public class KeyAgreementTestable extends BaseTestable { @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); @@ -87,25 +88,24 @@ public class KeyAgreementTestable extends BaseTestable { } } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { ok = false; - error = false; hasRun = true; return; } + stage = KeyAgreementStage.DoPhase; try { ka.doPhase(publicKey, true); } catch (IllegalStateException | InvalidKeyException e) { ok = false; - error = false; hasRun = true; return; } + stage = KeyAgreementStage.GenerateSecret; try { secret = ka.generateSecret(); } catch (IllegalStateException | UnsupportedOperationException isex) { ok = false; - error = false; hasRun = true; return; } @@ -118,4 +118,12 @@ public class KeyAgreementTestable extends BaseTestable { } hasRun = true; } + + public enum KeyAgreementStage { + GetPrivate, + GetPublic, + Init, + DoPhase, + GenerateSecret + } } diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java index 02b81a4..b232456 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java +++ b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTest.java @@ -1,4 +1,4 @@ -package cz.crcs.ectester.standalone.test; +package cz.crcs.ectester.standalone.test.base; import cz.crcs.ectester.common.test.Result; import cz.crcs.ectester.common.test.SimpleTest; diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java index 774c3ec..b561b8b 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java +++ b/src/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java @@ -1,6 +1,4 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; +package cz.crcs.ectester.standalone.test.base; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; @@ -10,7 +8,7 @@ import java.security.spec.ECParameterSpec; /** * @author Jan Jancar johny@neuromancer.sk */ -public class KeyGeneratorTestable extends BaseTestable { +public class KeyGeneratorTestable extends StandaloneTestable<KeyGeneratorTestable.KeyGeneratorStage> { private KeyPair kp; private KeyPairGenerator kpg; private int keysize = 0; @@ -41,6 +39,7 @@ public class KeyGeneratorTestable extends BaseTestable { @Override public void run() { try { + stage = KeyGeneratorStage.Init; try { if (spec != null) { kpg.initialize(spec); @@ -48,13 +47,15 @@ public class KeyGeneratorTestable extends BaseTestable { kpg.initialize(keysize); } } catch (InvalidAlgorithmParameterException e) { - hasRun = true; ok = false; + hasRun = true; return; } + + stage = KeyGeneratorStage.GenKeyPair; kp = kpg.genKeyPair(); - ok = true; + ok = true; } catch (Exception ex) { ok = false; error = true; @@ -62,4 +63,9 @@ public class KeyGeneratorTestable extends BaseTestable { } hasRun = true; } + + public enum KeyGeneratorStage { + Init, + GenKeyPair + } } diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/base/SignatureTest.java index 481d289..d8b3e0f 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTest.java +++ b/src/cz/crcs/ectester/standalone/test/base/SignatureTest.java @@ -1,4 +1,4 @@ -package cz.crcs.ectester.standalone.test; +package cz.crcs.ectester.standalone.test.base; import cz.crcs.ectester.common.test.Result; import cz.crcs.ectester.common.test.SimpleTest; diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java index 6bc9b30..873757b 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java +++ b/src/cz/crcs/ectester/standalone/test/base/SignatureTestable.java @@ -1,7 +1,4 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.BaseTestable; -import cz.crcs.ectester.common.test.TestException; +package cz.crcs.ectester.standalone.test.base; import java.security.InvalidKeyException; import java.security.SecureRandom; @@ -13,7 +10,7 @@ import java.security.interfaces.ECPublicKey; /** * @author Jan Jancar johny@neuromancer.sk */ -public class SignatureTestable extends BaseTestable { +public class SignatureTestable extends StandaloneTestable<SignatureTestable.SignatureStage> { private Signature sig; private ECPrivateKey signKey; private ECPublicKey verifyKey; @@ -29,7 +26,7 @@ public class SignatureTestable extends BaseTestable { this.data = data; if (data == null) { SecureRandom random = new SecureRandom(); - this.data = new byte[32]; + this.data = new byte[64]; random.nextBytes(this.data); } } @@ -58,11 +55,13 @@ public class SignatureTestable extends BaseTestable { @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) { @@ -71,6 +70,7 @@ public class SignatureTestable extends BaseTestable { return; } + stage = SignatureStage.UpdateSign; try { sig.update(data); } catch (SignatureException e) { @@ -79,6 +79,7 @@ public class SignatureTestable extends BaseTestable { return; } + stage = SignatureStage.Sign; try { signature = sig.sign(); } catch (SignatureException e) { @@ -87,6 +88,7 @@ public class SignatureTestable extends BaseTestable { return; } + stage = SignatureStage.InitVerify; try { sig.initVerify(verifyKey); } catch (InvalidKeyException e) { @@ -95,6 +97,7 @@ public class SignatureTestable extends BaseTestable { return; } + stage = SignatureStage.UpdateVerify; try { sig.update(data); } catch (SignatureException e) { @@ -103,6 +106,7 @@ public class SignatureTestable extends BaseTestable { return; } + stage = SignatureStage.Verify; try { verified = sig.verify(signature); } catch (SignatureException e) { @@ -118,4 +122,14 @@ public class SignatureTestable extends BaseTestable { } 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<T extends Enum<T>> extends BaseTestable { + protected T stage; + + public T getStage() { + return stage; + } +} diff --git a/src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java b/src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java index 572449a..e030664 100644 --- a/src/cz/crcs/ectester/standalone/test/StandaloneDefaultSuite.java +++ b/src/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java @@ -1,4 +1,4 @@ -package cz.crcs.ectester.standalone.test; +package cz.crcs.ectester.standalone.test.suites; import cz.crcs.ectester.common.cli.TreeCommandLine; import cz.crcs.ectester.common.ec.EC_Curve; @@ -9,12 +9,13 @@ 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 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 @@ -27,13 +28,36 @@ public class StandaloneDefaultSuite extends StandaloneTestSuite { @Override protected void runTests() throws Exception { - String kpgAlgo = cli.getOptionValue("test.kpg-type", "EC"); + String kpgAlgo = cli.getOptionValue("test.kpg-type"); 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(); + + KeyPairGeneratorIdent kpgIdent; + if (kpgAlgo == null) { + // try EC, if not, fail with: need to specify kpg algo. + Optional<KeyPairGeneratorIdent> 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<KeyPairGeneratorIdent> 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; diff --git a/src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java index 2949d52..c01f8cd 100644 --- a/src/cz/crcs/ectester/standalone/test/StandaloneTestSuite.java +++ b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java @@ -1,4 +1,4 @@ -package cz.crcs.ectester.standalone.test; +package cz.crcs.ectester.standalone.test.suites; import cz.crcs.ectester.common.cli.TreeCommandLine; import cz.crcs.ectester.common.output.TestWriter; |
