[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r1638 - trunk/hsmbully/src

Rick van Rein rick at openfortress.nl
Sun Aug 16 23:17:35 CEST 2009


Author: vanrein
Date: 2009-08-16 23:17:35 +0200 (Sun, 16 Aug 2009)
New Revision: 1638

Modified:
   trunk/hsmbully/src/Makefile.am
   trunk/hsmbully/src/TODO
   trunk/hsmbully/src/hsmbully.1
   trunk/hsmbully/src/hsmbully.c
Log:
Many cmdline options added to hsmbully


Modified: trunk/hsmbully/src/Makefile.am
===================================================================
--- trunk/hsmbully/src/Makefile.am	2009-08-16 13:37:34 UTC (rev 1637)
+++ trunk/hsmbully/src/Makefile.am	2009-08-16 21:17:35 UTC (rev 1638)
@@ -11,4 +11,6 @@
 
 hsmbully_LDADD = @CUNIT_LIBS@ -lm
 
+man_MANS = hsmbully.1
+
 EXTRA_DIST = $(srcdir)/cryptoki/*.h

Modified: trunk/hsmbully/src/TODO
===================================================================
--- trunk/hsmbully/src/TODO	2009-08-16 13:37:34 UTC (rev 1637)
+++ trunk/hsmbully/src/TODO	2009-08-16 21:17:35 UTC (rev 1638)
@@ -1,4 +1,10 @@
-- Only the used CKM_xxx are employed in this test.
+- Only the used CKM_xxx should be employed in this test.
 - There is no testing of C_SignUpdate or C_VerifyUpdate
 + We de not test concurrent PKCS #11 access because we cannot exhaust that
-- Incorporate commandline-processing from cunit-stephen
++ Incorporate commandline options --pin --so-pin --pkcs11lib for normal testing
++ Incorporate commandline option --destructive to destroy previous HSM content
++ Incorporate commandline option --fast-and-frivolous for quick 'n' dirty tests
+X Incorporate commandline option --max-keypairs for unlimited/large key memory
++ Incorporate commandline options --skip-testname
+- Incorporate commandline option --token or so for token identification
+- Incorporate commandline options from cunit-stephen

Modified: trunk/hsmbully/src/hsmbully.1
===================================================================
--- trunk/hsmbully/src/hsmbully.1	2009-08-16 13:37:34 UTC (rev 1637)
+++ trunk/hsmbully/src/hsmbully.1	2009-08-16 21:17:35 UTC (rev 1638)
@@ -1,4 +1,4 @@
-.TH HSMBULLY 1 "$Revision:$"
+.TH HSMBULLY 1 "$Revision$"
 .SH NAME
 hsmbully \- Test a PKCS #11 token for OpenDNSSEC suitability
 .SH SYNOPSIS
@@ -7,10 +7,11 @@
 .SH DESCRIPTION
 .PP
 The hsmbully tool is designed to verify if a token, HSM or other PKCS #11
-implementation suffices to support OpenDNSSEC.  As it is intended to avoid
-setting up OpenDNSSEC fully on the token, it cannot give absolute certainty
-that a token will suffice, but in most cases it can give an early warning
-if the token will give problems when running fullblown OpenDNSSEC.
+implementation suffices to support OpenDNSSEC.  It is intended to allow a
+test before setting up full-blown OpenDNSSEC on the token, but as a
+result of that it cannot give 100% certainty that a token will suffice.
+In most cases however, it can give ample warning if the token would give
+problems when running fullblown OpenDNSSEC.
 .PP
 There are two modes of operation for hsmbully; one is destructive, meaning
 that all the contents on the token will be wiped, and the token will be
@@ -27,60 +28,127 @@
 objects created on the token for tests will be removed after successful
 termination of hsmbully.
 .PP
+The tests performed by hsmbully are deterministic.  That is, a second run with
+the same parameters and on the same initial token state should run in exactly
+the same way.  This is ensured by an internal "random" number generator that
+is reset with a given seed.
+.PP
 The current version of hsmbully assumes to find only a single slot with a
 token in it.  If not, it will bail out and complain that it does not know
 what token to bully.
 .SH OPTIONS
 .PP
 Several options to hsmbully are required options.  You must always specify
-\fB\-\-pin\fR, \fB\-\-so\-pin\fR and \fB\-\-pkcs11lib\R.
+\fB\-\-pin\fR, \fB\-\-so\-pin\fR and \fB\-\-pkcs11lib\fR.  It is likely
+that you will initially want to specify \fB\-\-fast\-and\-frivolous\fR and
+\fB\-\-verbose=4\fR as well.
 .TP
+\fB\-\-help\fR
+A quick and incomplete reference to the hsmbully commandline options.
+.TP
+\fB\-\-verbose\fR, \fB\-v\fR, \fB\-\-verbose=NUM\fR
+Increase or set the verbosity level.  Default level is 1, which reports only
+major steps of the program.  Level 0 is quiet, and higher levels may yield
+more detailed output.
+.TP
 \fB\-\-destructive\fR
 destroy all contents on the token.  This means that the \fB\-\-pin\fR and
 \fB\-\-so\-pin\fR options are interpreted as values to set, rather than as
 values to use for login.  There is no single-character option alias for
 this long option.
 .TP
-\fB\-\-pin=PIN\fR, \fB-p PIN\fR
+\fB\-\-pin=PIN\fR, \fB\-p PIN\fR
 specifies the user PIN to be used by hsmbully.  If \fB\-\-destructive\fR
 is also specified, this PIN is set rather than just used to login.  In
 that case, the PIN will remain on the token even after all other objects
 are removed.
 .TP
-\fB\-\-so\-pin=PIN\fR, \fB-s PIN\fR
+\fB\-\-so\-pin=PIN\fR, \fB\-P PIN\fR
 specifies the security officer PIN, also known as the SO-PIN, to be used
 by hsmbully.  If \fB\-\-destructive\fR is also specified, this PIN is set
 rather than just used to login.  In that case, the PIN will remain on the
 token even after all other objects are removed.
 .TP
-\fB\-\-pkcs11lib=PIN\fR, \fB-l /path/to/lib.so\fR
+\fB\-\-pkcs11lib=PIN\fR, \fB\-l /path/to/lib.so\fR
 specifies the PKCS #11 library to use.  This must be a shared library that
 adheres to the PKCS #11 specifications from RSA Laboratories.  It will be
 addressed as a dynamic library.
+.TP
+\fB\-\-fast\-and\-frivolous\fR, \fB\-\-frivolous\fR, \fB\-f\fR
+The fullblown tests performed by hsmbully are quite extensive.  This may
+not be ideal during some preliminary work.  This option replaces the normal
+fullblown testing with far fewer loop-arounds.  Note that the outcome of
+hsmbully is generated faster, but it is less likely to find potential problems
+in the token under test.
+.TP
+\fB\-\-skip\-initiation\fR
+Skip the Initiation Test, as described under
+.SM
+.B "TESTS PERFORMED"
+below.  This may be useful if a token is known broken in this area, but
+still thought to be serious material for OpenDNSSEC.  Be very sure what
+you are doing though, you may be leaking keys before you know it.
+.TP
+\fB\-\-skip\-fragmentation\fR
+Skip the Fragmentation Test, as described under
+.SM
+.B "TESTS PERFORMED"
+below.  This may be useful for very large tokens, or soft tokens that have
+a virtually unconstrained memory space available.  Fragmentation testing
+may take unpractically long on such tokens, and may be skipped if sufficient
+trust in non-fragmentation may be assumed.
+.TP
+\fB\-\-skip\-keysizing\fR
+Skip the Key Sizing Test, as described under
+.SM
+.B "TESTS PERFORMED"
+below.  This may help to overcome problems with tokens that lie about the
+key sizes they can handle; for example, a token that can handle keys with
+1024 or 2048 bits, but nothing in between.  Be sure to manually configure
+OpenDNSSEC to key sizes usable for this token.
+.TP
+\fB\-\-skip\-signing\fR
+Skip the Signing Test, as described under
+.SM
+.B "TESTS PERFORMED"
+below.  This is not usually a shocking test to skip, as it tests a feature
+that is so common that it usually tested thoroughly by both token manufacturer
+and their (other) customers.
+.SM
+.B "TESTS PERFORMED"
+below.  If all four tests are skipped, hsmbully will not test anything. 
+.\" .TP
+.\" \fB\-\-max\-keypairs=NUM\fR, \fB\-\-max\-keys=NUM\fR, \fB\-m NUM\fR
+.\" For tokens with very large, or even unconstrained space for key storage, the
+.\" fragmentation test may have to be skipped.  This option indicates the maximum
+.\" number of key pairs to generate, and it will trigger an error if this maximum
+.\" is reached before running out of memory during this test.
 .\" TODO: --token
-.\" TODO: --quick
 .\" TODO: --interactive/CUnit
 .SH "TESTS PERFORMED"
 The following tests are performed as part of a run of hsmbully:
 .TP
 \fBInitiation test\fR
-This tests if the HSM properly handles all sorts of orders of opening and
+This tests if the token properly handles all sorts of orders of opening and
 closing access to the resources on the token.  The sequences tested
 deliberately include invalid accesses, such as not logging on and seeing
 if a previous sesssion's login is reused.  If the token sustains this test,
 it appears to be a proper implementation of those aspects of PKCS #11.
+.TP
 \fBFragmentation test\fR
 This tests if memory can sustain a long list of creations and deletions of
 keys, without ending up with fragmented memory.  This test starts by filling
 up all free space in the token with keys of various sizes, and then removes
 arbitrary ones and expects to be able to recreate a new one of the same size
 immediately after that.
+.TP
 \fBKey sizing test\fR
 This tests if the key sizes supported by the token are within reasonable
 constraints, if they match the algorithms used by OpenDNSSEC and if the
 claimed key size range is covered as PKCS #11 prescribes.  The test is done
 by creating key pairs and verifying the size of the modulus of the public
 key.
+.TP
 \fBSigning test\fR
 This tests if the signatures are made properly.  Signatures are constructed
 at a variety of key sizes within the supported range.

Modified: trunk/hsmbully/src/hsmbully.c
===================================================================
--- trunk/hsmbully/src/hsmbully.c	2009-08-16 13:37:34 UTC (rev 1637)
+++ trunk/hsmbully/src/hsmbully.c	2009-08-16 21:17:35 UTC (rev 1638)
@@ -41,17 +41,7 @@
 #endif
 
 
-#ifdef QUICK_N_DIRTY
-#  define THOUSANDS 10
-#  define HUNDRED   8
-#  define COUPLE    3
-#else
-#  define THOUSANDS 2500
-#  define HUNDRED   100
-#  define COUPLE    10
-#endif
 
-
 /* =============================================================== */
 
 
@@ -129,7 +119,7 @@
 #define GETRV(x) { ck_rv = (x); }
 #define TESTRV(s,x) { ck_rv = (x); if (ck_rv!=CKR_OK) { fprintf (stderr, "%s: Error %08x in retval\n", s, ck_rv); } }
 // #define TESTRV(s,x) { static char cumsgbuf [1025]; if (ck_rv==CKR_OK) { ck_rv = (x); fprintf (stderr, "Return value %08lx at %s:%d\n", ck_rv, __FILE__, __LINE__); } if (ck_rv==CKR_OK) { printf ("Pass: %s\n", (s)); } else { snprintf (cumsgbuf, sizeof (cumsgbuf)-1, "Return value %08lx is not CKR_OK: %s", ck_rv, (s)); cumsgbuf [sizeof (cumsgbuf)-1] = '\0'; fprintf (stderr, "Fail: %s\n", cumsgbuf); } }
-#define MKFATAL() { if (ck_rv != CKR_OK) exit (1); }
+#define MKFATAL() { if (ck_rv != CKR_OK) { fprintf (stderr, "Fatal error in %s:%d\n", __FILE__, __LINE__); exit (1); } }
 #define LASTRVOK() (ck_rv==CKR_OK)
 
 
@@ -153,7 +143,24 @@
 /* Whether this tool should destroy all data on the HSM or not */
 static int destructive = 0;
 
+/* Repeating counters, which can be overridden for quicker testing */
+static int thousands = 2500;
+static int hundred = 100;
+static int couple = 10;
 
+/* How many key pairs to generate maximally?  0 means infinite */
+static int max_keypairs = 0;
+
+/* What verbosity level has been requested?  Start is 1 */
+static int verbosity = 1;
+
+/* Should certain tests be skipped altogether? */
+static int skip_initiation = 0;
+static int skip_fragmentation = 0;
+static int skip_keysizing = 0;
+static int skip_signing = 0;
+
+
 /* =============================================================== */
 
 
@@ -225,6 +232,9 @@
 		{ CKA_UNWRAP, &false, sizeof (false) },
 		{ CKA_DERIVE, &false, sizeof (false) },
 	};
+	if (verbosity >= 3) {
+		printf ("   - Creating key pair with %d bit modulus\n", keybits);
+	}
 	return P11("C_GenerateKeyPair") (
 			seshdl,
 			&mech,
@@ -245,6 +255,11 @@
 	CK_BYTE noappinfo;
 	int initestctr;
 
+	/* Announce the start of this test */
+	if (verbosity >= 1) {
+		printf ("Entering initiation test\n");
+	}
+
 	/* Complain if user PIN and SO PIN are the same -- this will bring
 	 * out more subtlety in the tests to follow.
 	 */
@@ -283,7 +298,7 @@
 	/*
 	 * Iterate over the actual test, running (distorted) scripts.
 	 */
-	for (initestctr=0; initestctr < THOUSANDS; initestctr++) {
+	for (initestctr=0; initestctr < thousands; initestctr++) {
 		/*
   		 * Choices to be made at randomish:
   		 * choice_session==0           =>  fail to open session
@@ -295,6 +310,10 @@
 		int choice_rw      = randomish (2);
 		int choice_user    = randomish (2);
 
+		if (verbosity >= 4) {
+			printf ("%8d\b\b\b\b\b\b\b\b", thousands-initestctr);
+		}
+
 		/*
 		 *  Open session with slot (with 10% chance of failure).
 		 */
@@ -316,7 +335,11 @@
 					(CK_UTF8CHAR_PTR) (choice_user? ascii_pin_user: ascii_pin_so),
 					choice_user? strlen (ascii_pin_user): strlen (ascii_pin_so)));
 			if (choice_session) {
-				MKFATAL ();
+				if (LASTRVOK ()) {
+					CU_PASS ("Properly granted login on an open session");
+				} else {
+					CU_FAIL ("Incorrectly failed to login on an open session");
+				}
 			} else {
 				if (LASTRVOK ()) {
 					CU_FAIL ("Incorrectly allowed login on a non-existing session");
@@ -447,6 +470,9 @@
 	/*
 	 * End of initiation test, comprising of thousands of tests.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Token state returned to normal\n");
+	}
 }
 
 
@@ -472,6 +498,11 @@
 	int testctr;
 	CK_RV retval;
 
+	/* Announce the start of this test */
+	if (verbosity >= 1) {
+		printf ("Entering fragmentation test\n");
+	}
+
 	/*
 	 *  Open RW session with slot
 	 */
@@ -499,6 +530,9 @@
 	 * Fetch supported key sizes for this token.  Count in bytes, not
 	 * bits, to simplify later randomisation of key sizes.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Determine key sizes\n");
+	}
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMinKeySize % 8, 0);
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMaxKeySize % 8, 0);
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMinKeySize <= mech_sha1_rsa_pkcs.ulMaxKeySize);
@@ -506,24 +540,28 @@
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMaxKeySize >= 2048);
 	minbytes = mech_sha1_rsa_pkcs.ulMinKeySize / 8;
 	maxbytes = mech_sha1_rsa_pkcs.ulMaxKeySize / 8;
