aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--unit_tests.py68
2 files changed, 18 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 90ecb31..f901fb1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,9 +15,11 @@ libhal/tests/test-ecdsa-*.der
libhal/tests/test-hash
libhal/tests/test-mkmif
libhal/tests/test-pbkdf2
+libhal/tests/test-rpc_bighash
libhal/tests/test-rpc_get_random
libhal/tests/test-rpc_get_version
libhal/tests/test-rpc_hash
+libhal/tests/test-rpc_login
libhal/tests/test-rpc_pkey
libhal/tests/test-rpc_server
libhal/tests/test-rsa
diff --git a/unit_tests.py b/unit_tests.py
index b15d7a7..a036a32 100644
--- a/unit_tests.py
+++ b/unit_tests.py
@@ -6,6 +6,7 @@ PKCS #11 unit tests, using Py11 and the Python unit_test framework.
import unittest
import datetime
+import platform
import sys
from py11 import *
@@ -19,6 +20,12 @@ except ImportError:
pycrypto_loaded = False
+if platform.system() == "Darwin":
+ libpkcs11_default = "./libpkcs11.dylib"
+else:
+ libpkcs11_default = "./libpkcs11.so"
+
+
def log(msg):
if not args.quiet:
sys.stderr.write(msg)
@@ -38,31 +45,21 @@ def parse_arguments(argv = ()):
parser.add_argument("--quiet", action = "store_true", help = "suppress chatter")
parser.add_argument("--so-pin", default = "fnord", help = "security officer PIN")
parser.add_argument("--user-pin", default = "fnord", help = "user PIN")
- parser.add_argument("--wheel-pin", help = "wheel PIN")
- parser.add_argument("--initial-pin", help = "initial PIN",
- default = "YouReallyNeedToChangeThisPINRightNowWeAreNotKidding")
parser.add_argument("--slot", default = 0, type = int, help = "slot number")
- parser.add_argument("--libpkcs11", default = "./libpkcs11.so", help = "PKCS #11 library")
- parser.add_argument("--p11util", default = "./p11util", help = "p11util binary")
- parser.add_argument("--server", help = "RPC server binary")
+ parser.add_argument("--libpkcs11", default = libpkcs11_default, help = "PKCS #11 library")
parser.add_argument("--all-tests", action = "store_true", help = "enable tests usually skipped")
parser.add_argument("--sql-file", default = "unit_tests.db", help = "SQLite3 database")
parser.add_argument("--ks-client", default = "unit_tests.ks-client", help = "client keystore (ks_mmap only)")
- parser.add_argument("--ks-server", default = "unit_tests.ks-server", help = "server keystore (ks_mmap only)")
parser.add_argument("--only-test", default = [], nargs = "+", help = "only run tests named here")
return parser.parse_args(argv)
args = parse_arguments()
p11 = None
-rpc = None
-
def setUpModule():
- from subprocess import Popen, PIPE
- from os import unlink, environ, geteuid
- from os.path import abspath, isfile, expanduser
+ from os import unlink, environ
+ from os.path import abspath, isfile
global p11
- global rpc
def new_file(fn):
fn = abspath(fn)
@@ -72,27 +69,6 @@ def setUpModule():
environ["PKCS11_DATABASE"] = new_file(args.sql_file)
environ["CRYPTECH_KEYSTORE"] = new_file(args.ks_client)
- server_keystore = new_file(args.ks_server)
-
- # The sudo and environment variable here are for the Novena, They
- # don't make much sense for the Alpha. May want to factor them
- # out and make them the caller's problem at some point.
- if args.server and isfile(args.server):
- cmd = [args.server]
- if geteuid() != 0:
- cmd.insert(0, "sudo")
- log("Starting RPC server: {}".format(" ".join(cmd)))
- rpc = Popen(cmd, env = dict(environ, CRYPTECH_KEYSTORE = server_keystore))
-
- # Order of PINs here is significant, see p11util for details.
- log("Setting PINs (SLOW!)")
- if args.wheel_pin is None:
- flags = "-sup"
- pins = (args.initial_pin, args.so_pin, args.user_pin)
- else:
- flags = "-wsup"
- pins = (args.initial_pin, args.wheel_pin, args.so_pin, args.user_pin)
- Popen((args.p11util, flags), stdin = PIPE).communicate("".join(pin + "\n" for pin in pins))
log("Loading PKCS #11 library {}".format(args.libpkcs11))
p11 = PKCS11(args.libpkcs11)
@@ -101,26 +77,14 @@ def setUpModule():
def tearDownModule():
- from os import unlink, geteuid
- try:
+ from os import unlink
+ from os.path import isfile
+
+ if isfile(args.sql_file):
unlink(args.sql_file)
- except:
- pass
- try:
+
+ if isfile(args.ks_client):
unlink(args.ks_client)
- except:
- pass
- try:
- unlink(args.ks_server)
- except:
- pass
- global rpc
- if rpc is not None:
- if geteuid() == 0:
- rpc.terminate()
- else:
- from subprocess import check_call
- check_call(("sudo", "kill", str(rpc.pid)))
# Subclass a few bits of unittest to add timing reports for individual tests.