From 7e624f40b2b60a582db9bf297f00b743e3a91c96 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 25 Jul 2017 05:53:10 -0300 Subject: [feature] handle unsupported encryption schemes by saving directly --- src/leap/soledad/client/_crypto.py | 6 +++++- src/leap/soledad/client/_db/blobs.py | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/leap/soledad/client/_crypto.py b/src/leap/soledad/client/_crypto.py index a0ec343c..8b0b8f81 100644 --- a/src/leap/soledad/client/_crypto.py +++ b/src/leap/soledad/client/_crypto.py @@ -108,6 +108,10 @@ class InvalidBlob(Exception): pass +class EncryptionSchemeNotImplementedException(Exception): + pass + + class SoledadCrypto(object): """ This class provides convenient methods for document encryption and @@ -389,7 +393,7 @@ class BlobDecryptor(object): # we can refuse to process something that is in the future or # too far in the past (1984 would be nice, hehe) if preamble.scheme != ENC_SCHEME.symkey: - raise InvalidBlob('Invalid scheme: %s' % preamble.scheme) + raise EncryptionSchemeNotImplementedException(preamble.scheme) if preamble.method != ENC_METHOD.aes_256_gcm: method = preamble.method raise InvalidBlob('Invalid encryption scheme: %s' % method) diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index e95f9d9e..5334ffe5 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -42,6 +42,7 @@ from .._document import BlobDoc from .._crypto import DocInfo from .._crypto import BlobEncryptor from .._crypto import BlobDecryptor +from .._crypto import EncryptionSchemeNotImplementedException from .._http import HTTPClient from .._pipes import TruncatedTailPipe from .._pipes import PreamblePipe @@ -124,22 +125,30 @@ class DecrypterBuffer(object): self.secret = secret self.tag = tag self.preamble_pipe = PreamblePipe(self._make_decryptor) + self.decrypter = None def _make_decryptor(self, preamble): - self.decrypter = BlobDecryptor( - self.doc_info, preamble, - secret=self.secret, - armor=False, - start_stream=False, - tag=self.tag) - return TruncatedTailPipe(self.decrypter, tail_size=len(self.tag)) + try: + self.decrypter = BlobDecryptor( + self.doc_info, preamble, + secret=self.secret, + armor=False, + start_stream=False, + tag=self.tag) + return TruncatedTailPipe(self.decrypter, tail_size=len(self.tag)) + except EncryptionSchemeNotImplementedException: + self.raw_data = BytesIO() + return self.raw_data def write(self, data): self.preamble_pipe.write(data) def close(self): - real_size = self.decrypter.decrypted_content_size - return self.decrypter._end_stream(), real_size + if self.decrypter: + real_size = self.decrypter.decrypted_content_size + return self.decrypter._end_stream(), real_size + else: + return self.raw_data, self.raw_data.tell() class BlobManager(object): -- cgit v1.2.3