def _db1AssertDocsSyncedToServer(results): self.assertEqual(number_of_docs, len(created_ids)) for soldoc in created_ids: couchdoc = db.get_doc(soldoc.doc_id) self.assertTrue(couchdoc) # assert document structure in couch server self.assertEqual(soldoc.doc_id, couchdoc.doc_id) self.assertEqual(soldoc.rev, couchdoc.rev) couch_content = couchdoc.content.keys() self.assertEqual(['raw'], couch_content) content = couchdoc.get_json() self.assertTrue(_crypto.is_symmetrically_encrypted(content))
def test_encrypt_and_decrypt(self): """ Check that encrypting and decrypting gives same doc. """ crypto = _crypto.SoledadCrypto('A' * 96) payload = {'key': 'someval'} doc1 = SoledadDocument('id1', '1', json.dumps(payload)) encrypted = yield crypto.encrypt_doc(doc1) assert encrypted != payload assert 'raw' in encrypted doc2 = SoledadDocument('id1', '1') doc2.set_json(encrypted) assert _crypto.is_symmetrically_encrypted(encrypted) decrypted = (yield crypto.decrypt_doc(doc2)).getvalue() assert len(decrypted) != 0 assert json.loads(decrypted) == payload
def assertGetEncryptedDoc( self, db, doc_id, doc_rev, content, has_conflicts): """ Assert that the document in the database looks correct. """ exp_doc = self.make_document(doc_id, doc_rev, content, has_conflicts=has_conflicts) doc = db.get_doc(doc_id) if is_symmetrically_encrypted(doc.content['raw']): crypt = self._soledad._crypto decrypted = yield crypt.decrypt_doc(doc) doc.set_json(decrypted) self.assertEqual(exp_doc.doc_id, doc.doc_id) self.assertEqual(exp_doc.rev, doc.rev) self.assertEqual(exp_doc.has_conflicts, doc.has_conflicts) self.assertEqual(exp_doc.content, doc.content)
def __atomic_doc_parse(self, doc_info, content, total): doc = Document(doc_info['id'], doc_info['rev'], content) if is_symmetrically_encrypted(content): content = (yield self._crypto.decrypt_doc(doc)).getvalue() elif old_crypto.is_symmetrically_encrypted(doc): content = self._deprecated_crypto.decrypt_doc(doc) doc.set_json(content) # TODO insert blobs here on the blob backend # FIXME: This is wrong. Using the very same SQLite connection object # from multiple threads is dangerous. We should bring the dbpool here # or find an alternative. Deferring to a thread only helps releasing # the reactor for other tasks as this is an IO intensive call. yield threads.deferToThread(self._insert_doc_cb, doc, doc_info['gen'], doc_info['trans_id']) self._received_docs += 1 user_data = {'uuid': self.uuid, 'userid': self.userid} _emit_receive_status(user_data, self._received_docs, total=total)
def __atomic_doc_parse(self, doc_info, content, total): doc = SoledadDocument(doc_info['id'], doc_info['rev'], content) if is_symmetrically_encrypted(content): content = yield self._crypto.decrypt_doc(doc) elif old_crypto.is_symmetrically_encrypted(doc): content = self._deprecated_crypto.decrypt_doc(doc) doc.set_json(content) # TODO insert blobs here on the blob backend # FIXME: This is wrong. Using the very same SQLite connection object # from multiple threads is dangerous. We should bring the dbpool here # or find an alternative. Deferring to a thread only helps releasing # the reactor for other tasks as this is an IO intensive call. yield threads.deferToThread(self._insert_doc_cb, doc, doc_info['gen'], doc_info['trans_id']) self._received_docs += 1 user_data = {'uuid': self.uuid, 'userid': self.userid} _emit_receive_status(user_data, self._received_docs, total=total)