aboutsummaryrefslogtreecommitdiff
path: root/projects/hsm/cryptech_probe
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2020-05-25 19:33:47 -0400
committerRob Austein <sra@hactrn.net>2020-05-25 19:33:47 -0400
commitf948d674351a2ca87d33c0e0d8558cbbb2f59682 (patch)
treebf3e5c562e24929da786d8834d3ffe455d974e67 /projects/hsm/cryptech_probe
parent52f72e1e5dc5d3b646b54363f811ee2fd7958c19 (diff)
Untested conversion to support Python 3
Diffstat (limited to 'projects/hsm/cryptech_probe')
-rwxr-xr-xprojects/hsm/cryptech_probe21
1 files changed, 11 insertions, 10 deletions
diff --git a/projects/hsm/cryptech_probe b/projects/hsm/cryptech_probe
index ccee40a..3d14484 100755
--- a/projects/hsm/cryptech_probe
+++ b/projects/hsm/cryptech_probe
@@ -38,6 +38,7 @@ goes to stderr.
import sys
import time
import argparse
+import binascii
import serial.tools.list_ports_posix
class positive_integer(int):
@@ -52,16 +53,16 @@ parser.add_argument("--no-cleanup", action = "store_true", help = "don't
parser.add_argument("--read-buffer-size", type = positive_integer, help = "size of read buffer", default = 1024)
args = parser.parse_args()
-SLIP_END = chr(0300) # Indicates end of SLIP packet
-SLIP_ESC = chr(0333) # Indicates byte stuffing
-SLIP_ESC_END = chr(0334) # ESC ESC_END means END data byte
-SLIP_ESC_ESC = chr(0335) # ESC ESC_ESC means ESC data byte
+SLIP_END = b"\300" # Indicates end of SLIP packet
+SLIP_ESC = b"\333" # Indicates byte stuffing
+SLIP_ESC_END = b"\334" # ESC ESC_END means END data byte
+SLIP_ESC_ESC = b"\335" # ESC ESC_ESC means ESC data byte
-Control_U = chr(0025) # Console: clear line
-Control_M = chr(0015) # Console: end of line
+Control_U = b"\025" # Console: clear line
+Control_M = b"\015" # Console: end of line
-RPC_query = chr(0) * 8 # client_handle = 0, function code = RPC_FUNC_GET_VERSION
-RPC_reply = chr(0) * 12 # opcode = RPC_FUNC_GET_VERSION, client_handle = 0, valret = HAL_OK
+RPC_query = b"\0" * 8 # client_handle = 0, function code = RPC_FUNC_GET_VERSION
+RPC_reply = b"\0" * 12 # opcode = RPC_FUNC_GET_VERSION, client_handle = 0, valret = HAL_OK
# This is the query string we send to each USB port we find. It's
# intended to be relatively harmless, at least for either of the HSM
@@ -101,11 +102,11 @@ for port in ports:
response = tty.read(args.read_buffer_size)
if args.debug:
- sys.stderr.write("Received from {}: {!r} ({})\n".format(port, response, ":".join("{:02x}".format(ord(c)) for c in response)))
+ sys.stderr.write("Received from {}: {!r} ({})\n".format(port, response, ":".join(binascii.hexlify(c) for c in response)))
# Check whether we got a known console prompt.
- is_cty = any(prompt in response for prompt in ("Username:", "Password:", "cryptech>"))
+ is_cty = any(prompt in response for prompt in (b"Username:", b"Password:", b"cryptech>"))
# Check whether we got something that looks like the response to an RPC version query.
# We skip over the version value itself, as it might change, but we check that it's