From dce980c4af4824b5592e9d9c18f69c311de9da23 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sat, 9 Jun 2018 00:18:57 -0500 Subject: [PATCH] Remove ssl settings --- resources/lib/downloadutils.py | 60 +++++++++++++--------------------- resources/lib/userclient.py | 17 +--------- resources/settings.xml | 4 +-- 3 files changed, 26 insertions(+), 55 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 11faa6d7..c6b0447a 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -23,6 +23,11 @@ log = logging.getLogger("EMBY."+__name__) ################################################################################################## +class HTTPException(Exception): + # Emby HTTP exception + def __init__(self, status): + self.status = status + class DownloadUtils(object): @@ -56,14 +61,13 @@ class DownloadUtils(object): def get_token(self): return self._get_session_info()['Token'] - def add_server(self, server, ssl): + def add_server(self, server): # Reserved for userclient only server_id = server['Id'] info = { 'UserId': server['UserId'], 'Server': connectionmanager.getServerAddress(server, server['LastConnectionMode']), 'Token': server['AccessToken'], - 'SSL': ssl } for server_info in self.servers: if server_info == server_id: @@ -158,10 +162,9 @@ class DownloadUtils(object): # Attach authenticated header to the session session = requests.Session() session.headers = self.get_header() - session.verify = self.session['SSL'] # Retry connections to the server - session.mount("http://", requests.adapters.HTTPAdapter(max_retries=1)) - session.mount("https://", requests.adapters.HTTPAdapter(max_retries=1)) + session.mount("http://", requests.adapters.HTTPAdapter(max_retries=3)) + session.mount("https://", requests.adapters.HTTPAdapter(max_retries=3)) self.session_requests = session log.info("requests session started on: %s", self.session['Server']) @@ -227,16 +230,13 @@ class DownloadUtils(object): if requires_server and (not server or not server.get("Server") or not server.get("UserId")): log.info("Aborting download, Server Details Error: %s url=%s" % (server, url)) - exc = Exception("Aborting download, Server Details Error: %s url=%s" % (server, url)) - exc.quiet = True - raise exc + raise Exception("Aborting download, Server Details Error: %s url=%s" % (server, url)) if server_id is None and self.session_requests is not None: # Main server session = self.session_requests else: session = requests kwargs.update({ - 'verify': server['SSL'], 'headers': self.get_header(server_id, authenticate) }) @@ -247,9 +247,7 @@ class DownloadUtils(object): # does the URL look ok if url.startswith('/'): - exc = Exception("URL Error: " + url) - exc.quiet = True - raise exc + raise Exception("URL Error: " + url) ##### PREPARE REQUEST ##### kwargs.update({ @@ -263,6 +261,8 @@ class DownloadUtils(object): log.debug(kwargs) response = self._requests(action_type, session, **kwargs) #response = requests.get('http://httpbin.org/status/400') + if window('emby_test') == "false": + raise requests.exceptions.ConnectionError if response.status_code == 204: # No body in the response @@ -288,28 +288,19 @@ class DownloadUtils(object): ##### EXCEPTIONS ##### - except requests.exceptions.SSLError as error: - log.error("Invalid SSL certificate for: %s", url) - error.quiet = True - raise - - except requests.exceptions.ConnectTimeout as error: - log.error("ConnectTimeout at: %s", url) - error.quiet = True - raise - - except requests.exceptions.ReadTimeout as error: - log.error("ReadTimeout at: %s", url) - error.quiet = True - raise - except requests.exceptions.ConnectionError as error: # Make the addon aware of status + window('emby_test', value="true") + if window('emby_online') != "false": log.error("Server unreachable at: %s", url) window('emby_online', value="false") - error.quiet = True - raise + + raise HTTPException(None) + + except requests.exceptions.ReadTimeout as error: + log.error("ReadTimeout at: %s", url) + raise HTTPException(None) except requests.exceptions.HTTPError as error: @@ -335,14 +326,10 @@ class DownloadUtils(object): xbmcgui.Dialog().notification(heading="Error connecting", message="Unauthorized.", icon=xbmcgui.NOTIFICATION_ERROR) - - error.quiet = True - raise + raise HTTPException(response.status_code) # if we got to here and did not process the download for some reason then that is bad - exc = Exception("Unhandled Download : %s", url) - #exc.quiet = True - raise exc + raise Exception("Unhandled Download : %s", url) def _ensure_server(self, server_id=None): @@ -364,8 +351,7 @@ class DownloadUtils(object): info = { 'UserId': "", 'Server': "", - 'Token': "", - 'SSL': False + 'Token': "" } if server_id is None: # Main server diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index 039a45f5..c39953fc 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -73,19 +73,6 @@ class UserClient(threading.Thread): log.error(error) return False - @classmethod - def get_ssl(cls): - """ - Returns boolean value or path to certificate - True: Verify ssl - False: Don't verify connection - """ - certificate = settings('sslcert') - if certificate != "None": - return certificate - - return True if settings('sslverify') == "true" else False - def get_access(self): if not self._has_access: @@ -200,8 +187,7 @@ class UserClient(threading.Thread): 'UserId': userid, 'Server': server, 'ServerId': settings('serverId'), - 'Token': token, - 'SSL': self.get_ssl() + 'Token': token } # Set downloadutils.py values doutils.set_session(**server_json) @@ -235,7 +221,6 @@ class UserClient(threading.Thread): added_servers = [] for server in servers: if server['Id'] != settings('serverId'): - # TODO: SSL setup self.doutils.add_server(server, False) added_servers.append(server['Id']) diff --git a/resources/settings.xml b/resources/settings.xml index 9777784d..2ff06886 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -11,8 +11,8 @@ - - +