aboutsummaryrefslogtreecommitdiff
path: root/cryptech_backup
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2020-09-06 00:06:57 -0400
committerRob Austein <sra@hactrn.net>2020-09-06 00:06:57 -0400
commitfe62a7a3bfa0829c367433659d4bdf2a2b004d77 (patch)
tree64d85f44febcacde29e75eb4081cf6ceb583ba8a /cryptech_backup
parent6212a592c52372080c7c5035c6a2513dcb50cf61 (diff)
Can't write bytes to JSON, only str
Diffstat (limited to 'cryptech_backup')
-rwxr-xr-xcryptech_backup13
1 files 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()))