summaryrefslogtreecommitdiff
path: root/src/leap/soledad
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-12-03 11:28:21 -0200
committerdrebs <drebs@leap.se>2012-12-03 11:28:21 -0200
commit9c63f2becc0caa1f684852224375b54f828cc42e (patch)
tree781bcddd81eacc1c286ed7c9cdec83749ca84bdf /src/leap/soledad
parent7a932811c018bb30b584451d4fe114cf69ab420c (diff)
LeapDocument can set and get 'valid' encrypted json
Diffstat (limited to 'src/leap/soledad')
-rw-r--r--src/leap/soledad/leap.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/leap/soledad/leap.py b/src/leap/soledad/leap.py
index 08330618..863e63f8 100644
--- a/src/leap/soledad/leap.py
+++ b/src/leap/soledad/leap.py
@@ -26,21 +26,27 @@ class LeapDocument(Document):
Returns document's json serialization encrypted with user's public key.
"""
# TODO: replace for openpgp encryption with users's pub key.
- return base64.b64encode(self.get_json())
+ return json.dumps({'cyphertext':base64.b64encode(self.get_json())})
- def set_encrypted_json(self):
+ def set_encrypted_json(self, encrypted_json):
"""
Set document's content based on encrypted version of json string.
"""
# TODO:
# - replace for openpgp decryption using user's priv key.
# - raise error if unsuccessful.
- return self.set_json(base64.b64decode(self.get_json()))
+ cyphertext = json.loads(encrypted_json)['cyphertext']
+ plaintext = base64.b64decode(cyphertext)
+ return self.set_json(plaintext)
class LeapSyncTarget(HTTPSyncTarget):
def _parse_sync_stream(self, data, return_doc_cb, ensure_callback=None):
+ """
+ Does the same as parent's method but ensures incoming content will be
+ decrypted.
+ """
parts = data.splitlines() # one at a time
if not parts or parts[0] != '[':
raise BrokenSyncStream
@@ -75,6 +81,9 @@ class LeapSyncTarget(HTTPSyncTarget):
def sync_exchange(self, docs_by_generations, source_replica_uid,
last_known_generation, last_known_trans_id,
return_doc_cb, ensure_callback=None):
+ """
+ Does the same as parent's method but encrypts content before syncing.
+ """
self._ensure_connection()
if self._trace_hook: # for tests
self._trace_hook('sync_exchange')