Пример #1
0
    def __init__(self, config):
        """
       :type method: str
       :param config:
       :type config: yowsup.config.v1.config.Config
       """

        self.pvars = []
        self.port = 443
        self.type = "GET"
        self.parser = None
        self.params = []
        self.headers = {}

        self.sent = False
        self.response = None

        self._config = config
        self._p_in = str(config.phone)[len(str(config.cc)):]
        self._axolotlmanager = AxolotlManagerFactory() \
            .get_manager(self._config.phone)  # type: yowsup.axolotl.manager.Axolotlmanager

        if config.expid is None:
            config.expid = WATools.generateDeviceId()

        if config.fdid is None:
            config.fdid = WATools.generatePhoneId()

        if config.client_static_keypair is None:
            config.client_static_keypair = WATools.generateKeyPair()

        self.addParam("cc", config.cc)
        self.addParam("in", self._p_in)
        self.addParam("lg", "en")
        self.addParam("lc", "GB")
        self.addParam("mistyped", "6")
        self.addParam("authkey", self.b64encode(config.client_static_keypair.public.data))
        self.addParam("e_regid", self.b64encode(struct.pack('>I', self._axolotlmanager.registration_id)))
        self.addParam("e_keytype", self.b64encode(b"\x05"))
        self.addParam("e_ident", self.b64encode(self._axolotlmanager.identity.publicKey.serialize()[1:]))

        signedprekey = self._axolotlmanager.load_latest_signed_prekey(generate=True)
        self.addParam("e_skey_id", self.b64encode(struct.pack('>I', signedprekey.getId())[1:]))
        self.addParam("e_skey_val", self.b64encode(signedprekey.getKeyPair().publicKey.serialize()[1:]))
        self.addParam("e_skey_sig", self.b64encode(signedprekey.getSignature()))

        self.addParam("fdid", config.fdid)
        self.addParam("expid", self.b64encode(config.expid))

        self.addParam("network_radio_type", "1")
        self.addParam("simnum", "1")
        self.addParam("hasinrc", "1")
        self.addParam("pid", int(random.uniform(100, 9999)))
        self.addParam("rc", 0)
        if self._config.id:
            self.addParam("id", self._config.id)
    def fromFilePath(fpath, url, mediaType, ip, to, mimeType = None, preview = None, filehash = None, filesize = None):
        mimeType = mimeType or MimeTools.getMIME(fpath)
        filehash = filehash or WATools.getFileHashForUpload(fpath)
        size = filesize or os.path.getsize(fpath)
        fileName = os.path.basename(fpath)

        return DownloadableMediaMessageProtocolEntity(mediaType, mimeType, filehash, url, ip, size, fileName, to = to, preview = preview)
Пример #3
0
 def fromFilePath(fpath, url, mediaType, ip, to, mimeType = None, preview = None, filehash = None, filesize = None):
     mediaType = mediaType or MimeTools.getMIME(fpath)
     filehash = filehash or WATools.getFileHashForUpload2(fpath)
     size = filesize or os.path.getsize(fpath)
     fileName = os.path.basename(fpath)
     return DownloadableMediaMessageProtocolEntity(mediaType, mimeType, filehash, url, ip, size, fileName, to=to,
                                                   preview= preview)
 def fromBuilder(builder):
     url = builder.get("url")
     ip = builder.get("ip")
     assert url, "Url is required"
     mimeType = builder.get("mimetype", MimeTools.getMIME(builder.getOriginalFilepath()))
     filehash = WATools.getFileHashForUpload(builder.getFilepath())
     size = os.path.getsize(builder.getFilepath())
     fileName = os.path.basename(builder.getFilepath())
     return DownloadableMediaMessageProtocolEntity(builder.mediaType, mimeType, filehash, url, ip, size, fileName, to = builder.jid, preview = builder.get("preview"))
Пример #5
0
 def fromBuilder(builder):
     url = builder.get("url")
     ip = builder.get("ip")
     assert url, "Url is required"
     mimeType = builder.get("mimetype", MimeTools.getMIME(builder.getOriginalFilepath()))
     filehash = WATools.getFileHashForUpload2(builder.getFilepath())
     size = os.path.getsize(builder.getFilepath())
     fileName = os.path.basename(builder.getFilepath())
     return DownloadableMediaMessageProtocolEntity(builder.mediaType, mimeType, filehash, url, ip, size, fileName, to = builder.jid, preview = builder.get("preview"))
Пример #6
0
    def send(self, parser = None):
        if self.__id is not None:
            request = WAExistsRequest(self.cc, self.p_in, self.__id)
            result = request.send()
            if result["status"] == "ok":
                return result

        self.__id = WATools.generateIdentity()
        self.addParam("id", self.__id)

        res = super(WACodeRequest, self).send(parser)
        if res["status"] == "sent":
            StorageTools.writeIdentity(self.cc + self.p_in, self.__id)
        return res
Пример #7
0
    def send(self, parser = None):
        if self.__id is not None:
            request = WAExistsRequest(self.cc, self.p_in, self.__id)
            result = request.send()
            if result["status"] == "ok":
                return result

        self.__id = WATools.generateIdentity()
        self.addParam("id", self.__id)

        res = super(WACodeRequest, self).send(parser)
        if res["status"] == "sent":
            StorageTools.writeIdentity(self.cc + self.p_in, self.__id)
        return res
Пример #8
0
    def send(self, parser = None, encrypt=True, preview=False):
        if self. _config.id is not None:
            request = WAExistsRequest(self._config)
            result = request.send(encrypt=encrypt, preview=preview)

            if result:
                if result["status"] == "ok":
                    return result
                elif result["status"] == "fail" and "reason" in result and result["reason"] == "blocked":
                    return result
        else:
            self._config.id = WATools.generateIdentity()
            self.addParam("id", self._config.id)

        res = super(WACodeRequest, self).send(parser, encrypt=encrypt, preview=preview)

        return res
