diff options
| author | J08nY | 2018-01-13 01:15:44 +0100 |
|---|---|---|
| committer | J08nY | 2018-01-13 01:15:44 +0100 |
| commit | eca4e6a299c5765b1bb2fa17113bc12c84d8a406 (patch) | |
| tree | 2c71746f53696df05edee2ada11586b6991f63d7 | |
| parent | 94e441b522069d3fed4b88a4823b91c1593bac68 (diff) | |
| download | ECTester-eca4e6a299c5765b1bb2fa17113bc12c84d8a406.tar.gz ECTester-eca4e6a299c5765b1bb2fa17113bc12c84d8a406.tar.zst ECTester-eca4e6a299c5765b1bb2fa17113bc12c84d8a406.zip | |
6 files changed, 54 insertions, 29 deletions
diff --git a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java index 06c6d97..6ace3a0 100644 --- a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java +++ b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java @@ -10,7 +10,7 @@ import java.io.PrintStream; public abstract class BaseTextTestWriter implements TestWriter { private PrintStream output; - public static int BASE_WIDTH = 80; + public static int BASE_WIDTH = 90; public BaseTextTestWriter(PrintStream output) { this.output = output; @@ -24,7 +24,7 @@ public abstract class BaseTextTestWriter implements TestWriter { protected abstract String testableString(Testable t); - private String testString(Test t, int offset) { + private String testString(Test t, String prefix) { if (!t.hasRun()) { return null; } @@ -33,7 +33,7 @@ public abstract class BaseTextTestWriter implements TestWriter { StringBuilder out = new StringBuilder(); out.append(t.ok() ? " OK " : "NOK "); out.append(compound ? "┳ " : "━ "); - int width = BASE_WIDTH - (offset + out.length()); + int width = BASE_WIDTH - (prefix.length() + out.length()); String widthSpec = "%-" + String.valueOf(width) + "s"; out.append(String.format(widthSpec, t.getDescription())); out.append(" ┃ "); @@ -47,11 +47,13 @@ public abstract class BaseTextTestWriter implements TestWriter { Test[] tests = test.getTests(); for (int i = 0; i < tests.length; ++i) { if (i == tests.length - 1) { - out.append(" ┗ "); + out.append(prefix).append(" ┗ "); + out.append(testString(tests[i], prefix + " ")); } else { - out.append(" ┣ "); + out.append(prefix).append(" ┣ "); + out.append(testString(tests[i], prefix + " ┃ ")); } - out.append(testString(tests[i], offset + 6)); + if (i != tests.length - 1) { out.append(System.lineSeparator()); } @@ -67,7 +69,7 @@ public abstract class BaseTextTestWriter implements TestWriter { public void outputTest(Test t) { if (!t.hasRun()) return; - output.println(testString(t, 0)); + output.println(testString(t, "")); output.flush(); } diff --git a/src/cz/crcs/ectester/common/test/CompoundTest.java b/src/cz/crcs/ectester/common/test/CompoundTest.java index bcf4a0e..3b0b542 100644 --- a/src/cz/crcs/ectester/common/test/CompoundTest.java +++ b/src/cz/crcs/ectester/common/test/CompoundTest.java @@ -34,7 +34,7 @@ public class CompoundTest extends Test { return new CompoundTest((tests) -> { for (Test test : tests) { if (!Result.Value.fromExpected(what, test.ok()).ok()) { - return new Result(Result.Value.FAILURE, "At least one of the sub-tests did not have the expected result."); + 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."); @@ -51,7 +51,7 @@ public class CompoundTest extends Test { return new CompoundTest((tests) -> { for (Test test : tests) { if (Result.Value.fromExpected(what, test.ok()).ok()) { - return new Result(Result.Value.SUCCESS, "At least one of the sub-tests did have the expected result."); + 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."); @@ -68,7 +68,7 @@ public class CompoundTest extends Test { return new CompoundTest((tests) -> { for (int i = 0; i < results.length; ++i) { if (!Result.Value.fromExpected(results[i], tests[i].ok()).ok()) { - return new Result(Result.Value.FAILURE, "At least one of the sub-tests did not match the result mask."); + return new Result(Result.Value.FAILURE, "Some sub-tests did not match the result mask."); } } return new Result(Result.Value.SUCCESS, "All sub-tests matched the expected mask."); @@ -93,6 +93,7 @@ public class CompoundTest extends Test { for (Test test : tests) { test.run(); } + result = callback.apply(tests); this.hasRun = true; } diff --git a/src/cz/crcs/ectester/common/test/TestException.java b/src/cz/crcs/ectester/common/test/TestException.java index 01d195c..008e9f6 100644 --- a/src/cz/crcs/ectester/common/test/TestException.java +++ b/src/cz/crcs/ectester/common/test/TestException.java @@ -1,7 +1,9 @@ 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 * @author Jan Jancar johny@neuromancer.sk */ public class TestException extends Exception { diff --git a/src/cz/crcs/ectester/common/test/Testable.java b/src/cz/crcs/ectester/common/test/Testable.java index 3627075..5b84a45 100644 --- a/src/cz/crcs/ectester/common/test/Testable.java +++ b/src/cz/crcs/ectester/common/test/Testable.java @@ -21,7 +21,7 @@ public interface Testable { /** * Run this Runnable. * - * @throws TestException + * @throws TestException If an unexpected exception/error is encountered. */ void run() throws TestException; } diff --git a/src/cz/crcs/ectester/reader/test/CardDefaultSuite.java b/src/cz/crcs/ectester/reader/test/CardDefaultSuite.java index 9de741c..b05d4fe 100644 --- a/src/cz/crcs/ectester/reader/test/CardDefaultSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardDefaultSuite.java @@ -11,6 +11,9 @@ import cz.crcs.ectester.reader.ECTesterReader; import cz.crcs.ectester.reader.command.Command; import javacard.security.KeyPair; +import java.util.LinkedList; +import java.util.List; + import static cz.crcs.ectester.common.test.Result.ExpectedValue; /** @@ -34,30 +37,47 @@ public class CardDefaultSuite extends CardTestSuite { private void runDefault(byte field) throws Exception { for (short keyLength : EC_Consts.FP_SIZES) { - Test key = doTest(CommandTest.expect(new Command.Allocate(this.card, ECTesterApplet.KEYPAIR_BOTH, keyLength, field), ExpectedValue.SUCCESS)); + String description = "Tests of " + keyLength + "b " + (field == KeyPair.ALG_EC_FP ? "ALG_EC_FP" : "ALG_EC_F2M") + " support."; + + List<Test> supportTests = new LinkedList<>(); + Test key = runTest(CommandTest.expect(new Command.Allocate(this.card, ECTesterApplet.KEYPAIR_BOTH, keyLength, field), ExpectedValue.SUCCESS)); if (!key.ok()) { + doTest(CompoundTest.all(ExpectedValue.SUCCESS, description + " None.", key)); continue; } - doTest(CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS)); - doTest(CommandTest.expect(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.getCurve(keyLength, field), EC_Consts.PARAMETERS_DOMAIN_FP, null), ExpectedValue.SUCCESS)); - doTest(CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS)); + supportTests.add(key); + + Test genDefault = runTest(CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS)); + Test setCustom = runTest(CommandTest.expect(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.getCurve(keyLength, field), EC_Consts.PARAMETERS_DOMAIN_FP, null), ExpectedValue.SUCCESS)); + Test genCustom = runTest(CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS)); + supportTests.add(genDefault); + supportTests.add(setCustom); + supportTests.add(genCustom); + for (byte kaType : EC_Consts.KA_TYPES) { - Test allocate = CommandTest.expect(new Command.AllocateKeyAgreement(this.card, kaType), ExpectedValue.SUCCESS); - allocate.run(); + Test allocate = runTest(CommandTest.expect(new Command.AllocateKeyAgreement(this.card, kaType), ExpectedValue.SUCCESS)); if (allocate.ok()) { - Test ka = CommandTest.expect(new Command.ECDH(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_NONE, kaType), ExpectedValue.SUCCESS); - ka.run(); - Test kaCompressed = CommandTest.expect(new Command.ECDH(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_COMPRESS, kaType), ExpectedValue.SUCCESS); - kaCompressed.run(); - doTest(CompoundTest.all(ExpectedValue.SUCCESS, "Test of the " + CardUtil.getKATypeString(kaType) + " KeyAgreement.", allocate, ka, kaCompressed)); + Test ka = runTest(CommandTest.expect(new Command.ECDH(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_NONE, kaType), ExpectedValue.SUCCESS)); + Test kaCompressed = runTest(CommandTest.expect(new Command.ECDH(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_COMPRESS, kaType), ExpectedValue.SUCCESS)); + Test compound = runTest(CompoundTest.all(ExpectedValue.SUCCESS, "Test of the " + CardUtil.getKATypeString(kaType) + " KeyAgreement.", allocate, ka, kaCompressed)); + supportTests.add(compound); + } else { + runTest(allocate); + supportTests.add(allocate); } } for (byte sigType : EC_Consts.SIG_TYPES) { - Test allocate = doTest(CommandTest.expect(new Command.AllocateSignature(this.card, sigType), ExpectedValue.SUCCESS)); + Test allocate = runTest(CommandTest.expect(new Command.AllocateSignature(this.card, sigType), ExpectedValue.SUCCESS)); if (allocate.ok()) { - doTest(CommandTest.expect(new Command.ECDSA(this.card, ECTesterApplet.KEYPAIR_LOCAL, sigType, ECTesterApplet.EXPORT_FALSE, null), ExpectedValue.SUCCESS)); + Test expect = runTest(CommandTest.expect(new Command.ECDSA(this.card, ECTesterApplet.KEYPAIR_LOCAL, sigType, ECTesterApplet.EXPORT_FALSE, null), ExpectedValue.SUCCESS)); + Test compound = runTest(CompoundTest.all(ExpectedValue.SUCCESS, "Test of the " + CardUtil.getSigTypeString(sigType) + " signature.", allocate, expect)); + supportTests.add(compound); + } else { + supportTests.add(allocate); } } + doTest(CompoundTest.all(ExpectedValue.SUCCESS, description + " Some.", supportTests.toArray(new Test[0]))); + new Command.Cleanup(this.card).send(); } } } diff --git a/src/cz/crcs/ectester/standalone/consts/KeyAgreementIdent.java b/src/cz/crcs/ectester/standalone/consts/KeyAgreementIdent.java index a5d3578..0e4d311 100644 --- a/src/cz/crcs/ectester/standalone/consts/KeyAgreementIdent.java +++ b/src/cz/crcs/ectester/standalone/consts/KeyAgreementIdent.java @@ -35,10 +35,10 @@ public class KeyAgreementIdent extends Ident { //ALL.add(new KeyAgreementIdent("ECMQVwithSHA256CKDF", "1.3.132.1.15.1")); //ALL.add(new KeyAgreementIdent("ECMQVwithSHA384CKDF", "1.3.132.1.15.2")); //ALL.add(new KeyAgreementIdent("ECMQVwithSHA512CKDF", "1.3.132.1.15.3")); - // ECVKO - ALL.add(new KeyAgreementIdent("ECVKO", "ECGOST3410", "1.2.643.2.2.19", "GOST-3410-2001", "1.2.643.2.2.96")); - ALL.add(new KeyAgreementIdent("ECVKO256", "ECGOST3410-2012-256", "1.2.643.7.1.1.6.1", "1.2.643.7.1.1.1.1")); - ALL.add(new KeyAgreementIdent("ECVKO512", "ECGOST3410-2012-512", "1.2.643.7.1.1.6.2", "1.2.643.7.1.1.1.2")); + // ECVKO - Disable for now as it needs diferent params(too different from DH) + //ALL.add(new KeyAgreementIdent("ECVKO", "ECGOST3410", "1.2.643.2.2.19", "GOST-3410-2001", "1.2.643.2.2.96")); + //ALL.add(new KeyAgreementIdent("ECVKO256", "ECGOST3410-2012-256", "1.2.643.7.1.1.6.1", "1.2.643.7.1.1.1.1")); + //ALL.add(new KeyAgreementIdent("ECVKO512", "ECGOST3410-2012-512", "1.2.643.7.1.1.6.2", "1.2.643.7.1.1.1.2")); } public static KeyAgreementIdent get(String ident) { |
