Example #1
0
    def on_auth(self, event):
        logger.debug("Received auth event")
        credentials = event.getArg("credentials")
        self._username, local_static = int(credentials[0]), credentials[1]
        config = self._config_manager.load(
            self._username)  # type: yowsup.config.v1.config.Config
        # event's keypair will override config's keypair
        local_static = local_static or config.client_static_keypair
        if type(local_static) is bytes:
            local_static = KeyPair.from_bytes(local_static)
        assert type(local_static) is KeyPair
        passive = event.getArg('passive')

        self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

        if config.edge_routing_info:
            self.toLower(self.EDGE_HEADER)
            self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)
            self.toLower(config.edge_routing_info)
            self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

        self.toLower(self.HEADER)
        self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)

        remote_static = config.server_static_public

        self._rs = remote_static
        yowsupenv = YowsupEnv.getCurrent()
        client_config = ClientConfig(
            username=self._username,
            passive=passive,
            useragent=UserAgentConfig(platform=0,
                                      app_version="2.19.51",
                                      mcc=config.mcc,
                                      mnc=config.mnc,
                                      os_version=yowsupenv.getOSVersion(),
                                      manufacturer=yowsupenv.getManufacturer(),
                                      device=yowsupenv.getDeviceName(),
                                      os_build_number=yowsupenv.getOSVersion(),
                                      phone_id=config.fdid,
                                      locale_lang="en",
                                      locale_country="US"),
            pushname=config.pushname or self.DEFAULT_PUSHNAME,
            short_connect=True)
        if not self._in_handshake():
            logger.debug("Performing handshake [username= %d, passive=%s]" %
                         (self._username, passive))
            self._handshake_worker = WANoiseProtocolHandshakeWorker(
                self._wa_noiseprotocol,
                self._stream,
                client_config,
                local_static,
                remote_static,
            )
            logger.debug("Starting handshake worker")
            self._stream.set_events_callback(self._handle_stream_event)
            self._handshake_worker.start()
Example #2
0
    def on_auth(self, event):
        logger.debug("Received auth event")
        self._profile = self.getProp("profile")
        config = self._profile.config  # type: yowsup.config.v1.config.Config
        # event's keypair will override config's keypair
        local_static = config.client_static_keypair
        username = int(self._profile.username)

        if local_static is None:
            logger.error(
                "client_static_keypair is not defined in specified config, disconnecting"
            )
            self.broadcastEvent(
                YowLayerEvent(
                    YowNetworkLayer.EVENT_STATE_DISCONNECT,
                    reason=
                    "client_static_keypair is not defined in specified config")
            )
        else:
            if type(local_static) is bytes:
                local_static = KeyPair.from_bytes(local_static)
            assert type(local_static) is KeyPair, type(local_static)
            passive = event.getArg('passive')

            self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

            if config.edge_routing_info:
                self.toLower(self.EDGE_HEADER)
                self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)
                self.toLower(config.edge_routing_info)
                self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

            self.toLower(self.HEADER)
            self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)

            remote_static = config.server_static_public

            self._rs = remote_static
            yowsupenv = YowsupEnv.getCurrent()
            client_config = ClientConfig(
                username=username,
                passive=passive,
                useragent=UserAgentConfig(
                    platform=0,
                    app_version=yowsupenv.getVersion(),
                    mcc=config.mcc or "000",
                    mnc=config.mnc or "000",
                    os_version=yowsupenv.getOSVersion(),
                    manufacturer=yowsupenv.getManufacturer(),
                    device=yowsupenv.getDeviceName(),
                    os_build_number=yowsupenv.getOSVersion(),
                    phone_id=config.fdid or "",
                    locale_lang="en",
                    locale_country="US"),
                pushname=config.pushname or self.DEFAULT_PUSHNAME,
                short_connect=True)
            if not self._in_handshake():
                logger.debug(
                    "Performing handshake [username= %d, passive=%s]" %
                    (username, passive))
                self._handshake_worker = WANoiseProtocolHandshakeWorker(
                    self._wa_noiseprotocol, self._stream, client_config,
                    local_static, remote_static, self.on_handshake_finished)
                logger.debug("Starting handshake worker")
                self._stream.set_events_callback(self._handle_stream_event)
                self._handshake_worker.start()