Added a replacement tokes as an entry point for an experiment
This commit is contained in:
parent
ba72e80279
commit
127207414c
16
src/sessionmanager/_sslfixer.py
Normal file
16
src/sessionmanager/_sslfixer.py
Normal file
@ -0,0 +1,16 @@
|
||||
import os
|
||||
import ssl
|
||||
import utils
|
||||
|
||||
try:
|
||||
context = ssl.create_default_context()
|
||||
der_certs = context.get_ca_certs(binary_form=True)
|
||||
pem_certs = [ssl.DER_cert_to_PEM_cert(der) for der in der_certs]
|
||||
path = os.path.join(utils.getBundleDir(), 'nativecacerts.pem')
|
||||
|
||||
with open(path, 'w') as outfile:
|
||||
for pem in pem_certs:
|
||||
outfile.write(pem + '\n')
|
||||
os.environ['REQUESTS_CA_BUNDLE'] = path
|
||||
except:
|
||||
pass
|
93
src/sessionmanager/core.py
Normal file
93
src/sessionmanager/core.py
Normal file
@ -0,0 +1,93 @@
|
||||
import _sslfixer
|
||||
import random
|
||||
import requests
|
||||
import string
|
||||
|
||||
class AuthenticationError(Exception):
|
||||
pass
|
||||
|
||||
class ValidationError(Exception):
|
||||
pass
|
||||
|
||||
class C2DMError(Exception):
|
||||
pass
|
||||
|
||||
client_id = '2685278'
|
||||
client_secret = 'lxhD8OD7dMsqtXIm5IUY'
|
||||
api_ver='5.70'
|
||||
scope = 'all'
|
||||
user_agent = 'KateMobileAndroid/47-427 (Android 6.0.1; SDK 23; armeabi-v7a; samsung SM-G900F; ru)'
|
||||
android_id = '4119748609680577006'
|
||||
android_token = '5228540069896927210'
|
||||
api_url = 'https://api.vk.com/method/'
|
||||
|
||||
def requestAuth(login, password, scope=scope):
|
||||
if not (login or password):
|
||||
raise ValueError
|
||||
url = 'https://oauth.vk.com/token?grant_type=password&client_id='+client_id+'&client_secret='+client_secret+'&username='+login+'&password='+password+'&v='+api_ver+'&scope='+scope
|
||||
headers = {
|
||||
'User-Agent': user_agent
|
||||
}
|
||||
r = requests.get(url, headers=headers)
|
||||
if r.status_code == 200 and 'access_token' in r.text:
|
||||
res = r.json()
|
||||
access_token = res['access_token']
|
||||
user_id = str(res['user_id'])
|
||||
return access_token, user_id
|
||||
else:
|
||||
raise AuthenticationError(r.text)
|
||||
|
||||
def getReceipt(user_id):
|
||||
if not user_id:
|
||||
raise ValueError
|
||||
url = 'https://android.clients.google.com/c2dm/register3'
|
||||
headers = {
|
||||
'Authorization': 'AidLogin {0}:{1}'.format(android_id, android_token),
|
||||
'app': 'com.perm.kate',
|
||||
'Gcm-ver': '11951438',
|
||||
'Gcm-cert': 'ca7036ce4c5abe56b9f4439ea275171ceb0d35a4',
|
||||
#'User-Agent': 'Android-GCM/1.5 (klte NJH47F)',
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
data = {
|
||||
'X-subtype': '54740537194',
|
||||
'X-X-subscription': '54740537194',
|
||||
'X-X-subtype': '54740537194',
|
||||
'X-app_ver': '427',
|
||||
'X-kid': '|ID|1|',
|
||||
#'X-osv': '23',
|
||||
'X-cliv': 'iid-9452000',
|
||||
'X-gmsv': '11951438',
|
||||
'X-X-kid': '|ID|1|',
|
||||
'X-appid': ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(11)),
|
||||
'X-scope': 'id'+user_id,
|
||||
'X-subscription': '54740537194',
|
||||
'X-app_ver_name': '47',
|
||||
'app': 'com.perm.kate',
|
||||
'sender': '54740537194',
|
||||
'device': android_id,
|
||||
'cert': 'ca7036ce4c5abe56b9f4439ea275171ceb0d35a4',
|
||||
'app_ver': '427',
|
||||
'gcm_ver': '11951438'
|
||||
}
|
||||
r = requests.post(url, headers=headers, data=data)
|
||||
if r.status_code == 200 and 'token' in r.text:
|
||||
return r.text[13:]
|
||||
else:
|
||||
raise C2DMError(r.text)
|
||||
|
||||
def validateToken(token, receipt):
|
||||
if not (token or receipt):
|
||||
raise ValueError
|
||||
url = api_url+'auth.refreshToken?access_token='+token+'&receipt='+receipt+'&v='+api_ver
|
||||
headers = {'User-Agent': user_agent}
|
||||
r = requests.get(url, headers=headers)
|
||||
if r.status_code == 200 and 'token' in r.text:
|
||||
res = r.json()
|
||||
received_token = res['response']['token']
|
||||
if token == received_token or received_token is None :
|
||||
raise ValidationError(r.text)
|
||||
else:
|
||||
return received_token
|
||||
else:
|
||||
raise ValidationError(r.text)
|
@ -1,9 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import logging
|
||||
import languageHandler
|
||||
import paths
|
||||
import vkSessionHandler
|
||||
import sound
|
||||
import core
|
||||
from config_utils import Configuration, ConfigurationResetException
|
||||
from pubsub import pub
|
||||
from vk_api.exceptions import LoginRequired, VkApiError
|
||||
@ -84,14 +86,15 @@ class vkSession(object):
|
||||
file_ = "%s/session.conf" % (self.session_id,)
|
||||
# try:
|
||||
log.debug("Creating config file %s" % (file_,))
|
||||
self.settings = Configuration(paths.config_path(file_), paths.app_path("session.defaults"))
|
||||
self.settings = Configuration(os.path.join(paths.config_path(), file_), os.path.join(paths.app_path(), "session.defaults"))
|
||||
self.soundplayer = sound.soundSystem(self.settings["sound"])
|
||||
# except:
|
||||
# log.exception("The session configuration has failed.")
|
||||
|
||||
def login(self):
|
||||
try:
|
||||
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], filename=paths.config_path(self.session_id+"/vkconfig.json"))
|
||||
config_filename = os.path.join(paths.config_path(), self.session_id, "vkconfig.json")
|
||||
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], filename=config_filename)
|
||||
self.settings["vk"]["token"] = self.vk.client._session.access_token
|
||||
self.settings.write()
|
||||
self.logged = True
|
||||
@ -220,3 +223,8 @@ class vkSession(object):
|
||||
log.debug("Getting user identifier...")
|
||||
user = self.vk.client.users.get(fields="uid, first_name, last_name")
|
||||
self.user_id = user[0]["id"]
|
||||
# receipt = core.getReceipt(str(self.user_id))
|
||||
# print receipt
|
||||
# token = core.validateToken(self.vk.session_object.token["access_token"], receipt)
|
||||
# print token
|
||||
# self.vk.session_object.token = dict(access_token=token)
|
Loading…
Reference in New Issue
Block a user