Пример #9
0
def token():
  number = request.args.get('number')
  cc = request.args.get('cc')


  if number is not None:
    if cc is not None:

      in_ = number[len(cc):]
      token = CURRENT_ENV.getToken(in_)
      idx = WATools.generateIdentity()

      return jsonify(status=200, number=number, cc=cc, token=token, identity=quote(idx))
    else:
      return jsonify(status=402, error="Country code is required")
  else:
    return jsonify(status=402, error="Number is required")
Пример #10
0
    def __init__(self, config):
        """
       :type method: str
       :param config:
       :type config: yowsup.config.v1.config.Config
       """

        self.pvars = []
        self.port = 443
        self.type = "GET"
        self.parser = None
        self.params = []
        self.headers = {}

        self.sent = False
        self.response = None

        self._config = config
        self._p_in = str(config.phone)[len(str(config.cc)):]
        self._axolotlmanager = AxolotlManagerFactory() \
            .get_manager(self._config.phone)  # type: yowsup.axolotl.manager.Axolotlmanager

        if config.expid is None:
            config.expid = WATools.generateDeviceId()

        if config.fdid is None:
            config.fdid = WATools.generatePhoneId()

        if config.client_static_keypair is None:
            config.client_static_keypair = WATools.generateKeyPair()

        self.addParam("cc", config.cc)
        self.addParam("in", self._p_in)
        self.addParam("lg", "en")
        self.addParam("lc", "GB")
        self.addParam("mistyped", "6")
        self.addParam("authkey",
                      self.b64encode(config.client_static_keypair.public.data))
        self.addParam(
            "e_regid",
            self.b64encode(
                struct.pack('>I', self._axolotlmanager.registration_id)))
        self.addParam("e_keytype", self.b64encode(b"\x05"))
        self.addParam(
            "e_ident",
            self.b64encode(
                self._axolotlmanager.identity.publicKey.serialize()[1:]))

        signedprekey = self._axolotlmanager.load_latest_signed_prekey(
            generate=True)
        self.addParam(
            "e_skey_id",
            self.b64encode(struct.pack('>I', signedprekey.getId())[1:]))
        self.addParam(
            "e_skey_val",
            self.b64encode(
                signedprekey.getKeyPair().publicKey.serialize()[1:]))
        self.addParam("e_skey_sig",
                      self.b64encode(signedprekey.getSignature()))

        self.addParam("fdid", config.fdid)
        self.addParam("expid", self.b64encode(config.expid))

        self.addParam("network_radio_type", "1")
        self.addParam("simnum", "1")
        self.addParam("hasinrc", "1")
        self.addParam("pid", int(random.uniform(100, 9999)))
        self.addParam("rc", 0)
        if self._config.id:
            self.addParam("id", self._config.id)
Пример #11
0
    def __init__(self, config_or_profile):
        """
       :type method: str
       :param config_or_profile:
       :type config: yowsup.config.v1.config.Config | YowProfile
       """

        self.pvars = []
        self.port = 443
        self.type = "GET"
        self.parser = None
        self.params = []
        self.headers = {}

        self.sent = False
        self.response = None

        if isinstance(config_or_profile, Config):
            logger.warning(
                "Passing Config to WARequest is deprecated, pass a YowProfile instead"
            )
            profile = YowProfile(config_or_profile.phone, config_or_profile)
        else:
            assert isinstance(config_or_profile, YowProfile)
            profile = config_or_profile

        self._config = profile.config
        config = self._config
        self._p_in = str(config.phone)[len(str(config.cc)):]
        self._axolotlmanager = profile.axolotl_manager

        if config.expid is None:
            config.expid = WATools.generateDeviceId()

        if config.fdid is None:
            config.fdid = WATools.generatePhoneId()

        if config.client_static_keypair is None:
            config.client_static_keypair = WATools.generateKeyPair()

        self.addParam("cc", config.cc)
        self.addParam("in", self._p_in)
        self.addParam("lg", "en")
        self.addParam("lc", "GB")
        self.addParam("mistyped", "6")
        self.addParam("authkey",
                      self.b64encode(config.client_static_keypair.public.data))
        self.addParam(
            "e_regid",
            self.b64encode(
                struct.pack('>I', self._axolotlmanager.registration_id)))
        self.addParam("e_keytype", self.b64encode(b"\x05"))
        self.addParam(
            "e_ident",
            self.b64encode(
                self._axolotlmanager.identity.publicKey.serialize()[1:]))

        signedprekey = self._axolotlmanager.load_latest_signed_prekey(
            generate=True)
        self.addParam(
            "e_skey_id",
            self.b64encode(struct.pack('>I', signedprekey.getId())[1:]))
        self.addParam(
            "e_skey_val",
            self.b64encode(
                signedprekey.getKeyPair().publicKey.serialize()[1:]))
        self.addParam("e_skey_sig",
                      self.b64encode(signedprekey.getSignature()))

        self.addParam("fdid", config.fdid)
        self.addParam("expid", self.b64encode(config.expid))

        self.addParam("network_radio_type", "1")
        self.addParam("simnum", "1")
        self.addParam("hasinrc", "1")
        self.addParam("pid", int(random.uniform(100, 9999)))
        self.addParam("rc", 0)
        if self._config.id:
            self.addParam("id", self._config.id)
Пример #12
0
 def getFileHashForUpload(filePath):
     return WATools.getFileHashForUpload(filePath)
Пример #13
0
 def getFileHashForUpload(filePath):
     return WATools.getFileHashForUpload(filePath)