diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/common/cli/Colors.java | 4 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/common/output/BaseTextTestWriter.java | 4 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/output/TextTestWriter.java | 7 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/CardWrongSuite.java | 20 |
5 files changed, 28 insertions, 11 deletions
@@ -110,7 +110,7 @@ For format of this file see [FORMAT](docs/FORMAT.md). #### Test `-t / --test [test_suite]` -Perform support and performance tests of ECC. +Perform support,performance and vulnerability tests of ECC. Use with `-o / --output [out_type:]<out_file>` to output the test results to a file. For possible formats of this file see [FORMAT](docs/FORMAT.md). @@ -165,7 +165,7 @@ This shows that JCardsim simulates 112b Fp support with default curve present an ═══ Date: 2018.05.02 20:29:38 ═══ ECTester version: v0.2.0 ═══ Card ATR: 3bfa1800008131fe454a434f5033315632333298 - OK ┳ Tests of 112b ALG_EC_FP support. ┃ SUCCESS ┃ All sub-tests matched the expected mask. + OK ┳ (0) Tests of 112b ALG_EC_FP support. ┃ SUCCESS ┃ All sub-tests matched the expected mask. ┣ OK ━ Allocate both keypairs 112b ALG_EC_FP ┃ SUCCESS ┃ 22 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Generate both keypairs ┃ SUCCESS ┃ 23 ms ┃ OK (0x9000) OK (0x9000) ┣ OK ━ Allocate both keypairs 112b ALG_EC_FP ┃ SUCCESS ┃ 0 ms ┃ OK (0x9000) OK (0x9000) diff --git a/src/cz/crcs/ectester/common/cli/Colors.java b/src/cz/crcs/ectester/common/cli/Colors.java index cdc42e8..7601088 100644 --- a/src/cz/crcs/ectester/common/cli/Colors.java +++ b/src/cz/crcs/ectester/common/cli/Colors.java @@ -90,4 +90,8 @@ public class Colors { public static String bold(String text) { return colored(text, Attribute.BOLD); } + + public static String underline(String text) { + return colored(text, Attribute.UNDERLINE); + } }
\ No newline at end of file diff --git a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java index eef767b..f28f90a 100644 --- a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java +++ b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java @@ -27,13 +27,13 @@ public abstract class BaseTextTestWriter implements TestWriter { @Override public void begin(TestSuite suite) { - output.println("═══ Running test suite: " + Colors.bold(suite.getName()) + " ═══"); + output.println("═══ " + Colors.underline("Running test suite:") + " " + Colors.bold(suite.getName()) + " ═══"); for (String d : suite.getDescription()) { output.println("═══ " + d); } DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); Date date = new Date(); - output.println("═══ Date: " + dateFormat.format(date)); + output.println("═══ " + Colors.underline("Date:") + " " + dateFormat.format(date)); output.print(deviceString(suite)); } diff --git a/src/cz/crcs/ectester/reader/output/TextTestWriter.java b/src/cz/crcs/ectester/reader/output/TextTestWriter.java index 35d0900..a8e4ce9 100644 --- a/src/cz/crcs/ectester/reader/output/TextTestWriter.java +++ b/src/cz/crcs/ectester/reader/output/TextTestWriter.java @@ -1,5 +1,6 @@ package cz.crcs.ectester.reader.output; +import cz.crcs.ectester.common.cli.Colors; import cz.crcs.ectester.common.output.BaseTextTestWriter; import cz.crcs.ectester.common.test.TestSuite; import cz.crcs.ectester.common.test.Testable; @@ -42,12 +43,12 @@ public class TextTestWriter extends BaseTextTestWriter { if (suite instanceof CardTestSuite) { CardTestSuite cardSuite = (CardTestSuite) suite; StringBuilder sb = new StringBuilder(); - sb.append("═══ ECTester version: " + ECTesterReader.VERSION + ECTesterReader.GIT_COMMIT).append(System.lineSeparator()); - sb.append("═══ Card ATR: ").append(ByteUtil.bytesToHex(cardSuite.getCard().getATR().getBytes(), false)).append(System.lineSeparator()); + sb.append("═══ " + Colors.underline("ECTester version:") + " " + ECTesterReader.VERSION + ECTesterReader.GIT_COMMIT).append(System.lineSeparator()); + sb.append("═══ " + Colors.underline("Card ATR:") + " ").append(ByteUtil.bytesToHex(cardSuite.getCard().getATR().getBytes(), false)).append(System.lineSeparator()); try { CardMngr.CPLC cplc = cardSuite.getCard().getCPLC(); if (!cplc.values().isEmpty()) { - sb.append("═══ Card CPLC data:").append(System.lineSeparator()); + sb.append("═══ " + Colors.underline("Card CPLC data:")).append(System.lineSeparator()); for (Map.Entry<CardMngr.CPLC.Field, byte[]> entry : cplc.values().entrySet()) { CardMngr.CPLC.Field field = entry.getKey(); byte[] value = entry.getValue(); diff --git a/src/cz/crcs/ectester/reader/test/CardWrongSuite.java b/src/cz/crcs/ectester/reader/test/CardWrongSuite.java index 2057093..34d151b 100644 --- a/src/cz/crcs/ectester/reader/test/CardWrongSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardWrongSuite.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Random; import static cz.crcs.ectester.common.test.Result.ExpectedValue; + /** * @author Jan Jancar johny@neuromancer.sk */ @@ -112,22 +113,33 @@ public class CardWrongSuite extends CardTestSuite { Test resetSetup = CompoundTest.all(ExpectedValue.SUCCESS, "Reset keypair.", set.clone()); Test randomG = ecdhTest(new Command.Transform(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.KEY_BOTH, EC_Consts.PARAMETER_G, (short) (EC_Consts.TRANSFORMATION_FULLRANDOM | EC_Consts.TRANSFORMATION_04_MASK)), "Set G = random non-point/point-like.", "ECDH with non-point G."); + Test fullRandomG = ecdhTest(new Command.Transform(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.KEY_BOTH, EC_Consts.PARAMETER_G, EC_Consts.TRANSFORMATION_FULLRANDOM), "Set G = random data.", "ECDH with G = random data."); Test zeroG = ecdhTest(new Command.Transform(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.KEY_BOTH, EC_Consts.PARAMETER_G, EC_Consts.TRANSFORMATION_INFINITY), "Set G = inifnity.", "ECDH with G = infinity."); - Test wrongG = CompoundTest.all(ExpectedValue.SUCCESS, "Tests with corrupted G parameter.", zeroG, randomG); + Test wrongG = CompoundTest.all(ExpectedValue.SUCCESS, "Tests with corrupted G parameter.", randomG, fullRandomG, zeroG); byte[] originalR = new byte[keyLength]; EC_Consts.getCurveParameter(curve, EC_Consts.PARAMETER_R, originalR, (short) 0); BigInteger originalBigR = new BigInteger(1, originalR); + + BigInteger prevPrimeR; + do { + prevPrimeR = BigInteger.probablePrime(keyLength, r); + } while (prevPrimeR.compareTo(originalBigR) >= 0); + byte[] prevRBytes = ECUtil.toByteArray(prevPrimeR, keyLength); + EC_Params prevRData = new EC_Params(EC_Consts.PARAMETER_R, new byte[][]{prevRBytes}); + Test prevprimeWrongR = ecdhTest(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, prevRData.getParams(), prevRData.flatten()), "Set R = some prime (but [r]G != infinity) smaller than original R.", "ECDH with wrong R, prevprime."); + BigInteger nextPrimeR = originalBigR.nextProbablePrime(); byte[] nextRBytes = ECUtil.toByteArray(nextPrimeR, keyLength); EC_Params nextRData = new EC_Params(EC_Consts.PARAMETER_R, new byte[][]{nextRBytes}); - Test primeWrongR = ecdhTest(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, nextRData.getParams(), nextRData.flatten()), "Set R = some prime (but [r]G != infinity).", "ECDH with wrong R, prime."); + Test nextprimeWrongR = ecdhTest(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, nextRData.getParams(), nextRData.flatten()), "Set R = some prime (but [r]G != infinity) larger than original R.", "ECDH with wrong R, nextprime."); + byte[] nonprimeRBytes = nextRBytes.clone(); nonprimeRBytes[0] ^= 1; EC_Params nonprimeWrongRData = new EC_Params(EC_Consts.PARAMETER_R, new byte[][]{nonprimeRBytes}); Test nonprimeWrongR = ecdhTest(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, nonprimeWrongRData.getParams(), nonprimeWrongRData.flatten()), "Set R = some composite (but [r]G != infinity).", "ECDH with wrong R, composite."); - Test wrongR = CompoundTest.all(ExpectedValue.SUCCESS, "Tests with corrupted R parameter.", primeWrongR, nonprimeWrongR); + Test wrongR = CompoundTest.all(ExpectedValue.SUCCESS, "Tests with corrupted R parameter.", prevprimeWrongR, nextprimeWrongR, nonprimeWrongR); doTest(CompoundTest.all(ExpectedValue.SUCCESS, "Tests of " + keyLength + "b " + CardUtil.getKeyTypeString(KeyPair.ALG_EC_FP), setup, wrongPrime, resetSetup, wrongG, resetSetup.clone(), wrongR, resetSetup.clone())); } @@ -197,6 +209,6 @@ public class CardWrongSuite extends CardTestSuite { return; } ecdh.run(); - },fullDesc, preparePhase, allocateECDH, ecdh); + }, fullDesc, preparePhase, allocateECDH, ecdh); } } |