+	if (verbosity >= 3) {
+		printf ("   - Key sizes supported by this token range from %d to %d bits\n", minbytes * 8, maxbytes * 8);
+	}
 
 	/*
 	 * Fill the token with key pairs.  Loop until memory runs out, and
 	 * there's no more chances for filling up any further by lowering
 	 * the maximum key size.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Filling the token with key pairs\n");
+	}
 	retval = CKR_OK;
 	while ( retval == CKR_OK ) {
 		CK_ULONG keybits;
 
-#ifdef QUICK_N_DIRTY
-#ifdef MAX_KEYS_GEN
-		if (keypairs == MAX_KEYS_GEN) {
-			CU_FAIL ("Hit preset MAX_KEYS_GEN upper limit before the device's memory was full");
-			break;
+		if (max_keypairs > 0) {
+			if (keypairs == max_keypairs) {
+				CU_FAIL ("Hit maximum number of key pairs to generate before the device's memory was full");
+				break;
+			}
 		}
-#endif
-#endif
 
 		keybits = 8 * randomish_minmax (minbytes, maxbytes);
 		keys = realloc (keys, sizeof (keys [0]) * (keypairs+1));
@@ -557,8 +595,17 @@
 	 * If memory does not fragment, this should always succeed.
 	 * Repeat this test thousands of times (say, 2500x).
 	 */
