Skip to content

Commit

Permalink
Merge pull request #148 from crocs-muni/devel
Browse files Browse the repository at this point in the history
Devel - 1.7.3
  • Loading branch information
petrs authored Jun 10, 2017
2 parents f65f196 + f08051b commit 8fafb50
Show file tree
Hide file tree
Showing 47 changed files with 27,856 additions and 9,050 deletions.
Binary file modified AlgTest_JClient/dist/AlgTestJClient.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion AlgTest_JClient/src/algtest/AlgSupportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void TestSupportedModeSingle(APDU apdu) {
break;
}
case (byte) 0x13: {
try {offset++;m_object = KeyAgreement.getInstance(ALG_EC_SVDP_DH, false); apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = SUPP_ALG_SUPPORTED;}
try {offset++;m_object = KeyAgreement.getInstance(algorithmClass, false); apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = SUPP_ALG_SUPPORTED;}
catch (CryptoException e) { apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) ? (byte) 0 : (byte) 2; }
break;
}
Expand Down
15 changes: 12 additions & 3 deletions AlgTest_JClient/src/algtest/JCAlgTestApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ may be distributed under the terms of the GNU General Public License (GPL),
public class JCAlgTestApplet extends javacard.framework.Applet
{
// NOTE: when incrementing version, don't forget to update ALGTEST_JAVACARD_VERSION_CURRENT value
/**
* Version 1.7.3 (10.06.2017) + fixed issue with incorrect test for KeyAgreement support
*/
final static byte ALGTEST_JAVACARD_VERSION_1_7_3[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x33};
/**
* Version 1.7.2 (06.05.2017)
* + better support for RSA key collection
*/
//final static byte ALGTEST_JAVACARD_VERSION_1_7_2[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x32};
/**
* Version 1.7.1 (04.10.2016)
* + fixed issue with detection of ECFP-384 curve
*/
final static byte ALGTEST_JAVACARD_VERSION_1_7_1[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x31};
//final static byte ALGTEST_JAVACARD_VERSION_1_7_1[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x31};
/**
* Version 1.7.0 (16.9.2016)
* + applet/package AID change (now jcalgtest in hexa)
Expand All @@ -66,7 +75,7 @@ public class JCAlgTestApplet extends javacard.framework.Applet
* - fixed various issues with measurement of methods for asymmetric crypto algorithms
* - various refactoring
*/
final static byte ALGTEST_JAVACARD_VERSION_1_7_0[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x30};
//final static byte ALGTEST_JAVACARD_VERSION_1_7_0[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x37, (byte) 0x2e, (byte) 0x30};
/**
* Version 1.6.1 (28.1.2016)
* Reset of applet moved directly into main JCAlgTestApplet
Expand Down Expand Up @@ -131,7 +140,7 @@ public class JCAlgTestApplet extends javacard.framework.Applet
*/
//final static byte ALGTEST_JAVACARD_VERSION_1_0[] = {(byte) 0x31, (byte) 0x2e, (byte) 0x30};

byte ALGTEST_JAVACARD_VERSION_CURRENT[] = ALGTEST_JAVACARD_VERSION_1_7_1;
byte ALGTEST_JAVACARD_VERSION_CURRENT[] = ALGTEST_JAVACARD_VERSION_1_7_3;

AlgKeyHarvest m_keyHarvest = null;
AlgSupportTest m_supportTest = null;
Expand Down
17 changes: 17 additions & 0 deletions AlgTest_JClient/src/algtest/JCConsts.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class JCConsts {
public static final byte Signature_SIG_CIPHER_AES_MAC128 = 6;
public static final byte Signature_SIG_CIPHER_HMAC = 7;
public static final byte Signature_SIG_CIPHER_KOREAN_SEED_MAC = 8;
// JC3.0.5
public static final byte Signature_ALG_AES_CMAC_128 = 49;


public static final byte Signature_MODE_SIGN = 1;
public static final byte Signature_MODE_VERIFY = 2;
Expand Down Expand Up @@ -153,6 +156,9 @@ public class JCConsts {
public static final byte KeyAgreement_ALG_EC_SVDP_DHC_KDF = 2;
public static final byte KeyAgreement_ALG_EC_SVDP_DH_PLAIN = 3;
public static final byte KeyAgreement_ALG_EC_SVDP_DHC_PLAIN = 4;
public static final byte KeyAgreement_ALG_EC_PACE_GM = 5;
public static final byte KeyAgreement_ALG_EC_SVDP_DH_PLAIN_XY = 6;
public static final byte KeyAgreement_ALG_DH_PLAIN = 7;

// javacard.security.KeyAgreement Methods:
public static final short KeyAgreement_getInstance = 1;
Expand Down Expand Up @@ -286,6 +292,12 @@ public class JCConsts {
public static final byte MessageDigest_LENGTH_SHA_256 = 32;
public static final byte MessageDigest_LENGTH_SHA_384 = 48;
public static final byte MessageDigest_LENGTH_SHA_512 = 64;
// JC3.0.5
public static final byte MessageDigest_ALG_SHA3_224 = 8;
public static final byte MessageDigest_ALG_SHA3_256 = 9;
public static final byte MessageDigest_ALG_SHA3_384 = 10;
public static final byte MessageDigest_ALG_SHA3_512 = 11;


// javacard.security.MessageDigest Methods:
public static final short MessageDigest_getLength = 1;
Expand All @@ -300,6 +312,11 @@ public class JCConsts {
// javacard.security.RandomData Fields:
public static final byte RandomData_ALG_PSEUDO_RANDOM = 1;
public static final byte RandomData_ALG_SECURE_RANDOM = 2;
public static final byte RandomData_ALG_TRNG = 3;
public static final byte RandomData_ALG_ALG_PRESEEDED_DRBG = 4;
public static final byte RandomData_ALG_FAST = 5;
public static final byte RandomData_ALG_KEYGENERATION = 6;


// javacard.security.RandomData Methods:
public static final short RandomData_getInstance = 1;
Expand Down
29 changes: 18 additions & 11 deletions AlgTest_JClient/src/algtestjclient/AlgTestJClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,62 +53,69 @@ public class AlgTestJClient {
public static final String ALGTEST_SINGLEPERAPDU = "AT_SINGLEPERAPDU"; // for 'New' AlgTest
public static final String ALGTEST_PERFORMANCE = "AT_PERFORMANCE"; // for performance testing

/**
* Version 1.7.3 (10.06.2017)
* + added new constants from JC3.0.5
* - fixed bug with incorrect testing of KeyAgreement
*/
public final static String ALGTEST_JCLIENT_VERSION_1_7_3 = "1.7.3";

/**
* Version 1.7.2 (06.05.2017)
* + support for RSA key generation and export within given range
* + minor improvements of interface
*/
public final static String ALGTEST_JCLIENT_VERSION_1_7_2 = "1.7.2";
//public final static String ALGTEST_JCLIENT_VERSION_1_7_2 = "1.7.2";

/**
* Version 1.7.1 (03.10.2016)
* + support for reader access via JNA
*/
public final static String ALGTEST_JCLIENT_VERSION_1_7_1 = "1.7.1";
//public final static String ALGTEST_JCLIENT_VERSION_1_7_1 = "1.7.1";
/**
* Version 1.7.0 (19.09.2016) + Updates to support EC and asym. key
* operations properly
*/
public final static String ALGTEST_JCLIENT_VERSION_1_7_0 = "1.7.0";
//public final static String ALGTEST_JCLIENT_VERSION_1_7_0 = "1.7.0";
/**
* Version 1.6.0 (19.07.2015)
* + Many updates, performance tests
*/
public final static String ALGTEST_JCLIENT_VERSION_1_6_0 = "1.6.0";
//public final static String ALGTEST_JCLIENT_VERSION_1_6_0 = "1.6.0";

/**
* Version 1.3 (30.11.2014)
* + Improved gathering of data, single command per single algorithm instance possible
*/
public final static String ALGTEST_JCLIENT_VERSION_1_3_0 = "1.3.0";
//public final static String ALGTEST_JCLIENT_VERSION_1_3_0 = "1.3.0";
/**
* Version 1.2.1 (29.1.2014)
* + added support for TYPE_RSA_PRIVATE_TRANSIENT_RESET and TYPE_RSA_PRIVATE_TRANSIENT_DESELECT parsing
* + added possibility to run test for every class separately
* - more information for user, small refactoring
*/
public final static String ALGTEST_JCLIENT_VERSION_1_2_1 = "1.2.1";
//public final static String ALGTEST_JCLIENT_VERSION_1_2_1 = "1.2.1";
/**
* Version 1.2 (3.11.2013)
* + All relevant constants from JC2.2.2, JC3.0.1 and JC3.0.4 added
*/
public final static String ALGTEST_JCLIENT_VERSION_1_2 = "1.2";
//public final static String ALGTEST_JCLIENT_VERSION_1_2 = "1.2";
/**
* Version 1.1 (28.6.2013)
* + information about version added
* + link to project added into resulting file
*/
public final static String ALGTEST_JCLIENT_VERSION_1_1 = "1.1";
//public final static String ALGTEST_JCLIENT_VERSION_1_1 = "1.1";
/**
* Version 1.0 (27.11.2012)
* + initial version of AlgTestJClient, clone of AlgTestCppClient
*/
public final static String ALGTEST_JCLIENT_VERSION_1_0 = "1.0";
//public final static String ALGTEST_JCLIENT_VERSION_1_0 = "1.0";

/**
* Current version
*/
public final static String ALGTEST_JCLIENT_VERSION = ALGTEST_JCLIENT_VERSION_1_7_2;
public final static String ALGTEST_JCLIENT_VERSION = ALGTEST_JCLIENT_VERSION_1_7_3;

public final static int STAT_OK = 0;
/**
Expand All @@ -123,7 +130,7 @@ public static void main(String[] args) throws IOException, Exception {

m_SystemOutLogger.println("\n----------------------------------------------------------------------- ");
m_SystemOutLogger.println("JCAlgTest " + ALGTEST_JCLIENT_VERSION + " - comprehensive tool for JavaCard smart card testing.");
m_SystemOutLogger.println("Visit jcalgtest.org for results from 60+ cards. CRoCS.cz lab 2007-2016.");
m_SystemOutLogger.println("Visit jcalgtest.org for results from 60+ cards. CRoCS lab 2007-2017.");
m_SystemOutLogger.println("Please check if you use the latest version at\n https://github.com/crocs-muni/JCAlgTest/releases/latest.");

m_SystemOutLogger.println("-----------------------------------------------------------------------\n");
Expand Down
52 changes: 39 additions & 13 deletions AlgTest_JClient/src/algtestjclient/SingleModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ may be distributed under the terms of the GNU General Public License (GPL),

/* Import 'ALGTEST_JCLIENT_VERSION' variable - possibly replace with actual import of those variables later? */
import AlgTest.Consts;
import AlgTest.JCConsts;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -105,8 +106,12 @@ public class SingleModeTest {
"ALG_RSA_SHA_224_PKCS1#3.0.1", "ALG_RSA_SHA_256_PKCS1#3.0.1", "ALG_RSA_SHA_384_PKCS1#3.0.1", "ALG_RSA_SHA_512_PKCS1#3.0.1",
"ALG_RSA_SHA_224_PKCS1_PSS#3.0.1", "ALG_RSA_SHA_256_PKCS1_PSS#3.0.1", "ALG_RSA_SHA_384_PKCS1_PSS#3.0.1", "ALG_RSA_SHA_512_PKCS1_PSS#3.0.1",
//3.0.4
"ALG_DES_MAC4_ISO9797_1_M1_ALG3#3.0.4", "ALG_DES_MAC8_ISO9797_1_M1_ALG3#3.0.4"
"ALG_DES_MAC4_ISO9797_1_M1_ALG3#3.0.4", "ALG_DES_MAC8_ISO9797_1_M1_ALG3#3.0.4",
//3.0.5
"ALG_AES_CMAC_128#3.0.5"
};
public static final int SIGNATURE_STR_LAST_INDEX = JCConsts.Signature_ALG_AES_CMAC_128;


public static final String CIPHER_STR[] = {"javacardx.crypto.Cipher",
"ALG_DES_CBC_NOPAD#≤2.1", "ALG_DES_CBC_ISO9797_M1#≤2.1", "ALG_DES_CBC_ISO9797_M2#≤2.1", "ALG_DES_CBC_PKCS5#≤2.1",
Expand All @@ -122,13 +127,19 @@ public class SingleModeTest {
"ALG_AES_BLOCK_192_CBC_NOPAD#3.0.1", "ALG_AES_BLOCK_192_ECB_NOPAD#3.0.1", "ALG_AES_BLOCK_256_CBC_NOPAD#3.0.1", "ALG_AES_BLOCK_256_ECB_NOPAD#3.0.1",
"ALG_AES_CBC_ISO9797_M1#3.0.1", "ALG_AES_CBC_ISO9797_M2#3.0.1", "ALG_AES_CBC_PKCS5#3.0.1", "ALG_AES_ECB_ISO9797_M1#3.0.1", "ALG_AES_ECB_ISO9797_M2#3.0.1", "ALG_AES_ECB_PKCS5#3.0.1"
};
public static final int CIPHER_STR_LAST_INDEX = JCConsts.Cipher_ALG_AES_ECB_PKCS5;


public static final String KEYAGREEMENT_STR[] = {"javacard.security.KeyAgreement",
//2.2.1
"ALG_EC_SVDP_DH#2.2.1", "ALG_EC_SVDP_DHC#2.2.1",
"ALG_EC_SVDP_DH/ALG_EC_SVDP_DH_KDF#2.2.1", "ALG_EC_SVDP_DHC/ALG_EC_SVDP_DHC_KDF#2.2.1",
//3.0.1
"ALG_EC_SVDP_DH_KDF#3.0.1", "ALG_EC_SVDP_DH_PLAIN#3.0.1", "ALG_EC_SVDP_DHC_KDF#3.0.1", "ALG_EC_SVDP_DHC_PLAIN#3.0.1"
//was incorrectly like this: "ALG_EC_SVDP_DH_KDF#3.0.1", "ALG_EC_SVDP_DH_PLAIN#3.0.1", "ALG_EC_SVDP_DHC_KDF#3.0.1", "ALG_EC_SVDP_DHC_PLAIN#3.0.1",
"ALG_EC_SVDP_DH_PLAIN#3.0.1", "ALG_EC_SVDP_DHC_PLAIN#3.0.1",
//3.0.5
"ALG_EC_PACE_GM#3.0.5", "ALG_EC_SVDP_DH_PLAIN_XY#3.0.5", "ALG_DH_PLAIN#3.0.5"
};
public static final int KEYAGREEMENT_STR_LAST_INDEX = JCConsts.KeyAgreement_ALG_DH_PLAIN;
/*
public static final String KEYBUILDER_STR[] = {
"javacard.security.KeyBuilder",
Expand Down Expand Up @@ -204,13 +215,22 @@ public class SingleModeTest {
//2.2.2
"ALG_SHA_256#2.2.2", "ALG_SHA_384#2.2.2", "ALG_SHA_512#2.2.2",
//3.0.1
"ALG_SHA_224#3.0.1"
"ALG_SHA_224#3.0.1",
//3.0.5
"ALG_SHA3_224#3.0.5", "ALG_SHA3_256#3.0.5", "ALG_SHA3_384#3.0.5", "ALG_SHA3_512#3.0.5"
};

public static final int MESSAGEDIGEST_STR_LAST_INDEX = JCConsts.MessageDigest_ALG_SHA3_512;

public static final String RANDOMDATA_STR[] = {"javacard.security.RandomData",
"ALG_PSEUDO_RANDOM#≤2.1", "ALG_SECURE_RANDOM#≤2.1"};

"ALG_PSEUDO_RANDOM#≤2.1", "ALG_SECURE_RANDOM#≤2.1",
//3.0.5
"ALG_TRNG#3.0.5", "ALG_ALG_PRESEEDED_DRBG#3.0.5", "ALG_FAST#3.0.5", "ALG_KEYGENERATION#3.0.5"
};
public static final int RANDOMDATA_STR_LAST_INDEX = JCConsts.RandomData_ALG_KEYGENERATION;

public static final String CHECKSUM_STR[] = {"javacard.security.Checksum", "ALG_ISO3309_CRC16#2.2.1", "ALG_ISO3309_CRC32#2.2.1"};
public static final int CHECKSUM_STR_LAST_INDEX = JCConsts.Checksum_ALG_ISO3309_CRC32;


public static final String JCSYSTEM_STR[] = {"javacard.framework.JCSystem", "JCSystem.getVersion()[Major.Minor]#≤2.1",
"JCSystem.isObjectDeletionSupported#2.2.0", "JCSystem.MEMORY_TYPE_PERSISTENT#2.2.1", "JCSystem.MEMORY_TYPE_TRANSIENT_RESET#2.2.1",
Expand Down Expand Up @@ -678,6 +698,7 @@ public static void TestClassCipher(FileOutputStream file) throws Exception{
m_SystemOutLogger.println(message);
file.write(message.getBytes());

assert (CIPHER_STR_LAST_INDEX == (CIPHER_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i=1; i< SingleModeTest.CIPHER_STR.length; i++){ // i = 1 because Cipher[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
Expand Down Expand Up @@ -717,11 +738,12 @@ public static void TestClassSignature (FileOutputStream file) throws IOException
m_SystemOutLogger.println(message);
file.write(message.getBytes());

assert (SIGNATURE_STR_LAST_INDEX == (SIGNATURE_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i=1; i<SingleModeTest.SIGNATURE_STR.length; i++){ // i = 1 because Signature[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
// get starting time of communication cycle
apdu[OFFSET_DATA] = (byte)i;
apdu[OFFSET_DATA] = (byte) i;
elapsedCard = -System.currentTimeMillis();
ResponseAPDU response = cardManager.sendAPDU(apdu);
// save time of card response
Expand Down Expand Up @@ -754,6 +776,7 @@ public static void TestClassMessageDigest (FileOutputStream file) throws IOExcep
m_SystemOutLogger.println(message);
file.write(message.getBytes());

assert (MESSAGEDIGEST_STR_LAST_INDEX == (MESSAGEDIGEST_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i=1; i<SingleModeTest.MESSAGEDIGEST_STR.length; i++){ // i = 1 because MessageDigest[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
Expand All @@ -776,7 +799,7 @@ public static void TestClassMessageDigest (FileOutputStream file) throws IOExcep
* @throws IOException
* @throws Exception
*/
public static void TestClassRandomData (FileOutputStream file) throws IOException, Exception{
public static void TestClassRandomData(FileOutputStream file) throws IOException, Exception{
long elapsedCard = 0;
byte[] apdu = new byte[6];
apdu[OFFSET_CLA] = Consts.CLA_CARD_ALGTEST; // for AlgTest applet
Expand All @@ -790,6 +813,7 @@ public static void TestClassRandomData (FileOutputStream file) throws IOExceptio
m_SystemOutLogger.println(message);
file.write(message.getBytes());

assert (RANDOMDATA_STR_LAST_INDEX == (SingleModeTest.RANDOMDATA_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i=1; i<SingleModeTest.RANDOMDATA_STR.length; i++){ // i = 1 because RandomData[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
Expand Down Expand Up @@ -861,15 +885,16 @@ public static void TestClassKeyAgreement (FileOutputStream file) throws IOExcept
apdu[OFFSET_P2] = (byte)0x00;
apdu[OFFSET_LC] = (byte)0x01;

/* Creates message with class name and writes it in the output file and on the screen. */
// Creates message with class name and writes it in the output file and on the screen.
String message = "\n" + cardManager.GetAlgorithmName(SingleModeTest.KEYAGREEMENT_STR[0]) + "\r\n";
m_SystemOutLogger.println(message);
file.write(message.getBytes());

for (int i=1; i<SingleModeTest.KEYAGREEMENT_STR.length; i++){ // i = 1 because KeyAgreement[0] is class name
assert (KEYAGREEMENT_STR_LAST_INDEX == (SingleModeTest.KEYAGREEMENT_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i = 1; i<SingleModeTest.KEYAGREEMENT_STR.length; i++){ // i = 1 because KeyAgreement[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
apdu[OFFSET_DATA] = (byte)i;
apdu[OFFSET_DATA] = (byte) i;
// get starting time of communication cycle
elapsedCard = -System.currentTimeMillis();
ResponseAPDU response = cardManager.sendAPDU(apdu);
Expand Down Expand Up @@ -902,7 +927,8 @@ public static void TestClassChecksum (FileOutputStream file) throws IOException,
m_SystemOutLogger.println(message);
file.write(message.getBytes());

for (int i=1; i<SingleModeTest.CHECKSUM_STR.length; i++){ // i = 1 because Checksum[0] is class name
assert (CHECKSUM_STR_LAST_INDEX == (CHECKSUM_STR.length - 1)); // Sanity check as we will construct constant value based on position inside string
for (int i=1; i< CHECKSUM_STR.length; i++){ // i = 1 because Checksum[0] is class name
// Reset applet before call
cardManager.sendAPDU(RESET_APDU);
apdu[OFFSET_DATA] = (byte) i;
Expand Down
Binary file added AlgTest_JavaCard/AlgTest_v1.7.3_jc222.cap
Binary file not shown.
2 changes: 1 addition & 1 deletion AlgTest_JavaCard/src/AlgTest/AlgSupportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void TestSupportedModeSingle(APDU apdu) {
break;
}
case (byte) 0x13: {
try {offset++;m_object = KeyAgreement.getInstance(ALG_EC_SVDP_DH, false); apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = SUPP_ALG_SUPPORTED;}
try {offset++;m_object = KeyAgreement.getInstance(algorithmClass, false); apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = SUPP_ALG_SUPPORTED;}
catch (CryptoException e) { apdubuf[(short) (ISO7816.OFFSET_CDATA + offset)] = (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) ? (byte) 0 : (byte) 2; }
break;
}
Expand Down
Loading

0 comments on commit 8fafb50

Please sign in to comment.