Example #1
0
    def new_token(self, internal=True):
        password = self._decryptedpw()
        data = self.webrequest(self.baseAuthUrl + self.authUrl,
                               internal=internal,
                               data=WebFormData(Email=self.name,
                                                Passwd=password,
                                                PersistentCookie='false',
                                                accountType='HOSTED_OR_GOOGLE',
                                                skipvpage='true'))
        if not data:
            return False

        if not data or data.find('Error=badauth') != -1:
            log.warning('Invalid username or password: badauth token')
            self.bad_pw()
            return False
        d1 = dict(b.split('=') for b in data.split())
        d1.update(Session='true', skipvpage='true', service='gaia')
        token = self.webrequest(self.baseAuthUrl + self.tokenUrl,
                                WebFormData(**d1))
        token = token.strip()
        if not internal:
            self.external_token = token

        return token
Example #2
0
def get_login_cookie(login, password, api="icq.net", api2=None):
    if api2 is None:
        api2 = api
    r = get_login_data(login, password, api2)
    sessionSecret = r["response"]["data"]["sessionSecret"]
    token = r["response"]["data"]["token"]["a"]
    sessionKey = hmac_sha256_base64(sessionSecret, password)
    uri = "https://api.oscar.%s/aim/startOSCARSession" % api

    d = dict(a=token, f="json", k=ICQ_API_KEY, ts=r["response"]["data"]["hostTime"], useTLS=1)

    queryString = WebFormData(d=LazySortedDict(d)).replace("+", "%20")
    hashData = "GET&" + urllib.quote(uri, safe="") + "&" + queryString.encode("url")

    digest = hmac_sha256_base64(hashData, sessionKey)

    url = uri + "?" + queryString + "&sig_sha256=" + digest
    ret = simplejson.loads(wget(url))
    return ret
Example #3
0
    def __call__(self, method, callback=None, **kwds):
        callargs = {
            'session_token': self.session_token,
            'application_id': 'user',
            'format': 'json'
        }
        callargs.update(method=method)
        callargs.update(kwds)

        def success(req, resp):
            resp = resp.read()
            json = simplejson.loads(resp)
            if json['stat'] == 'ok':
                callback.success(json['result'] if 'result' in
                                 json else json['results'])
            elif json['stat'] == 'fail':
                raise Exception('API call failed %r', json)
            elif json['stat'] == 'nobot':
                d = {
                    'x*=': (lambda x, y: x * y),
                    'x-=': (lambda x, y: x - y),
                    'x+=': (lambda x, y: x + y),
                    'x=x%': (lambda x, y: x % y)
                }

                result = json['result']

                fnc = result['jsfunc'].replace('(function(){var ', '').replace(
                    'return x;})()', '')
                init = fnc.split(';')[0]
                rest = fnc.split(';')[1:]
                x = int(init[2:])
                for val in rest:
                    for key in d:
                        if val.startswith(key):
                            y = int(val[len(key):])
                            x = d[key](x, y)

                self.security.nobot.submitAnswer(answer=x,
                                                 origCallObj=simplejson.dumps(
                                                     result['origCallObj']),
                                                 callback=callback)

        self.opener.open(self.API_URL,
                         WebFormData(**callargs),
                         success=success,
                         error=callback.error)
Example #4
0
    def __call__(self, method, callback=None, **kwds):
        callargs = {
            'session_token': self.session_token,
            'user_id': self.user_id
        }
        callargs.update(method=method)
        if 'event_types' in kwds:
            kwds['event_types'] = simplejson.dumps(kwds['event_types'])
        callargs.update(kwds)

        req = AsyncHttp.HTTPRequest(self.REALTIME_URL, WebFormData(**callargs),
                                    {'X-T-Uid': self.user_id})

        def success(req, resp):
            resp = resp.read()

            # TODO temporary until prod nodeServer gets updated
            if resp.startswith('undefined'):
                resp = resp[10:-2]

            json = simplejson.loads(resp)
            data = json['data']

            if method == 'query_event_id':
                if json['status'] == 'ok':
                    log.info('Realtime initialization successful')
                    callback.success(data)
                else:
                    log.warning('Realtime initialization failed')
                    callback.error()

            elif method == 'register_client':
                if 'success' in json:
                    log.info('Realtime pushed data %r', data)
                    callback.success(data)
                elif data[
                        'message'] == 'Authentication failed: Bad session token.':
                    log.warning(
                        "We're likely active on a browser, hop on their userObj"
                    )
                    callback.error()
                else:
                    log.warning('Realtime register failed %r', data)
                    callback.error()

        self.opener.open(req, success=success, error=callback.error)
Example #5
0
 def challenge(self, challenge):
     in_params = WebFormData.parse(challenge, utf8=True)
     out_params = {'nonce': in_params['nonce'].encode('utf-8')}
     out_params = self.api.prepare_call(in_params['method'].encode('utf-8'), **out_params)
     return Response(out_params)
Example #6
0
 def challenge(self, challenge):
     in_params = WebFormData.parse(challenge, utf8=True)
     out_params = {'nonce': in_params['nonce'].encode('utf-8')}
     out_params = self.api.prepare_call(in_params['method'].encode('utf-8'),
                                        **out_params)
     return Response(out_params)