-	for (testctr = 0; testctr < THOUSANDS; testctr++) {
+	if (verbosity >= 2) {
+		printf (" * Randomly replace key pairs with ones of the same size\n");
+	}
+	for (testctr = 0; testctr < thousands; testctr++) {
 		int victim = randomish (keypairs);
+		if (verbosity >= 3) {
+			printf ("   - Removing a %d bit key pair, expecting to free the memory for a new one\n", keys [victim].modbits);
+			if (verbosity >= 4) {
+				printf ("%8d\b\b\b\b\b\b\b\b", thousands-testctr);
+			}
+		}
 		TESTRV ("Removing a private key for fragmentation testing",
 			 P11("C_DestroyObject") (seshdl, keys [victim].priv));
 		TESTRV ("Removing a public key for fragmentation testing",
@@ -575,6 +622,9 @@
 	/*
 	 * Cleanup: Destroy all key pairs, logout, close session.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Cleanup the key pairs on the token\n");
+	}
 	for (kp=0; kp<keypairs; kp++) {
 		TESTRV ("Removing a private key after fragmentation test",
 			 P11("C_DestroyObject") (seshdl, keys [kp].priv));
@@ -607,10 +657,15 @@
 
 	CK_RV retval;
 
+	/* Announce the start of this test */
+	if (verbosity >= 1) {
+		printf ("Entering keysizing test\n");
+	}
+
 	/*
 	 *  Open RW session with slot
 	 */
-	TESTRV ("Opening session for fragmentation test",
+	TESTRV ("Opening session for keysizing test",
 		P11("C_OpenSession") (slotid, CKF_SERIAL_SESSION | CKF_RW_SESSION,
 				(void *) &noappinfo, NULL_PTR, &seshdl));
 	MKFATAL ();
@@ -634,6 +689,9 @@
 	 * Fetch supported key sizes for this token.  Count in bytes, not
 	 * bits, to simplify later randomisation of key sizes.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Determine key sizes\n");
+	}
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMinKeySize % 8, 0);
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMaxKeySize % 8, 0);
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMinKeySize <= mech_sha1_rsa_pkcs.ulMaxKeySize);
@@ -641,10 +699,16 @@
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMaxKeySize >= 2048);
 	minbytes = mech_sha1_rsa_pkcs.ulMinKeySize / 8;
 	maxbytes = mech_sha1_rsa_pkcs.ulMaxKeySize / 8;
