diff options
Diffstat (limited to 'libhal.py')
-rw-r--r-- | libhal.py | 47 |
1 files changed, 0 insertions, 47 deletions
@@ -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() |