浏览代码

fixup with msgpack data types related fixes

Thomas Waldmann 1 年之前
父节点
当前提交
bfead4b288
共有 1 个文件被更改,包括 9 次插入7 次删除
  1. 9 7
      src/borg/crypto/key.py

+ 9 - 7
src/borg/crypto/key.py

@@ -307,27 +307,29 @@ class KeyBase:
         unpacker = get_limited_unpacker("archive")
         unpacker = get_limited_unpacker("archive")
         unpacker.feed(data)
         unpacker.feed(data)
         unpacked = unpacker.unpack()
         unpacked = unpacker.unpack()
-        if b"tam" not in unpacked:
+        if "tam" not in unpacked:
             if tam_required:
             if tam_required:
-                archive_name = unpacked.get(b"name", b"<unknown>").decode("ascii", "replace")
+                archive_name = unpacked.get("name", "<unknown>")
                 raise ArchiveTAMRequiredError(archive_name)
                 raise ArchiveTAMRequiredError(archive_name)
             else:
             else:
                 logger.debug("TAM not found and not required")
                 logger.debug("TAM not found and not required")
                 return unpacked, False
                 return unpacked, False
-        tam = unpacked.pop(b"tam", None)
+        tam = unpacked.pop("tam", None)
         if not isinstance(tam, dict):
         if not isinstance(tam, dict):
             raise ArchiveTAMInvalid()
             raise ArchiveTAMInvalid()
-        tam_type = tam.get(b"type", b"<none>").decode("ascii", "replace")
+        tam_type = tam.get("type", "<none>")
         if tam_type != "HKDF_HMAC_SHA512":
         if tam_type != "HKDF_HMAC_SHA512":
             if tam_required:
             if tam_required:
                 raise TAMUnsupportedSuiteError(repr(tam_type))
                 raise TAMUnsupportedSuiteError(repr(tam_type))
             else:
             else:
                 logger.debug("Ignoring TAM made with unsupported suite, since TAM is not required: %r", tam_type)
                 logger.debug("Ignoring TAM made with unsupported suite, since TAM is not required: %r", tam_type)
                 return unpacked, False
                 return unpacked, False
-        tam_hmac = tam.get(b"hmac")
-        tam_salt = tam.get(b"salt")
-        if not isinstance(tam_salt, bytes) or not isinstance(tam_hmac, bytes):
+        tam_hmac = tam.get("hmac")
+        tam_salt = tam.get("salt")
+        if not isinstance(tam_salt, (bytes, str)) or not isinstance(tam_hmac, (bytes, str)):
             raise ArchiveTAMInvalid()
             raise ArchiveTAMInvalid()
+        tam_hmac = want_bytes(tam_hmac)  # legacy
+        tam_salt = want_bytes(tam_salt)  # legacy
         offset = data.index(tam_hmac)
         offset = data.index(tam_hmac)
         data[offset : offset + 64] = bytes(64)
         data[offset : offset + 64] = bytes(64)
         tam_key = self._tam_key(tam_salt, context=b"archive")
         tam_key = self._tam_key(tam_salt, context=b"archive")