+	if (verbosity >= 3) {
+		printf ("   - Key sizes supported by this token range from %d to %d bits\n", minbytes * 8, maxbytes * 8);
+	}
 
 	/*
 	 * Iterate over key pair lengths, checking the modulus size of each.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Check modulus size of each possible key pair length\n");
+	}
 	curbytes = minbytes;
 	while (curbytes <= maxbytes) {
 		int ok = 1;
@@ -654,6 +718,9 @@
 			{ CKA_MODULUS, NULL_PTR, 0 },
 		};
 		uint8_t *modulus;
+		if (verbosity >= 4) {
+			printf ("%8d\b\b\b\b\b\b\b\b", maxbytes-curbytes);
+		}
 		retval = newkeypair (seshdl, modbits, &pub, &priv);
 		TESTRV ("Creating key pair in modulus size test", retval);
 		ok = ok && (retval == CKR_OK);
@@ -698,11 +765,13 @@
 	/*
 	 * Cleanup.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Cleaning up token state\n");
+	}
 	TESTRV ("Logging out after modulus size test",
 		 P11("C_Logout") (seshdl));
 	TESTRV ("Closing session after modulus size test",
 		 P11("C_CloseSession") (seshdl));
-
 }
 
 
@@ -720,6 +789,11 @@
 
 	int keytestctr, sigtestctr;
 
+	/* Announce the start of this test */
+	if (verbosity >= 1) {
+		printf ("Entering signing test\n");
+	}
+
 	/*
 	 *  Open RW session with slot
 	 */
