Merge pull request #6902 from ThomasWaldmann/fix-5719-1.1

check: try harder to create the key, fixes #5719
This commit is contained in:
TW 2022-07-30 15:30:02 +02:00 committed by GitHub
commit 151b245863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 10 deletions

View File

@ -20,7 +20,7 @@ logger = create_logger()
from . import xattr
from .chunker import Chunker
from .cache import ChunkListEntry
from .crypto.key import key_factory
from .crypto.key import key_factory, UnsupportedPayloadError
from .compress import Compressor, CompressionSpec
from .constants import * # NOQA
from .hashindex import ChunkIndex, ChunkIndexEntry, CacheSynchronizer
@ -1250,7 +1250,7 @@ class ArchiveChecker:
if not self.chunks:
logger.error('Repository contains no apparent data at all, cannot continue check/repair.')
return False
self.key = self.identify_key(repository)
self.key = self.make_key(repository)
if verify_data:
self.verify_data()
if Manifest.MANIFEST_ID not in self.chunks:
@ -1292,14 +1292,24 @@ class ArchiveChecker:
for id_ in result:
self.chunks[id_] = init_entry
def identify_key(self, repository):
try:
some_chunkid, _ = next(self.chunks.iteritems())
except StopIteration:
# repo is completely empty, no chunks
return None
cdata = repository.get(some_chunkid)
return key_factory(repository, cdata)
def make_key(self, repository):
attempt = 0
for chunkid, _ in self.chunks.iteritems():
attempt += 1
if attempt > 999:
# we did a lot of attempts, but could not create the key via key_factory, give up.
break
cdata = repository.get(chunkid)
try:
return key_factory(repository, cdata)
except UnsupportedPayloadError:
# we get here, if the cdata we got has a corrupted key type byte
pass # ignore it, just try the next chunk
if attempt == 0:
msg = 'make_key: repository has no chunks at all!'
else:
msg = 'make_key: failed to create the key (tried %d chunks)' % attempt
raise IntegrityError(msg)
def verify_data(self):
logger.info('Starting cryptographic data integrity verification...')