From 796746b86badee1d54bbb5c9e412a71f610042cb Mon Sep 17 00:00:00 2001 From: Chris Hines <chris.hines@monash.edu> Date: Thu, 8 Aug 2019 11:54:37 +0800 Subject: [PATCH] revert commits created trying to debug a safari issue .. it looks like the issue is on novnc --- TES/tes/apiendpoints.py | 2 +- TWS/twsproxy/__init__.py | 35 +++++++---------------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/TES/tes/apiendpoints.py b/TES/tes/apiendpoints.py index 65c6a30..8df948f 100644 --- a/TES/tes/apiendpoints.py +++ b/TES/tes/apiendpoints.py @@ -475,7 +475,7 @@ class CreateTunnel(Resource): localbind=localbind, authtok=authtok) response = make_response("") response.mime_type = 'application/json' - response.set_cookie('twsproxyauth', authtok, httponly=True,secure=True,samesite='Strict') + response.set_cookie('twsproxyauth', authtok) logger.debug('JobConnect.connect: connecting via redirect with cookie authtok set to {}'.format(authtok)) return response diff --git a/TWS/twsproxy/__init__.py b/TWS/twsproxy/__init__.py index 42e8dc3..3fbe1c3 100644 --- a/TWS/twsproxy/__init__.py +++ b/TWS/twsproxy/__init__.py @@ -41,7 +41,7 @@ class TWSProxy(threading.Thread): header[bytessofar:bytessofar+len(partial)] = partial bytessofar = bytessofar + len(partial) logger.debug('inittws, checking headers') - port = self.verifyauth(header[0:bytessofar]) + port = TWSProxy.verifyauth(header[0:bytessofar]) if port is not None: logger.debug('inittws, found auth token and got port {}'.format(port)) keepreading = False @@ -49,9 +49,7 @@ class TWSProxy(threading.Thread): logger.debug('inittws, no authtok found in the first {} bytes'.format(bytessofar)) else: logger.debug('inittws, select returned with no more info, verifying headers for the last time') - port = self.verifyauth(header[0:bytessofar]) - logger.debug(header[0:bytessofar]) - + port = TWSProxy.verifyauth(header[0:bytessofar]) keepreading = False if initcount > failthresh: logger.debug('inittws, checked headers enough times, got {} bytes with no success'.format(bytessofar)) @@ -79,12 +77,6 @@ class TWSProxy(threading.Thread): return (None,None) - def insert_header(self,buff,insertafter,extraheader): - try: - index = buff.decode().index(insertafter.decode()) - except: - return buff - return buff[0:index] + extraheader + buff[index:] def run(self): import logging @@ -93,11 +85,6 @@ class TWSProxy(threading.Thread): initshutdown = threading.Event() initshutdown.clear() (header, bytessofar) = self.inittws(initshutdown) - if self.authtok is not None: - replyheader = b'Set-Cookie: twsproxyauth2='+self.authtok+b' ; HttpOnly; SameSite=Lax; Path=/ \r\n' - else: - replyheader = None - insertafter = b'HTTP/1.1 200 OK\r\n' logger.debug('connecting {} to {}'.format(self.csock,self.ssock)) if initshutdown.isSet(): logger.debug('NOT connecting {} inittws did not connect us'.format(self.csock)) @@ -110,7 +97,7 @@ class TWSProxy(threading.Thread): TWSProxy.reliablesend(self.ssock,header[0:bytessofar],bytessofar) logger.debug('creating threads') # TWSProxy.twosocks(self.csock,self.ssock,initshutdown) - t1 = threading.Thread(target=TWSProxy.sockcopy, args=(self.ssock, self.csock, initshutdown,insertafter,replyheader),name='s2c') + t1 = threading.Thread(target=TWSProxy.sockcopy, args=(self.ssock, self.csock, initshutdown),name='s2c') t2 = threading.Thread(target=TWSProxy.sockcopy, args=(self.csock, self.ssock, initshutdown),name='c2s') t1.start() t2.start() @@ -124,11 +111,12 @@ class TWSProxy(threading.Thread): if self.csock is not None: self.csock.close() - def verifyauth(self,header): + @staticmethod + def verifyauth(header): import re import requests logger = logging.getLogger() - token = b'twsproxyauth[0-9]*=(?P<authtok>\w+)[\W|$]' + token = b'twsproxyauth=(?P<authtok>\w+)[\W|$]' m = re.search(token,header) if m: authtok = m.groupdict()['authtok'] @@ -146,7 +134,6 @@ class TWSProxy(threading.Thread): except: logger.error('authtok found port found {}'.format(port)) raise Exception('unable to get a port number for the authtok {}'.format(r.text)) - self.authtok = authtok return port return None # if m: @@ -216,7 +203,7 @@ class TWSProxy(threading.Thread): @staticmethod - def sockcopy(src,dest,initshutdown,insertafter=None,insert=None): + def sockcopy(src,dest,initshutdown): shuttype = socket.SHUT_RD import threading logger = logging.getLogger() @@ -233,14 +220,6 @@ class TWSProxy(threading.Thread): msglength = -1 try: buff = src.recv(TWSProxy.MAXBUFF) - if insert is not None: - try: - index = buff.decode().index(insertafter.decode()) - newbuff = buff[0:index+len(insertafter)] + insert + buff[index+len(insertafter):] - buff = newbuff - insert = None - except: - pass if buff is None: continue except ConnectionResetError as e: -- GitLab