From fe62a7a3bfa0829c367433659d4bdf2a2b004d77 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 6 Sep 2020 00:06:57 -0400 Subject: Can't write bytes to JSON, only str --- cryptech_backup | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cryptech_backup b/cryptech_backup index 4292eaf..def2a31 100755 --- a/cryptech_backup +++ b/cryptech_backup @@ -149,10 +149,10 @@ def defcmd(subparsers, func): def b64(der): - return base64.b64encode(der).splitlines() + return base64.b64encode(der).decode().splitlines() def b64join(lines): - return base64.b64decode("".join(lines)) + return base64.b64decode("".join(lines).encode()) def cmd_setup(args, hsm): @@ -350,7 +350,7 @@ class AESKeyWrapWithPadding(object): if len(C) % 8 != 0: raise self.UnwrapError("Ciphertext length {} is not an integral number of blocks" .format(len(C))) - n = (len(C) / 8) - 1 + n = (len(C) // 8) - 1 R = [C[i : i + 8] for i in range(0, len(C), 8)] if n == 1: R[0], R[1] = self._decrypt(R[0], R[1]) @@ -368,9 +368,8 @@ class AESKeyWrapWithPadding(object): raise self.UnwrapError("Length encoded in AIV out of range: m {}, n {}".format(m, n)) R = b"".join(R[1:]) assert len(R) == 8 * n - if any(r != b"\x00" for r in R[m:]): - raise self.UnwrapError("Nonzero trailing bytes {}".format( - binascii.hexlify(R[m:]).decode("ascii"))) + if R[m:].strip(b"\x00"): + raise self.UnwrapError("Nonzero trailing bytes 0x{}".format(binascii.hexlify(R[m:]).decode("ascii"))) return R[:m] @@ -415,7 +414,7 @@ class SoftKEKEK(object): return AESKeyWrapWithPadding(PBKDF2( password = getpass.getpass("KEKEK Passphrase: "), salt = salt, - dkLen = keylen/8, + dkLen = keylen//8, count = iterations, prf = lambda p, s: HMAC.new(p, s, SHA256).digest())) -- cgit v1.2.3