summaryrefslogtreecommitdiff
path: root/leap.py
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
commitc44d3870bf93ed6e6d466275f2adaa87697e29f7 (patch)
tree1fe3678c29ac6bc40887ce0b59d5ea6a769b765f /leap.py
parent5385ce5923559c5158f3a5bcbc83bd9b43e9b6f8 (diff)
LeapDocument can set and get 'valid' encrypted json
Diffstat (limited to 'leap.py')
-rw-r--r--leap.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/leap.py b/leap.py
index 08330618..863e63f8 100644
--- a/leap.py
+++ b/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')