From 641a95fd9b3a61dc405084e88f5ef6bd25030ca7 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 30 Oct 2016 16:13:52 -0400 Subject: Preliminary libhal.py test code superseded by unit-tests.py --- libhal.py | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/libhal.py b/libhal.py index 41fb799..50209f9 100644 --- a/libhal.py +++ b/libhal.py @@ -641,50 +641,3 @@ class HSM(object): def pkey_delete_attribute(self, pkey, attr_type): with self.rpc(RPC_FUNC_PKEY_DELETE_ATTRIBUTE, pkey, attr_type): return - -if __name__ == "__main__": - - import argparse - - def hexstr(s): - return "".join("{:02x}".format(ord(c)) for c in s) - - parser = argparse.ArgumentParser() - parser.add_argument("--device", default = os.getenv("CRYPTECH_RPC_CLIENT_SERIAL_DEVICE", "/dev/ttyUSB0")) - parser.add_argument("--pin", default = "fnord") - args = parser.parse_args() - - hsm = HSM(device = args.device) - - print "Version:", hex(hsm.get_version()) - - print "Random:", hexstr(hsm.get_random(16)) - - h = hsm.hash_initialize(HAL_DIGEST_ALGORITHM_SHA256) - h.update("Hi, Mom") - print "Hash:", hexstr(h.finalize()) - - h = hsm.hash_initialize(HAL_DIGEST_ALGORITHM_SHA256, key = "secret") - h.update("Hi, Dad") - print "HMAC:", hexstr(h.finalize()) - - print "Logging in" - hsm.login(HAL_USER_NORMAL, args.pin) - - print "Generating key" - k = hsm.pkey_generate_ec(HAL_CURVE_P256) - print "PKey: {0.uuid} {0.key_type} {0.key_flags} {1}".format(k, hexstr(k.public_key)) - hsm.pkey_close(k) - - for flags in (0, HAL_KEY_FLAG_TOKEN): - for t, c, f, u in hsm.pkey_list(flags = flags): - print "List:", u, t, c, f - - for f in (HAL_KEY_FLAG_TOKEN, 0): - for u in hsm.pkey_match(flags = f): - print "Match:", u - - k = hsm.pkey_find(k.uuid) - hsm.pkey_delete(k) - - hsm.logout() -- cgit v1.2.3