예제 #1
0
    async def on_POST(self, request: SynapseRequest):
        requester = await self.auth.get_user_by_req(request)

        submission = parse_json_object_from_request(request)

        if "device_id" not in submission:
            raise errors.SynapseError(
                400,
                "device_id missing",
                errcode=errors.Codes.MISSING_PARAM,
            )
        elif not isinstance(submission["device_id"], str):
            raise errors.SynapseError(
                400,
                "device_id must be a string",
                errcode=errors.Codes.INVALID_PARAM,
            )

        result = await self.device_handler.rehydrate_device(
            requester.user.to_string(),
            self.auth.get_access_token_from_request(request),
            submission["device_id"],
        )

        return (200, result)
예제 #2
0
파일: devices.py 프로젝트: ysoffner/synapse
    def on_POST(self, request):
        requester = yield self.auth.get_user_by_req(request)

        try:
            body = servlet.parse_json_object_from_request(request)
        except errors.SynapseError as e:
            if e.errcode == errors.Codes.NOT_JSON:
                # deal with older clients which didn't pass a J*DELETESON dict
                # the same as those that pass an empty dict
                body = {}
            else:
                raise e

        if 'devices' not in body:
            raise errors.SynapseError(400,
                                      "No devices supplied",
                                      errcode=errors.Codes.MISSING_PARAM)

        yield self.auth_handler.validate_user_via_ui_auth(
            requester,
            body,
            self.hs.get_ip_from_request(request),
        )

        yield self.device_handler.delete_devices(
            requester.user.to_string(),
            body['devices'],
        )
        defer.returnValue((200, {}))
예제 #3
0
    def on_POST(self, request):
        try:
            body = servlet.parse_json_object_from_request(request)
        except errors.SynapseError as e:
            if e.errcode == errors.Codes.NOT_JSON:
                # deal with older clients which didn't pass a J*DELETESON dict
                # the same as those that pass an empty dict
                body = {}
            else:
                raise e

        if 'devices' not in body:
            raise errors.SynapseError(400,
                                      "No devices supplied",
                                      errcode=errors.Codes.MISSING_PARAM)

        authed, result, params, _ = yield self.auth_handler.check_auth([
            [constants.LoginType.PASSWORD],
        ], body, self.hs.get_ip_from_request(request))

        if not authed:
            defer.returnValue((401, result))

        requester = yield self.auth.get_user_by_req(request)
        yield self.device_handler.delete_devices(
            requester.user.to_string(),
            body['devices'],
        )
        defer.returnValue((200, {}))
예제 #4
0
    async def on_PUT(self, request: SynapseRequest):
        submission = parse_json_object_from_request(request)
        requester = await self.auth.get_user_by_req(request)

        if "device_data" not in submission:
            raise errors.SynapseError(
                400,
                "device_data missing",
                errcode=errors.Codes.MISSING_PARAM,
            )
        elif not isinstance(submission["device_data"], dict):
            raise errors.SynapseError(
                400,
                "device_data must be an object",
                errcode=errors.Codes.INVALID_PARAM,
            )

        device_id = await self.device_handler.store_dehydrated_device(
            requester.user.to_string(),
            submission["device_data"],
            submission.get("initial_device_display_name", None),
        )
        return 200, {"device_id": device_id}
예제 #5
0
    def query_local_devices(self, query):
        """Get E2E device keys for local users

        Args:
            query (dict[string, list[string]|None): map from user_id to a list
                 of devices to query (None for all devices)

        Returns:
            defer.Deferred: (resolves to dict[string, dict[string, dict]]):
                 map from user_id -> device_id -> device details
        """
        local_query = []

        result_dict = {}
        for user_id, device_ids in query.items():
            if not self.is_mine_id(user_id):
                logger.warning("Request for keys for non-local user %s",
                               user_id)
                raise errors.SynapseError(400, "Not a user here")

            if not device_ids:
                local_query.append((user_id, None))
            else:
                for device_id in device_ids:
                    local_query.append((user_id, device_id))

            # make sure that each queried user appears in the result dict
            result_dict[user_id] = {}

        results = yield self.store.get_e2e_device_keys(local_query)

        # Build the result structure, un-jsonify the results, and add the
        # "unsigned" section
        for user_id, device_keys in results.items():
            for device_id, device_info in device_keys.items():
                r = json.loads(device_info["key_json"])
                r["unsigned"] = {}
                display_name = device_info["device_display_name"]
                if display_name is not None:
                    r["unsigned"]["device_display_name"] = display_name
                result_dict[user_id][device_id] = r

        defer.returnValue(result_dict)