mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-20 21:27:32 +00:00
Improved error handling
This commit is contained in:
parent
1d0914177d
commit
bf08c09dcc
2 changed files with 10 additions and 7 deletions
|
@ -221,7 +221,7 @@ def restore_attrs(self, path, item, symlink=False):
|
|||
os.utime(path, (item['mtime'], item['mtime']))
|
||||
|
||||
def verify_file(self, item, start, result):
|
||||
def verify_chunk(chunk, error, (id, i, last)):
|
||||
def verify_chunk(chunk, error, (id, i)):
|
||||
if error:
|
||||
raise error
|
||||
if i == 0:
|
||||
|
@ -229,7 +229,7 @@ def verify_chunk(chunk, error, (id, i, last)):
|
|||
data, hash = self.key.decrypt(chunk)
|
||||
if self.key.id_hash(data) != id:
|
||||
result(item, False)
|
||||
elif last:
|
||||
elif i == n - 1:
|
||||
result(item, True)
|
||||
n = len(item['chunks'])
|
||||
if n == 0:
|
||||
|
@ -237,13 +237,14 @@ def verify_chunk(chunk, error, (id, i, last)):
|
|||
result(item, True)
|
||||
else:
|
||||
for i, (id, size, csize) in enumerate(item['chunks']):
|
||||
self.store.get(NS_CHUNK, id, callback=verify_chunk, callback_data=(id, i, i==n-1))
|
||||
self.store.get(NS_CHUNK, id, callback=verify_chunk, callback_data=(id, i))
|
||||
|
||||
def delete(self, cache):
|
||||
def callback(chunk, error, id):
|
||||
assert not error
|
||||
data, items_hash = self.key.decrypt(chunk)
|
||||
assert self.key.id_hash(data) == id
|
||||
if self.key.id_hash(data) != id:
|
||||
raise IntegrityError('Chunk checksum mismatch')
|
||||
unpacker.feed(data)
|
||||
for item in unpacker:
|
||||
try:
|
||||
|
|
|
@ -50,7 +50,8 @@ def open(self, filename):
|
|||
if not data:
|
||||
print 'Incorrect password'
|
||||
key = msgpack.unpackb(data)
|
||||
assert key['version'] == 1
|
||||
if key['version'] != 1:
|
||||
raise IntegrityError('Invalid key file header')
|
||||
self.store_id = key['store_id']
|
||||
self.enc_key = key['enc_key']
|
||||
self.enc_hmac_key = key['enc_hmac_key']
|
||||
|
@ -161,10 +162,11 @@ def encrypt(self, data):
|
|||
return ''.join(('\0', hash, data)), hash
|
||||
|
||||
def decrypt(self, data):
|
||||
assert data[0] == '\0'
|
||||
if data[0] != '\0':
|
||||
raise IntegrityError('Invalid encryption envelope')
|
||||
hash = data[1:33]
|
||||
if HMAC.new(self.enc_hmac_key, data[33:], SHA256).digest() != hash:
|
||||
raise IntegrityError('Encryption integrity error')
|
||||
raise IntegrityError('Encryption envelope checksum mismatch')
|
||||
nonce = bytes_to_long(data[33:49])
|
||||
counter = Counter.new(128, initial_value=nonce, allow_wraparound=True)
|
||||
data = AES.new(self.enc_key, AES.MODE_CTR, counter=counter).decrypt(data[49:])
|
||||
|
|
Loading…
Reference in a new issue