示例#1
0
    def _put_secrets_in_shared_db(self):
        """
        Assert local keys are the same as shared db's ones.

        Try to fetch keys from shared recovery database. If they already exist
        in the remote db, assert that that data is the same as local data.
        Otherwise, upload keys to shared recovery database.
        """
        soledad_assert(
            self._has_secret(),
            'Tried to send keys to server but they don\'t exist in local '
            'storage.')
        # try to get secrets doc from server, otherwise create it
        doc = self._get_secrets_from_shared_db()
        if doc is None:
            doc = document.SoledadDocument(
                doc_id=self._shared_db_doc_id())
        # fill doc with encrypted secrets
        doc.content = self._export_recovery_document()
        # upload secrets to server
        user_data = self._get_user_data()
        events.emit_async(events.SOLEDAD_UPLOADING_KEYS, user_data)
        db = self._shared_db
        if not db:
            logger.warning('No shared db found')
            return
        db.put_doc(doc)
        events.emit_async(events.SOLEDAD_DONE_UPLOADING_KEYS, user_data)
示例#2
0
文件: fetch.py 项目: Moscarda/soledad
def _emit_receive_status(received_docs, total):
    content = {'received': received_docs, 'total': total}
    emit_async(SOLEDAD_SYNC_RECEIVE_STATUS, content)

    if received_docs % 20 == 0:
        msg = "%d/%d" % (received_docs, total)
        logger.debug("Sync receive status: %s" % msg)
示例#3
0
    def _put_secrets_in_shared_db(self):
        """
        Assert local keys are the same as shared db's ones.

        Try to fetch keys from shared recovery database. If they already exist
        in the remote db, assert that that data is the same as local data.
        Otherwise, upload keys to shared recovery database.
        """
        soledad_assert(
            self._has_secret(),
            'Tried to send keys to server but they don\'t exist in local '
            'storage.')
        # try to get secrets doc from server, otherwise create it
        doc = self._get_secrets_from_shared_db()
        if doc is None:
            doc = document.SoledadDocument(doc_id=self._shared_db_doc_id())
        # fill doc with encrypted secrets
        doc.content = self._export_recovery_document()
        # upload secrets to server
        user_data = self._get_user_data()
        events.emit_async(events.SOLEDAD_UPLOADING_KEYS, user_data)
        db = self._shared_db
        if not db:
            logger.warning('No shared db found')
            return
        db.put_doc(doc)
        events.emit_async(events.SOLEDAD_DONE_UPLOADING_KEYS, user_data)
示例#4
0
def _emit_receive_status(user_data, received_docs, total):
    content = {'received': received_docs, 'total': total}
    emit_async(SOLEDAD_SYNC_RECEIVE_STATUS, user_data, content)

    if received_docs % 20 == 0:
        msg = "%d/%d" % (received_docs, total)
        logger.debug("Sync receive status: %s" % msg)
示例#5
0
    def _get_secrets_from_shared_db(self):
        """
        Retrieve the document with encrypted key material from the shared
        database.

        :return: a document with encrypted key material in its contents
        :rtype: document.SoledadDocument
        """
        events.emit_async(events.SOLEDAD_DOWNLOADING_KEYS, self._uuid)
        db = self._shared_db
        if not db:
            logger.warning('No shared db found')
            return
        doc = db.get_doc(self._shared_db_doc_id())
        events.emit_async(events.SOLEDAD_DONE_DOWNLOADING_KEYS, self._uuid)
        return doc
示例#6
0
        def _decorated(self, *args, **kwargs):

            # emit starting event
            user_data = self._user_data
            name = 'SOLEDAD_' + verb.upper() + '_KEYS'
            event = getattr(events, name)
            events.emit_async(event, user_data)

            # run the method
            result = method(self, *args, **kwargs)

            # emit a finished event
            name = 'SOLEDAD_DONE_' + verb.upper() + '_KEYS'
            event = getattr(events, name)
            events.emit_async(event, user_data)

            return result
