diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-12-04 15:52:56 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-12-04 15:52:56 -0300 |
commit | 7f2eec3df3ee5e0eecdb25f064353992d1ec2436 (patch) | |
tree | d763cfef45009f868fe4992beb822cd95e45f76a /src/leap | |
parent | 4afbe7fa6aee038bcaaf4c1c377d7e6921096d27 (diff) |
[bug] escape tag and size
It was generating spaces, causing split to fail sometimes.
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/soledad/client/_db/blobs/__init__.py | 6 | ||||
-rw-r--r-- | src/leap/soledad/server/_streaming_resource.py | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/leap/soledad/client/_db/blobs/__init__.py b/src/leap/soledad/client/_db/blobs/__init__.py index b7b8ad1f..86e45381 100644 --- a/src/leap/soledad/client/_db/blobs/__init__.py +++ b/src/leap/soledad/client/_db/blobs/__init__.py @@ -128,9 +128,9 @@ class StreamDecrypterBuffer(object): self.buf += data if SEPARATOR in self.buf: marker, self.buf = self.buf.split(' ') - assert(len(marker) == 20) # 4 byte size + 16 byte tag - size, tag = marker[:4], marker[4:] - self.current_blob_size = self.size_pack.unpack(size)[0] + size, tag = marker[:8], marker[8:] + tag = base64.urlsafe_b64decode(tag) + self.current_blob_size = int(size, 16) self.received = len(self.buf) blob_id = self.blobs_list.pop(0) buf = DecrypterBuffer(blob_id, self.secret, tag) diff --git a/src/leap/soledad/server/_streaming_resource.py b/src/leap/soledad/server/_streaming_resource.py index 8ce304d1..9b672107 100644 --- a/src/leap/soledad/server/_streaming_resource.py +++ b/src/leap/soledad/server/_streaming_resource.py @@ -20,7 +20,7 @@ A twisted resource that serves download as a single stream of multiple blobs. <- [(size(blob_id), content(blob_id)) for blob_id in DATA] (as a binary stream) """ import json -import struct +import base64 from zope.interface import implementer from twisted.internet.interfaces import IPushProducer @@ -38,7 +38,6 @@ __all__ = ['StreamingResource'] logger = getLogger(__name__) -SIZE_PACKER = struct.Struct('<I') class StreamingResource(Resource): @@ -94,10 +93,11 @@ class DownstreamProducer(object): request, paths = self.request, self.paths while paths: blob_id, path, size = paths.pop(0) - request.write(SIZE_PACKER.pack(size)) # sends file size + request.write('%08x' % size) # sends file size with open(path, 'rb') as blob_fd: blob_fd.seek(-16, 2) - request.write(blob_fd.read()) # sends AES-GCM tag + encoded_tag = base64.urlsafe_b64encode(blob_fd.read()) + request.write(encoded_tag) # sends AES-GCM tag blob_fd.seek(0) request.write(' ') data = blob_fd.read(self.chunk_size) |