aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-11-25 12:51:29 -0500
committerRob Austein <sra@hactrn.net>2016-11-25 12:51:29 -0500
commitc28f77d75105a31555c0eb45f45c76675248032f (patch)
tree21037c38a4611c6e89c5c9912a79f76f3d303eb6 /projects
parent434088cf8f53770bf016fe8503beaefcdd3c45b4 (diff)
Add debugging code to cryptech_upload.
Diffstat (limited to 'projects')
-rwxr-xr-xprojects/hsm/cryptech_upload27
1 files changed, 20 insertions, 7 deletions
diff --git a/projects/hsm/cryptech_upload b/projects/hsm/cryptech_upload
index 0c3f6fc..6cf1283 100755
--- a/projects/hsm/cryptech_upload
+++ b/projects/hsm/cryptech_upload
@@ -105,16 +105,28 @@ def parse_args():
type = argparse.FileType("rb"),
help = "Explicit source image file for upload, overrides firmware tarball")
+ parser.add_argument("--separate-pins",
+ action = "store_true",
+ help = "Prompt separately for each PIN required during upload")
+
+ parser.add_argument("--debug",
+ action = "store_true",
+ help = "Enable debugging of upload protocol",
+ )
+
return parser.parse_args()
def _write(dst, data):
+ numeric = isinstance(data, (int, long))
+ if numeric:
+ data = struct.pack("<I", data)
dst.write(data)
- #if len(data) == 4:
- # print("Wrote 0x{!s}".format(data.encode("hex")))
- #else:
- # print("Wrote {!r}".format(data))
-
+ if args.debug:
+ if numeric:
+ print("Wrote 0x{!s}".format(data.encode("hex")))
+ else:
+ print("Wrote {!r}".format(data))
def _read(dst):
res = ""
@@ -124,7 +136,8 @@ def _read(dst):
while x:
res += x
x = dst.read(1)
- #print ("Read {!r}".format(res))
+ if args.debug:
+ print ("Read {!r}".format(res))
return res
pin = None
@@ -137,7 +150,7 @@ def _execute(dst, cmd):
_write(dst, args.username + "\r")
prompt = _read(dst)
if prompt.endswith("Password: "):
- if not pin:
+ if not pin or args.separate_pins:
pin = getpass.getpass("{} PIN: ".format(args.username))
_write(dst, pin + "\r")
prompt = _read(dst)