示例#7
0
文件: util.py 项目: leapcode/soledad
        def _decorated(self, *args, **kwargs):

            # emit starting event
            user_data = self._user_data
            name = 'SOLEDAD_' + verb.upper() + '_KEYS'
            event = getattr(events, name)
            events.emit_async(event, user_data)

            # run the method
            result = method(self, *args, **kwargs)

            # emit a finished event
            name = 'SOLEDAD_DONE_' + verb.upper() + '_KEYS'
            event = getattr(events, name)
            events.emit_async(event, user_data)

            return result
示例#8
0
    def _get_secrets_from_shared_db(self):
        """
        Retrieve the document with encrypted key material from the shared
        database.

        :return: a document with encrypted key material in its contents
        :rtype: document.SoledadDocument
        """
        user_data = self._get_user_data()
        events.emit_async(events.SOLEDAD_DOWNLOADING_KEYS, user_data)
        db = self._shared_db
        if not db:
            logger.warning('No shared db found')
            return
        doc = db.get_doc(self._shared_db_doc_id())
        user_data = {'userid': self._userid, 'uuid': self._uuid}
        events.emit_async(events.SOLEDAD_DONE_DOWNLOADING_KEYS, user_data)
        return doc
示例#9
0
    def _gen_secret(self):
        """
        Generate a secret for symmetric encryption and store in a local
        encrypted file.

        This method emits the following events.signals:

            * SOLEDAD_CREATING_KEYS
            * SOLEDAD_DONE_CREATING_KEYS

        :return: The id of the generated secret.
        :rtype: str
        """
        events.emit_async(events.SOLEDAD_CREATING_KEYS, self._uuid)
        # generate random secret
        secret = os.urandom(self.GEN_SECRET_LENGTH)
        secret_id = sha256(secret).hexdigest()
        self._secrets[secret_id] = secret
        self._store_secrets()
        events.emit_async(events.SOLEDAD_DONE_CREATING_KEYS, self._uuid)
        return secret_id
示例#10
0
    def _gen_secret(self):
        """
        Generate a secret for symmetric encryption and store in a local
        encrypted file.

        This method emits the following events.signals:

            * SOLEDAD_CREATING_KEYS
            * SOLEDAD_DONE_CREATING_KEYS

        :return: The id of the generated secret.
        :rtype: str
        """
        user_data = self._get_user_data()
        events.emit_async(events.SOLEDAD_CREATING_KEYS, user_data)
        # generate random secret
        secret = os.urandom(self.GEN_SECRET_LENGTH)
        secret_id = sha256(secret).hexdigest()
        self._secrets[secret_id] = secret
        self._store_secrets()
        events.emit_async(events.SOLEDAD_DONE_CREATING_KEYS, user_data)
        return secret_id
示例#11
0
文件: api.py 项目: Meistache/soledad
 def _emit_done_data_sync(passthrough):
     user_data = {'uuid': self.uuid, 'userid': self.userid}
     soledad_events.emit_async(
         soledad_events.SOLEDAD_DONE_DATA_SYNC, user_data)
     return passthrough
示例#12
0
def _emit_send_status(user_data, idx, total):
    content = {'sent': idx, 'total': total}
    emit_async(SOLEDAD_SYNC_SEND_STATUS, user_data, content)

    msg = "%d/%d" % (idx, total)
    logger.debug("Sync send status: %s" % msg)
示例#13
0
文件: send.py 项目: Meistache/soledad
def _emit_send_status(user_data, idx, total):
    content = {'sent': idx, 'total': total}
    emit_async(SOLEDAD_SYNC_SEND_STATUS, user_data, content)

    msg = "%d/%d" % (idx, total)
    logger.debug("Sync send status: %s" % msg)
示例#14
0
文件: api.py 项目: DarkDare/soledad
 def _emit_done_data_sync(passthrough):
     user_data = {'uuid': self.uuid, 'userid': self.userid}
     soledad_events.emit_async(
         soledad_events.SOLEDAD_DONE_DATA_SYNC, user_data)
     return passthrough
示例#15
0
文件: api.py 项目: Moscarda/soledad
 def _emit_done_data_sync(passthrough):
     soledad_events.emit_async(
         soledad_events.SOLEDAD_DONE_DATA_SYNC, self.uuid)
     return passthrough