aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-10-30 16:13:52 -0400
committerRob Austein <sra@hactrn.net>2016-10-30 16:13:52 -0400
commit641a95fd9b3a61dc405084e88f5ef6bd25030ca7 (patch)
tree5a3bfed2ab9ad4e6870a6eb60a41319b7a566a18
parent65e3711c86b6e94a1ced8128f7dfbd1e85638c06 (diff)
Preliminary libhal.py test code superseded by unit-tests.py
-rw-r--r--libhal.py47
1 files changed, 0 insertions, 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()