Skip to content

Commit

Permalink
list: support {tam} placeholder. check archive TAM.
Browse files Browse the repository at this point in the history
list: shows either "verified" or "none", depending on
whether a TAM auth tag could be verified or was
missing (old archives from borg < 1.0.9).

when loading an archive, we now try to verify the archive
TAM, but we do not require it. people might still have
old archives in their repos and we want to be able to
list such repos without fatal exceptions.
  • Loading branch information
ThomasWaldmann committed Aug 29, 2023
1 parent 277b0b8 commit b23e6cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/borg/archive.py
Expand Up @@ -493,6 +493,7 @@ def __init__(
self.name = name # overwritten later with name from archive metadata
self.name_in_manifest = name # can differ from .name later (if borg check fixed duplicate archive names)
self.comment = None
self.tam_verified = False
self.numeric_ids = numeric_ids
self.noatime = noatime
self.noctime = noctime
Expand Down Expand Up @@ -532,7 +533,9 @@ def __init__(
def _load_meta(self, id):
cdata = self.repository.get(id)
_, data = self.repo_objs.parse(id, cdata)
metadata = ArchiveItem(internal_dict=msgpack.unpackb(data))
# we do not require TAM for archives, otherwise we can not even borg list a repo with old archives.
archive, self.tam_verified = self.key.unpack_and_verify_archive(data, force_tam_not_required=True)
metadata = ArchiveItem(internal_dict=archive)
if metadata.version not in (1, 2): # legacy: still need to read v1 archives
raise Exception("Unknown archive metadata version")
# note: metadata.items must not get written to disk!
Expand Down
4 changes: 3 additions & 1 deletion src/borg/crypto/key.py
Expand Up @@ -301,7 +301,9 @@ def unpack_and_verify_archive(self, data, force_tam_not_required=False):
"""Unpack msgpacked *data* and return (object, did_verify)."""
tam_required = self.tam_required
if force_tam_not_required and tam_required:
logger.warning("Archive authentication DISABLED.")
# for a long time, borg only checked manifest for "tam_required" and
# people might have archives without TAM, so don't be too annoyingly loud here:
logger.debug("Archive authentication DISABLED.")
tam_required = False
data = bytearray(data)
unpacker = get_limited_unpacker("archive")
Expand Down
7 changes: 6 additions & 1 deletion src/borg/helpers/parseformat.py
Expand Up @@ -723,11 +723,12 @@ class ArchiveFormatter(BaseFormatter):
"id": "internal ID of the archive",
"hostname": "hostname of host on which this archive was created",
"username": "username of user who created this archive",
"tam": "TAM authentication state of this archive",
"size": "size of this archive (data plus metadata, not considering compression and deduplication)",
"nfiles": "count of files in this archive",
}
KEY_GROUPS = (
("archive", "name", "comment", "id"),
("archive", "name", "comment", "id", "tam"),
("start", "time", "end", "command_line"),
("hostname", "username"),
("size", "nfiles"),
Expand All @@ -750,6 +751,7 @@ def __init__(self, format, repository, manifest, key, *, iec=False):
"username": partial(self.get_meta, "username", ""),
"comment": partial(self.get_meta, "comment", ""),
"command_line": partial(self.get_meta, "command_line", ""),
"tam": self.get_tam,
"size": partial(self.get_meta, "size", 0),
"nfiles": partial(self.get_meta, "nfiles", 0),
"end": self.get_ts_end,
Expand Down Expand Up @@ -795,6 +797,9 @@ def get_meta(self, key, default=None):
def get_ts_end(self):
return self.format_time(self.archive.ts_end)

def get_tam(self):
return "verified" if self.archive.tam_verified else "none"

def format_time(self, ts):
return OutputTimestamp(ts)

Expand Down

0 comments on commit b23e6cb

Please sign in to comment.