async def do_get(self, url="/labels"): url = 'https://' + self.target_host + url network = Network.get_instance() proxy = network.proxy if network else None async with make_aiohttp_session(proxy) as session: async with session.get(url) as result: return await result.json()
async def get_update_info(self): async with make_aiohttp_session( proxy=self.main_window.network.proxy) as session: async with session.get(UpdateCheck.url) as result: signed_version_dict = await result.json(content_type=None) # example signed_version_dict: # { # "version": "3.9.9", # "signatures": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } version_num = signed_version_dict['version'] sigs = signed_version_dict['signatures'] for address, sig in sigs.items(): if address not in UpdateCheck.VERSION_ANNOUNCEMENT_SIGNING_KEYS: continue sig = base64.b64decode(sig) msg = version_num.encode('utf-8') if ecc.verify_message_with_address( address=address, sig65=sig, message=msg, net=constants.BitcoinMainnet): self.print_error( f"valid sig for version announcement '{version_num}' from address '{address}'" ) break else: raise Exception( 'no valid signature for version announcement') return LooseVersion(version_num.strip())
async def get_update_info(self): async with make_aiohttp_session(proxy=self.main_window.network.proxy) as session: async with session.get(UpdateCheck.url) as result: signed_version_dict = await result.json(content_type=None) # example signed_version_dict: # { # "version": "3.9.9", # "signatures": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } version_num = signed_version_dict['version'] sigs = signed_version_dict['signatures'] for address, sig in sigs.items(): if address not in UpdateCheck.VERSION_ANNOUNCEMENT_SIGNING_KEYS: continue sig = base64.b64decode(sig) msg = version_num.encode('utf-8') if ecc.verify_message_with_address(address=address, sig65=sig, message=msg, net=constants.BitcoinMainnet): self.print_error(f"valid sig for version announcement '{version_num}' from address '{address}'") break else: raise Exception('no valid signature for version announcement') return LooseVersion(version_num.strip())
async def get_update_info(self): # note: Use long timeout here as it is not critical that we get a response fast, # and it's bad not to get an update notification just because we did not wait enough. async with make_aiohttp_session(proxy=self.main_window.network.proxy, timeout=120) as session: async with session.get(UpdateCheck.url) as result: signed_version_dict = await result.json(content_type=None) # example signed_version_dict: # { # "version": "3.9.9", # "signatures": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } version_num = signed_version_dict['version'] sigs = signed_version_dict['signatures'] # for address, sig in sigs.items(): # if address not in UpdateCheck.VERSION_ANNOUNCEMENT_SIGNING_KEYS: # continue # sig = base64.b64decode(sig) # msg = version_num.encode('utf-8') # if ecc.verify_message_with_address(address=address, sig65=sig, message=msg, # net=constants.BitcoinMainnet): # self.logger.info(f"valid sig for version announcement '{version_num}' from address '{address}'") # break # else: # raise Exception('no valid signature for version announcement') return LooseVersion(version_num.strip())
async def do_post(self, url="/labels", data=None): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.proxy) as session: async with session.post(url, json=data) as result: try: return await result.json() except Exception as e: raise Exception('Could not decode: ' + await result.text()) from e
async def do_get(self, url="/labels"): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.proxy) as session: async with session.get(url) as result: return await result.json()