mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-10 06:03:38 +00:00
check: rebuild_refcounts verify and recreate TAM
This part of the archive checker recreates the Archive items (always, just in case some missing chunks needed repairing). When loading the Archive item, we now verify the TAM. When saving the (potentially modified) Archive item, we now (re-)generate the TAM. Archives without a valid TAM are dropped rather than TAM-authenticated when saving them. There shouldn't be any archives without a valid TAM: - borg writes an archive TAM since long (1.0.9) - users are expected to TAM-authenticate archives created by older borg when upgrading to borg 1.2.5. Also: Archive.set_meta: TAM-authenticate new archive This is also used by Archive.rename and .recreate.
This commit is contained in:
parent
1fd94bd38f
commit
7da8738513
1 changed files with 13 additions and 3 deletions
|
@ -959,7 +959,7 @@ Utilization of max. archive size: {csize_max:.0%}
|
||||||
def set_meta(self, key, value):
|
def set_meta(self, key, value):
|
||||||
metadata = self._load_meta(self.id)
|
metadata = self._load_meta(self.id)
|
||||||
setattr(metadata, key, value)
|
setattr(metadata, key, value)
|
||||||
data = msgpack.packb(metadata.as_dict())
|
data = self.key.pack_and_authenticate_metadata(metadata.as_dict(), context=b'archive')
|
||||||
new_id = self.key.id_hash(data)
|
new_id = self.key.id_hash(data)
|
||||||
self.cache.add_chunk(new_id, data, self.stats)
|
self.cache.add_chunk(new_id, data, self.stats)
|
||||||
self.manifest.archives[self.name] = (new_id, metadata.time)
|
self.manifest.archives[self.name] = (new_id, metadata.time)
|
||||||
|
@ -2061,7 +2061,17 @@ class ArchiveChecker:
|
||||||
self.error_found = True
|
self.error_found = True
|
||||||
del self.manifest.archives[info.name]
|
del self.manifest.archives[info.name]
|
||||||
continue
|
continue
|
||||||
archive = ArchiveItem(internal_dict=msgpack.unpackb(data))
|
try:
|
||||||
|
archive, verified = self.key.unpack_and_verify_archive(data, force_tam_not_required=False)
|
||||||
|
except IntegrityError as integrity_error:
|
||||||
|
# looks like there is a TAM issue with this archive, this might be an attack!
|
||||||
|
# when upgrading to borg 1.2.5, users are expected to TAM-authenticate all archives they
|
||||||
|
# trust, so there shouldn't be any without TAM.
|
||||||
|
logger.error('Archive TAM authentication issue for archive %s: %s', info.name, integrity_error)
|
||||||
|
self.error_found = True
|
||||||
|
del self.manifest.archives[info.name]
|
||||||
|
continue
|
||||||
|
archive = ArchiveItem(internal_dict=archive)
|
||||||
if archive.version != 1:
|
if archive.version != 1:
|
||||||
raise Exception('Unknown archive metadata version')
|
raise Exception('Unknown archive metadata version')
|
||||||
archive.cmdline = [safe_decode(arg) for arg in archive.cmdline]
|
archive.cmdline = [safe_decode(arg) for arg in archive.cmdline]
|
||||||
|
@ -2075,7 +2085,7 @@ class ArchiveChecker:
|
||||||
for previous_item_id in archive.items:
|
for previous_item_id in archive.items:
|
||||||
mark_as_possibly_superseded(previous_item_id)
|
mark_as_possibly_superseded(previous_item_id)
|
||||||
archive.items = items_buffer.chunks
|
archive.items = items_buffer.chunks
|
||||||
data = msgpack.packb(archive.as_dict())
|
data = self.key.pack_and_authenticate_metadata(archive.as_dict(), context=b'archive')
|
||||||
new_archive_id = self.key.id_hash(data)
|
new_archive_id = self.key.id_hash(data)
|
||||||
cdata = self.key.encrypt(data)
|
cdata = self.key.encrypt(data)
|
||||||
add_reference(new_archive_id, len(data), len(cdata), cdata)
|
add_reference(new_archive_id, len(data), len(cdata), cdata)
|
||||||
|
|
Loading…
Add table
Reference in a new issue