Beispiel #1
0
def encrypt_doc_task(doc_id, doc_rev, content, key, secret):
    """
    Encrypt the content of the given document.

    :param doc_id: The document id.
    :type doc_id: str
    :param doc_rev: The document revision.
    :type doc_rev: str
    :param content: The serialized content of the document.
    :type content: str
    :param key: The encryption key.
    :type key: str
    :param secret: The Soledad storage secret (used for MAC auth).
    :type secret: str

    :return: A tuple containing the doc id, revision and encrypted content.
    :rtype: tuple(str, str, str)
    """
    encrypted_content = encrypt_docstr(content, doc_id, doc_rev, key, secret)
    return doc_id, doc_rev, encrypted_content
Beispiel #2
0
def encrypt_doc_task(doc_id, doc_rev, content, key, secret):
    """
    Encrypt the content of the given document.

    :param doc_id: The document id.
    :type doc_id: str
    :param doc_rev: The document revision.
    :type doc_rev: str
    :param content: The serialized content of the document.
    :type content: str
    :param key: The encryption key.
    :type key: str
    :param secret: The Soledad storage secret (used for MAC auth).
    :type secret: str

    :return: A tuple containing the doc id, revision and encrypted content.
    :rtype: tuple(str, str, str)
    """
    encrypted_content = encrypt_docstr(content, doc_id, doc_rev, key, secret)
    return doc_id, doc_rev, encrypted_content
Beispiel #3
0
    def test_extra_comma(self):
        """
        Test adapted to use encrypted content.
        """
        doc = SoledadDocument('i', rev='r')
        doc.content = {}
        _crypto = self._soledad._crypto
        key = _crypto.doc_passphrase(doc.doc_id)
        secret = _crypto.secret

        enc_json = crypto.encrypt_docstr(doc.get_json(), doc.doc_id, doc.rev,
                                         key, secret)

        with self.assertRaises(u1db.errors.BrokenSyncStream):
            self.target._parse_received_doc_response("[\r\n{},\r\n]")

        with self.assertRaises(u1db.errors.BrokenSyncStream):
            self.target._parse_received_doc_response(
                ('[\r\n{},\r\n{"id": "i", "rev": "r", ' +
                 '"content": %s, "gen": 3, "trans_id": "T-sid"}' + ',\r\n]') %
                json.dumps(enc_json))
Beispiel #4
0
    def test_extra_comma(self):
        """
        Test adapted to use encrypted content.
        """
        doc = SoledadDocument('i', rev='r')
        doc.content = {}
        _crypto = self._soledad._crypto
        key = _crypto.doc_passphrase(doc.doc_id)
        secret = _crypto.secret

        enc_json = crypto.encrypt_docstr(
            doc.get_json(), doc.doc_id, doc.rev,
            key, secret)

        with self.assertRaises(u1db.errors.BrokenSyncStream):
            self.target._parse_received_doc_response("[\r\n{},\r\n]")

        with self.assertRaises(u1db.errors.BrokenSyncStream):
            self.target._parse_received_doc_response(
                ('[\r\n{},\r\n{"id": "i", "rev": "r", ' +
                 '"content": %s, "gen": 3, "trans_id": "T-sid"}' +
                 ',\r\n]') % json.dumps(enc_json))
Beispiel #5
0
    def test_extra_comma(self):
        """
        Test adapted to use encrypted content.
        """
        doc = SoledadDocument('i', rev='r')
        doc.content = {}
        _crypto = self._soledad._crypto
        key = _crypto.doc_passphrase(doc.doc_id)
        secret = _crypto.secret

        enc_json = crypto.encrypt_docstr(doc.get_json(), doc.doc_id, doc.rev,
                                         key, secret)
        tgt = target.SoledadSyncTarget("http://foo/foo",
                                       crypto=self._soledad._crypto)

        self.assertRaises(u1db.errors.BrokenSyncStream, tgt._parse_sync_stream,
                          "[\r\n{},\r\n]", None)
        self.assertRaises(
            u1db.errors.BrokenSyncStream, tgt._parse_sync_stream,
            '[\r\n{},\r\n{"id": "i", "rev": "r", '
            '"content": %s, "gen": 3, "trans_id": "T-sid"}'
            ',\r\n]' % json.dumps(enc_json), lambda doc, gen, trans_id: None)
Beispiel #6
0
    def test_extra_comma(self):
        """
        Test adapted to use encrypted content.
        """
        doc = SoledadDocument('i', rev='r')
        doc.content = {}
        _crypto = self._soledad._crypto
        key = _crypto.doc_passphrase(doc.doc_id)
        secret = _crypto.secret

        enc_json = crypto.encrypt_docstr(
            doc.get_json(), doc.doc_id, doc.rev,
            key, secret)
        tgt = target.SoledadSyncTarget(
            "http://foo/foo", crypto=self._soledad._crypto)

        self.assertRaises(u1db.errors.BrokenSyncStream,
                          tgt._parse_sync_stream, "[\r\n{},\r\n]", None)
        self.assertRaises(u1db.errors.BrokenSyncStream,
                          tgt._parse_sync_stream,
                          '[\r\n{},\r\n{"id": "i", "rev": "r", '
                          '"content": %s, "gen": 3, "trans_id": "T-sid"}'
                          ',\r\n]' % json.dumps(enc_json),
                          lambda doc, gen, trans_id: None)