@@ -747,6 +821,9 @@
 	 * Fetch supported key sizes for this token.  Count in bytes, not
 	 * bits, to simplify later randomisation of key sizes.
 	 */
+	if (verbosity >= 2) {
+		printf (" * Determine key sizes\n");
+	}
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMinKeySize % 8, 0);
 	CU_ASSERT_EQUAL (mech_sha1_rsa_pkcs.ulMaxKeySize % 8, 0);
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMinKeySize <= mech_sha1_rsa_pkcs.ulMaxKeySize);
@@ -754,12 +831,18 @@
 	CU_ASSERT (mech_sha1_rsa_pkcs.ulMaxKeySize >= 2048);
 	minbytes = mech_sha1_rsa_pkcs.ulMinKeySize / 8;
 	maxbytes = mech_sha1_rsa_pkcs.ulMaxKeySize / 8;
+	if (verbosity >= 3) {
+		printf ("   - Key sizes supported by this token range from %d to %d bits\n", minbytes * 8, maxbytes * 8);
+	}
 
 	/*
 	 * Iterate over keys a couple of times, creating a new key pair for
 	 * each iteration.
 	 */
-	for (keytestctr = 0; keytestctr < COUPLE; keytestctr++) {
+	for (keytestctr = 0; keytestctr < couple; keytestctr++) {
+		if (verbosity >= 2) {
+			printf (" * Key test iteration %d\n", keytestctr);
+		}
 
 		int modbits = 8 * randomish_minmax (minbytes, maxbytes);
 		CK_OBJECT_HANDLE pub, priv;
@@ -774,11 +857,14 @@
 		/* Iterate over signatures about a hundred times.  Create
 		 * a signature and verify it.
 		 */
-		for (sigtestctr = 0; sigtestctr < HUNDRED; sigtestctr++) {
+		for (sigtestctr = 0; sigtestctr < hundred; sigtestctr++) {
 			CK_BYTE data [] = "tralala-en-hopsasa";
 			CK_BYTE *sig = malloc (maxbytes);
 			CK_ULONG siglen;
 			CK_MECHANISM mech = { CKM_SHA1_RSA_PKCS, NULL_PTR, 0 };
+			if (verbosity >= 4) {
+				printf ("%3d / %8d\b\b\b\b\b\b\b\b\b\b\b\b\b\b", couple - keytestctr, hundred - sigtestctr);
+			}
 			if (sig == NULL) {
 				CU_FAIL ("Out of memory allocating for signature test");
 				break;
@@ -816,6 +902,9 @@
 	/*
 	 * Cleanup.
 	 */
+	if (verbosity >= 2) {
+		printf ("Cleaning up token state\n");
+	}
 	TESTRV ("Logging out after modulus size test",
 		 P11("C_Logout") (seshdl));
 	TESTRV ("Closing session after modulus size test",
@@ -843,6 +932,9 @@
  */
 void inittoken (void) {
 	if (destructive) {
+		if (verbosity >= 1) {
+			printf ("Formatting the token and setting the PIN and SO-PIN as specified\n");
+		}
 		TESTRV ("Formatting the token",
 			 P11("C_InitToken") (slotid, (CK_UTF8CHAR_PTR) ascii_pin_so, strlen (ascii_pin_so), (CK_UTF8CHAR_PTR) TOKENLABEL_32CHARS));
 	} else {
@@ -852,13 +944,22 @@
 
 
 /* Commandline options */
-static const char *opts = "hp:s:l:";	// excluding shorthand -X
+static const char *opts = "hvfp:P:l:m:";	// excluding shorthand -X
 static const struct option longopts[] = {
 	{ "help", 0, NULL, 'h' },
+	{ "verbose", 2, NULL, 'v' },
 	{ "pin", 1, NULL, 'p' },
-	{ "so-pin", 1, NULL, 's' },
+	{ "so-pin", 1, NULL, 'P' },
 	{ "pkcs11lib",1, NULL, 'l' },
 	{ "destructive", 0, NULL, 'X' },
+	{ "frivolous", 0, NULL, 'f' },
+	{ "fast-and-frivolous", 0, NULL, 'f' },
+	{ "max-keypairs", 1, NULL, 'm' },
+	// { "max-keys", 1, NULL, 'm' },
+	{ "skip-initiation", 0, NULL, 1 },
+	{ "skip-fragmentation", 0, NULL, 2 },
+	{ "skip-keysizing", 0, NULL, 3 },
+	{ "skip-signing", 0, NULL, 4 },
 	// { "token", 1, NULL, 't' },
 	//? { "interactive", 1, NULL, 'i' },
 	//? { "xmlfile", 1, NULL, 'i' },
@@ -918,7 +1019,7 @@
 			storepin ("user", optarg, ascii_pin_user, sizeof (ascii_pin_user) - 1);
 			break;
 			
-		case 's':	// --so-pin
+		case 'P':	// --so-pin
 			storepin ("SO", optarg, ascii_pin_so, sizeof (ascii_pin_so) - 1);
 			break;
 		case 'l':	// --pkcs1llib
@@ -926,17 +1027,12 @@
 				fprintf (stderr, "You should not open multiple PKCS #11 libraries\n");
 				exit (1);
 			}
-			if (strstr (argv [1], "softhsm")) {
-				fprintf (stderr, "WARNING -- It appears you are using the SoftHSM library.\nIt may not constrain memory size, causing this test to run extremely long.\n");
-			}
 			p11 = dlopen (optarg, RTLD_NOW | RTLD_GLOBAL);
 			if (!p11) {
 				fprintf (stderr, "%s\n", dlerror ());
 				exit (1);
 			}
 			break;
-		// case 't':
-		// Token?
 		case 'X':	// --destructive
 			if (destructive) {
 				fprintf (stderr, "You should not specify your destructive wishes more than once\n");
@@ -944,6 +1040,69 @@
 			}
 			destructive = 1;
 			break;
+		case 'f':	// --fast-and-frivolous
+			if (thousands < 1000) {
+				fprintf (stderr, "You should not specify the fast option more than once\n");
+				exit (1);
+			}
+			thousands = 10;
+			hundred = 8;
+			couple = 3;
+			break;
+#if 0
+		case 'm':	// --max-keypairs
+			if (max_keypairs > 0) {
+				fprintf (stderr, "You should not specify the maximum number of key pairs more than once\n");
+				exit (1);
+			}
+			max_keypairs = atoi (optarg);
+			if (max_keypairs <= 0) {
+				fprintf (stderr, "You should specify a positive integer for the maximum number of keypairs\n");
+				exit (1);
+			}
+			break;
+#endif
+		case 'v':		// --verbose
+			if (optarg) {
+				verbosity = atoi (optarg);
+				if (verbosity < 0) {
+					fprintf (stderr, "You should not specify negative verbosity levels\n");
+					exit (1);
+				}
+			} else {
+				verbosity++;
+			}
+			break;
+		case 1:			// --skip-initiation
+			if (skip_initiation) {
+				fprintf (stderr, "You should not specify --skip-initiation more than once\n");
+				exit (1);
+			}
+			skip_initiation = 1;
+			break;
+		case 2:			// --skip-fragmentation
+			if (skip_fragmentation) {
+				fprintf (stderr, "You should not specify --skip-fragmentation more than once\n");
+				exit (1);
+			}
+			skip_fragmentation = 1;
+			break;
+		case 3:			// --skip-keysizing
+			if (skip_keysizing) {
+				fprintf (stderr, "You should not specify --skip-keysizing more than once\n");
+				exit (1);
+			}
+			skip_keysizing = 1;
+			break;
+		case 4:			// --skip-signing
+			if (skip_signing) {
+				fprintf (stderr, "You should not specify --skip-signing more than once\n");
+				exit (1);
+			}
+			skip_signing = 1;
+			break;
+		// case 't':
+		// Token?
 		case -1:		// Done -- but are we, really?
 			if ((*ascii_pin_user) && (*ascii_pin_so) && p11) {
 				todo = 0;
@@ -954,7 +1113,7 @@
 		case 'h':
 		case ':':
 		case '?':
-			fprintf (stderr, "Usage: %s [--destructive] --pin 1234 --so-pin 4321 --pkcs11lib /path/to/libpkcs11.so\n", argv [0]);
+			fprintf (stderr, "Minimal usage: %s --pin 1234 --so-pin 4321 --pkcs11lib /path/to/libpkcs11.so\n", argv [0]);
 			exit (opt != 'h');
 		}
 	}
@@ -974,21 +1133,29 @@
 		fprintf (stderr, "Failed to allocate all test suites -- this is abnormal\n");
 		exit (1);
 	}
-	if (! CU_add_test (st [0], "Initiation test", testslot_initiation)) {
-		fprintf (stderr, "Failed to register test #0 -- this is abnormal\n");
-		exit (1);
+	if (! skip_initiation) {
+		if (! CU_add_test (st [0], "Initiation test", testslot_initiation)) {
+			fprintf (stderr, "Failed to register test #0 -- this is abnormal\n");
+			exit (1);
+		}
 	}
-	if (! CU_add_test (st [1], "Fragmentation test", testslot_fragmentation)) {
-		fprintf (stderr, "Failed to register test #1 -- this is abnormal\n");
-		exit (1);
+	if (! skip_fragmentation) {
+		if (! CU_add_test (st [1], "Fragmentation test", testslot_fragmentation)) {
+			fprintf (stderr, "Failed to register test #1 -- this is abnormal\n");
+			exit (1);
+		}
 	}
-	if (! CU_add_test (st [2], "Key sizing test", testslot_keysizing)) {
-		fprintf (stderr, "Failed to register test #2 -- this is abnormal\n");
-		exit (1);
+	if (! skip_keysizing) {
+		if (! CU_add_test (st [2], "Key sizing test", testslot_keysizing)) {
+			fprintf (stderr, "Failed to register test #2 -- this is abnormal\n");
+			exit (1);
+		}
 	}
-	if (! CU_add_test (st [3], "Signing test", testslot_signing)) {
-		fprintf (stderr, "Failed to register test #3 -- this is abnormal\n");
-		exit (1);
+	if (! skip_signing) {
+		if (! CU_add_test (st [3], "Signing test", testslot_signing)) {
+			fprintf (stderr, "Failed to register test #3 -- this is abnormal\n");
+			exit (1);
+		}
 	}
 
 	/*
@@ -1030,8 +1197,14 @@
 	/*
 	 * Automatically run all the tests that were registered
 	 */
+	if (verbosity >= 1) {
+		printf ("Beginning test sequence\n");
+	}
 	CU_list_tests_to_file ();
 	CU_automated_run_tests ();
+	if (verbosity >= 1) {
+		printf ("Ended test sequence\n");
+	}
 
 	/*
 	 * Unload the PKCS #11 library




More information about the Opendnssec-commits mailing list