aboutsummaryrefslogtreecommitdiff
path: root/cryptech_muxd
diff options
context:
space:
mode:
Diffstat (limited to 'cryptech_muxd')
-rwxr-xr-xcryptech_muxd31
1 files changed, 16 insertions, 15 deletions
diff --git a/cryptech_muxd b/cryptech_muxd
index ff40048..6c21f7e 100755
--- a/cryptech_muxd
+++ b/cryptech_muxd
@@ -45,6 +45,7 @@ import atexit
import weakref
import logging
import argparse
+import binascii
import logging.handlers
import serial
@@ -64,13 +65,13 @@ from cryptech.libhal import HAL_OK, RPC_FUNC_GET_VERSION, RPC_FUNC_LOGOUT, RPC_F
logger = logging.getLogger("cryptech_muxd")
-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
def slip_encode(buffer):
@@ -146,7 +147,7 @@ class PFUnixServer(tornado.tcpserver.TCPServer):
(aka PF_LOCAL) socket instead of a TCP socket.
"""
- def __init__(self, serial_stream, socket_filename, mode = 0600):
+ def __init__(self, serial_stream, socket_filename, mode = 0o600):
super(PFUnixServer, self).__init__()
self.serial = serial_stream
self.socket_filename = socket_filename
@@ -173,7 +174,7 @@ class RPCIOStream(SerialIOStream):
@tornado.gen.coroutine
def rpc_input(self, query, handle = 0, queue = None):
"Send a query to the HSM."
- logger.debug("RPC send: %s", ":".join("{:02x}".format(ord(c)) for c in query))
+ logger.debug("RPC send: %s", ":".join(binascii.hexlify(c) for c in query))
if queue is not None:
self.queues[handle] = queue
with (yield self.rpc_input_lock.acquire()):
@@ -189,10 +190,10 @@ class RPCIOStream(SerialIOStream):
reply = yield self.read_until(SLIP_END)
except tornado.iostream.StreamClosedError:
logger.info("RPC UART closed")
- for q in self.queues.itervalues():
+ for q in self.queues.values():
q.put_nowait(None)
return
- logger.debug("RPC recv: %s", ":".join("{:02x}".format(ord(c)) for c in reply))
+ logger.debug("RPC recv: %s", ":".join(binascii.hexlify(c) for c in reply))
if reply == SLIP_END:
continue
try:
@@ -348,7 +349,7 @@ class ProbeIOStream(SerialIOStream):
results = yield dict((dev, ProbeIOStream(dev).run_probe()) for dev in devs)
- for dev, result in results.iteritems():
+ for dev, result in results.items():
if result == "cty" and args.cty_device is None:
logger.info("Selecting %s as CTY device", dev)
@@ -370,9 +371,9 @@ class ProbeIOStream(SerialIOStream):
yield tornado.gen.sleep(0.5)
response = yield self.read_bytes(self.read_chunk_size, partial = True)
- logger.debug("Probing %s: %r %s", self.serial_device, response, ":".join("{:02x}".format(ord(c)) for c in response))
+ logger.debug("Probing %s: %r %s", self.serial_device, response, ":".join(binascii.hexlify(c) for c in response))
- 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>"))
try:
is_rpc = response[response.index(SLIP_END + RPC_reply) + len(SLIP_END + RPC_reply) + 4] == SLIP_END
@@ -429,7 +430,7 @@ def main():
parser.add_argument("--rpc-socket-mode",
help = "permission bits for RPC socket inode",
- default = 0600, type = lambda s: int(s, 8))
+ default = 0o600, type = lambda s: int(s, 8))
parser.add_argument("--cty-device",
help = "CTY serial device name",
@@ -442,7 +443,7 @@ def main():
parser.add_argument("--cty-socket-mode",
help = "permission bits for CTY socket inode",
- default = 0600, type = lambda s: int(s, 8))
+ default = 0o600, type = lambda s: int(s, 8))
args = parser.parse_args()