Verified Commit 50a863e5 authored by Victor's avatar Victor
Browse files

[bug] handle incomplete preamble as a retriable error

parent 8a89f00a
......@@ -104,8 +104,12 @@ class DecrypterBuffer(object):
if self.decrypter:
real_size = self.decrypter.decrypted_content_size
return self.decrypter.endStream(), real_size
elif hasattr(self, 'raw_data'):
# Externally encrypted blob, see Incoming API specification
return self.raw_data, self.raw_data.tell()
msg = "Incomplete Blob: %s" % self.doc_info.doc_id
raise RetriableTransferError(msg)
class StreamDecrypterBuffer(object):
......@@ -27,6 +27,7 @@ from twisted.internet import defer
from leap.soledad.client._db.blobs import DecrypterBuffer
from leap.soledad.client._db.blobs import BlobManager
from leap.soledad.client._db.blobs import FIXED_REV
from leap.soledad.client._db.blobs.errors import RetriableTransferError
from leap.soledad.client import _crypto
......@@ -70,3 +71,15 @@ class DecrypterBufferCase(unittest.TestCase):
fd = BytesIO('up and up')
manager._client.put = _check_result
yield manager._encrypt_and_upload(self.doc_info.doc_id, fd)
def test_incomplete_decryption(self):
# SCENARIO: Transport failed and close was called with incomplete data
# CASE 1: Incomplete preamble
encrypted = (yield self.blob.encrypt()).getvalue()
encrypted = encrypted[:20] # only 20 bytes of preamble arrived
tag = encrypted[-16:]
buf = DecrypterBuffer(self.doc_info.doc_id, self.secret, tag)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment