summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/leap/soledad/client/_blobs.py7
-rw-r--r--server/src/leap/soledad/server/_blobs.py16
2 files changed, 22 insertions, 1 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py
index 2cc06146..97d4c39c 100644
--- a/client/src/leap/soledad/client/_blobs.py
+++ b/client/src/leap/soledad/client/_blobs.py
@@ -198,12 +198,17 @@ class BlobManager(object):
logger.info("Staring download of blob: %s" % blob_id)
# TODO this needs to be connected in a tube
uri = self.remote + self.user + '/' + blob_id
- buf = DecrypterBuffer(doc_id, rev, self.secret)
data = yield treq.get(uri)
if data.code == 404:
logger.warn("Blob not found in server: %s" % blob_id)
defer.returnValue(None)
+ elif not data.headers.hasHeader('Tag'):
+ logger.error("Server didn't send a tag header for: %s" % blob_id)
+ defer.returnValue(None)
+ tag = data.headers.getRawHeaders('Tag')[0]
+ tag = base64.urlsafe_b64decode(tag)
+ buf = DecrypterBuffer(doc_id, rev, self.secret, tag)
# incrementally collect the body of the response
yield treq.collect(data, buf.write)
diff --git a/server/src/leap/soledad/server/_blobs.py b/server/src/leap/soledad/server/_blobs.py
index 3b840391..454ff5fe 100644
--- a/server/src/leap/soledad/server/_blobs.py
+++ b/server/src/leap/soledad/server/_blobs.py
@@ -26,6 +26,7 @@ environments.
"""
import commands
import os
+import base64
from twisted.web import static
from twisted.web import resource
@@ -66,6 +67,14 @@ class IBlobsBackend(Interface):
:returns: a deferred that fires upon finishing.
"""
+ def tag_header(user, blob_id, request):
+ """
+ Adds a header 'Tag' with the last 20 bytes of the encoded file,
+ which contains the tag.
+
+ :returns: a deferred that fires upon finishing.
+ """
+
def write_blob(user, blob_id, request):
"""
Write blob to the storage, reading it from the passed request.
@@ -91,6 +100,12 @@ class FilesystemBlobsBackend(object):
path = '/tmp/blobs/'
quota = 200 * 1024 # in KB
+ def tag_header(self, user, blob_id, request):
+ with open(self._get_path(user, blob_id)) as doc_file:
+ doc_file.seek(-16, 2)
+ tag = base64.urlsafe_b64encode(doc_file.read())
+ request.responseHeaders.setRawHeaders('Tag', [tag])
+
def read_blob(self, user, blob_id, request):
print "USER", user
print "BLOB_ID", blob_id
@@ -168,6 +183,7 @@ class BlobsResource(resource.Resource):
def render_GET(self, request):
print "GETTING", request.path
user, blob_id = self._split_path(request.path)
+ self._handler.tag_header(user, blob_id, request)
return self._handler.read_blob(user, blob_id, request)
def render_PUT(self, request):