def encrypt_credential_v1(self, raw): if sys.version_info < (3, 0): raw = bytes(py2_encode(raw)) else: raw = bytes(raw, 'utf-8') aes = pyaes.AESModeOfOperationCTR(self.get_device_id_v1()) return Util.base64enc(aes.encrypt(raw))
def login(self): username = self.getCredential('username') password = self.getCredential('password') headers = { 'Host': self.API_HOST, 'User-Agent': self.UA, 'Accept': '*/*', 'Accept-Language': self.ACCEPT_LANGUAGE, 'Accept-Encoding': 'gzip, deflate, br', 'Referer': self.API_HOST_GATEWAY_REFERER, 'Content-Type': 'application/xml', 'Authorization': 'Basic ' + Util.base64enc(username + ":" + Util.base64enc(password)), 'Origin': self.API_HOST_GATEWAY, 'Connection': 'keep-alive', } self.API_DEVICE_ID = self.addon.getSetting('individualization') if self.API_DEVICE_ID == "": self.log("NO REGISTRED DEVICE - generating") self.API_DEVICE_ID = self.generate_device_id() self.addon.setSetting('individualization', str(self.API_DEVICE_ID)) self.log("DEVICE ID: " + self.API_DEVICE_ID) login_hash = Util.hash256_string(self.API_DEVICE_ID + username + password) self.log("LOGIN HASH: " + login_hash) loaded_session = self.load_obj(self.addon_id + "_es_session") if loaded_session is not None: self.log("SAVED SESSION LOADED") if loaded_session["hash"] == login_hash: self.log("HASH IS VALID") if time.time() < (loaded_session["time"] + (self.SESSION_VALIDITY * 60 * 60)): self.log("NOT EXPIRED RESTORING...") self.API_DEVICE_TOKEN = loaded_session["API_DEVICE_TOKEN"] self.API_IDENTITY_GUID = loaded_session[ "API_IDENTITY_GUID"] self.API_ACCOUNT_GUID = loaded_session["API_ACCOUNT_GUID"] self.init_api() loaded_session['time'] = time.time() self.save_obj(loaded_session, self.addon_id + "_es_session") return True data = '<device><type>web</type><deviceId>' + self.API_DEVICE_ID + '</deviceId></device>' response = self.post_to_hbogo( self.API_URL_AUTH_WEBBASIC, headers, data, 'xml', self. max_comm_retry) # last parameter prevent retry on failed login if response is False: return False if response.find('status').text == 'Success': self.API_DEVICE_TOKEN = response.find('token').text self.API_IDENTITY_GUID = response.find('identityGuid').text self.API_ACCOUNT_GUID = response.find('accountGuid').text self.init_api() login_hash = Util.hash256_string( str(self.API_DEVICE_ID) + str(username) + str(password)) self.log("LOGIN HASH: " + login_hash) saved_session = { "hash": login_hash, "API_DEVICE_TOKEN": self.API_DEVICE_TOKEN, "API_IDENTITY_GUID": self.API_IDENTITY_GUID, "API_ACCOUNT_GUID": self.API_ACCOUNT_GUID, "time": time.time() } self.save_obj(saved_session, self.addon_id + "_es_session") return True return False