Beispiel #1
0
    def set_profile(self):

        # If default profile is not set, then ask the user
        if not globals.get_setting("default_profile"):
            profile_id = self.get_user_profile()

        url = "https://sentv-user-ext.totsuko.tv/sentv_user_ext/ws/v2/profile/" + globals.get_setting(
            "default_profile")

        headers = {
            "User-Agent": globals.UA_ANDROID_TV,
            "reqPayload": self.reqPayload,
            "Accept": "*/*",
            "Origin": "https://themis.dl.playstation.net",
            "Host": "sentv-user-ext.totsuko.tv",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "X-Requested-With": "com.snei.vue.atv"
        }

        r = requests.get(url, headers=headers, verify=self.verify)
        self.EPGreqPayload = str(r.headers['reqPayload'])
        globals.save_setting("EPGreqPayload", self.EPGreqPayload)
        auth_time = r.json()['header']['time_stamp']
        globals.save_setting("last_auth", auth_time)
Beispiel #2
0
    def parse_settings_file(self):

        dataFile = open(globals.DATA_FILE, "a+")
        settingsFileJson = "{}"

        try:
            dataFileContents = json.load(dataFile)
        except:
            print(TAG + "No valid JSON found, probably a first run")
            dataFile.seek(0, 0)
            dataFile.truncate()
            dataFile.write("{}")
            dataFile.close()

        if not globals.get_setting("device_id"):
            self.create_device_id()
        else:
            self.device_id = globals.get_setting("device_id")

        if not globals.get_setting("username"):
            globals.save_setting("username", raw_input("Username: "******"username")

        if not globals.get_setting("password"):
            globals.save_setting("password", getpass.getpass("Password: "******"password")

        if globals.get_setting("npsso"):
            self.npsso = globals.get_setting("npsso")

        if globals.get_setting("reqPayload"):
            self.reqPayload = globals.get_setting("reqPayload")
Beispiel #3
0
    def create_device_id(self):

        if (self.device_id == None):
            android_id = ''.join(
                random.choice('0123456789abcdef') for i in range(16))
            android_id = android_id.rjust(30, '0')
            manufacturer = 'Asus'
            model = 'Nexus 7'
            manf_model = ":%s:%s" % (manufacturer.rjust(
                10, ' '), model.rjust(10, ' '))
            manf_model = manf_model.encode("hex").upper()
            zero = '0'
            device_id = "0000%s%s01a8%s%s" % ("0007", "0002", android_id,
                                              manf_model + zero.ljust(32, '0'))

            print(TAG + "Device ID generated " + device_id)

            globals.save_setting("device_id", device_id)
Beispiel #4
0
    def two_step_verification(self, ticket_uuid):
        code = raw_input("Code: ")
        if code == '': sys.exit()

        url = globals.API_URL + '/sso_cookie'

        headers = {
            "Accept":
            "*/*",
            "Content-type":
            "application/x-www-form-urlencoded",
            "Origin":
            "https://id.sonyentertainmentnetwork.com",
            "Accept-Language":
            "en-US, en;q=0.8",
            "User-Agent":
            globals.UA_ANDROID_TV,
            "Connection":
            "Keep-Alive",
            "Referer":
            "https://id.sonyentertainmentnetwork.com/signin/?service_entity=urn:service-entity:psn&ui=pr&service_logo=ps&response_type=code&scope=psn:s2s&client_id="
            + globals.REQ_CLIENT_ID +
            "&request_locale=en_US&redirect_uri=https://io.playstation.com/playstation/psn/acceptLogin&error=login_required&error_code=4165&error_description=User+is+not+authenticated"
        }
        payload = 'authentication_type=two_step&ticket_uuid=' + ticket_uuid + '&code=' + code + '&client_id=' + globals.LOGIN_CLIENT_ID
        r = requests.post(url,
                          headers=headers,
                          cookies=globals.load_cookies(),
                          data=payload,
                          verify=verify)
        json_source = r.json()
        globals.save_cookies(r.cookies)

        if 'npsso' in json_source:
            npsso = json_source['npsso']
            globals.save_setting("npsso", json_source['npsso'])
            print(TAG + "Two factor login success")
        elif 'error_description' in json_source:
            print(TAG + "[-] ERROR: Login error - " +
                  json_source['error_description'])
            sys.exit()
        else:
            print(TAG + "[-] ERROR: Login error (generic)")
            sys.exit()
Beispiel #5
0
    def login(self):
        url = globals.API_URL + '/ssocookie'  #request a single sign on cookie

        headers = {
            "Accept": "*/*",
            "Content-type": "application/x-www-form-urlencoded",
            "Origin": "https://id.sonyentertainmentnetwork.com",
            "Accept-Language": "en-US, en; q=0.8",
            "Accept-Encoding": "deflate",
            "User-Agent": globals.UA_ANDROID_TV,
            "X-Requested-With": "com.snei.vue.atv",
            "Connection": "Keep-Alive"
        }

        payload = "authentication_type=password&username="******"&password="******"&client_id=" + globals.ANDROID_TV_CLIENT_ID
        r = requests.post(url,
                          headers=headers,
                          cookies=globals.load_cookies(),
                          data=payload,
                          verify=self.verify)
        json_source = r.json()
        globals.save_cookies(r.cookies)

        if 'npsso' in json_source:
            npsso = json_source['npsso']
            globals.save_setting('npsso', npsso)
            self.set_profile()
            print(TAG + "Login success")
        elif 'authentication_type' in json_source:
            if json_source['authentication_type'] == 'two_step':
                ticket_uuid = json_source['ticket_uuid']
                self.two_step_verification(ticket_uuid)
        elif 'error_description' in json_source:
            print(TAG + "[-] ERROR: Login error - " +
                  json_source['error_description'])
            sys.exit()
        else:
            #something bas must have happened
            print(TAG + "[-] ERROR: Login error (generic)")
            sys.exit()

        self.write_req_payload()
Beispiel #6
0
    def authorize_device(self):
        url = "https://sentv-user-auth.totsuko.tv/sentv_user_auth/ws/oauth2/token"
        url += "?device_type_id=" + globals.DEVICE_TYPE
        url += "&device_id=" + self.device_id
        url += "&code=" + self.get_grant_code()  #TODO: Implement function
        url += "&redirect_uri=" + urllib.quote_plus(globals.THEMIS)

        headers = {
            "Origin": "https://themis.dl.playstation.net",
            "User-Agent": globals.UA_ANDROID_TV,
            "Accept": "*/*",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "X-Requested-With": "com.snei.vue.atv"
        }

        # r = requests.get(url, headers=headers, verify=self.verify)
        # device_status = str(r.json()["body"]["status"])

        # print TAG + "Device Status = " + device_status

        if self.reqPayload != '':
            headers['reauth'] = '1'
            headers['reqPayload'] = self.reqPayload

        # if device_status == "UNAUTHORIZED":
        #     auth_error = str(r.json()['header']['error']['message'])
        #     error_code = str(r.json()['header']['error']['code'])
        #     print TAG + "Auth Error : " + auth_error + "(" + error_code + ")"

        r = requests.get(url, headers=headers, verify=self.verify)
        if 'reqPayload' in r.headers:
            self.reqPayload = str(r.headers['reqPayload'])
            globals.save_setting("reqPayload", self.reqPayload)
            auth_time = r.json()['header']['time_stamp']
            globals.save_setting("last_auth", auth_time)
            print TAG + "setting last auth time"

        else:
            print(TAG + "[-] ERROR: Could not authorize device: reqPayload: " +
                  str(self.reqPayload))
            sys.exit()
Beispiel #7
0
    def get_user_profile(self):
        url = "https://sentv-user-ext.totsuko.tv/sentv_user_ext/ws/v2/profile/ids"

        headers = {
            "User-Agent": globals.UA_ANDROID_TV,
            "reqPayload": self.reqPayload,
            "Accept": "*/*",
            "Origin": "https://themis.dl.playstation.net",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "X-Requested-With": "com.snei.vue.atv"
        }

        r = requests.get(url, headers=headers, verify=self.verify)

        if 'body' in r.json() and 'profiles' in r.json()['body']:
            profiles = r.json()['body']['profiles']
            prof_dict = {}
            prof_list = []
            print(TAG + "Profile not set getting available profiles")
            for profile in profiles:
                prof_dict[str(profile['profile_name'])] = str(
                    profile['profile_id'])
                prof_list.append(str(profile['profile_name']))
                print(TAG + "Profile Name: " + str(profile['profile_name']))

            selected_profile = raw_input("Please enter profile name: ")
            while selected_profile not in prof_list:
                print(TAG + "Invalid profile name")
                selected_profile = raw_input("Please enter profile name: ")

            globals.save_setting("default_profile",
                                 str(prof_dict[selected_profile]))
        else:
            print TAG + "ERROR: Could not retrieve profile list"
            sys.exit()