apply Alexey patch for TLS error. Now buffer is 1M, so this workaround should prevent TLS crash
This commit is contained in:
parent
2377437112
commit
b5ed8ee163
2 changed files with 11 additions and 46 deletions
|
@ -109,10 +109,7 @@ class Dispatcher(PlugIn):
|
||||||
Returns:
|
Returns:
|
||||||
1) length of processed data if some data were processed;
|
1) length of processed data if some data were processed;
|
||||||
2) '0' string if no data were processed but link is alive;
|
2) '0' string if no data were processed but link is alive;
|
||||||
3) 0 (zero) if underlying connection is closed.
|
3) 0 (zero) if underlying connection is closed."""
|
||||||
Take note that in case of disconnection detect during Process() call
|
|
||||||
disconnect handlers are called automatically.
|
|
||||||
"""
|
|
||||||
if (time.time() > self._lastIncome + 60) and not self._natSent: #1 min
|
if (time.time() > self._lastIncome + 60) and not self._natSent: #1 min
|
||||||
iq = Iq('get', NS_LAST, to=self._owner.Server)
|
iq = Iq('get', NS_LAST, to=self._owner.Server)
|
||||||
self.send(iq)
|
self.send(iq)
|
||||||
|
@ -121,13 +118,11 @@ class Dispatcher(PlugIn):
|
||||||
self._owner.disconnected()
|
self._owner.disconnected()
|
||||||
for handler in self._cycleHandlers: handler(self)
|
for handler in self._cycleHandlers: handler(self)
|
||||||
if self._owner.Connection.pending_data(timeout):
|
if self._owner.Connection.pending_data(timeout):
|
||||||
try: data=self._owner.Connection.receive()
|
data=self._owner.Connection.receive()
|
||||||
except IOError: return
|
|
||||||
self.Stream.Parse(data)
|
self.Stream.Parse(data)
|
||||||
if data:
|
self._lastIncome = time.time()
|
||||||
self._lastIncome = time.time()
|
self._natSent = False
|
||||||
self._natSent = False
|
return len(data)
|
||||||
return len(data)
|
|
||||||
return '0' # It means that nothing is received but link is alive.
|
return '0' # It means that nothing is received but link is alive.
|
||||||
|
|
||||||
def RegisterNamespace(self,xmlns,order='info'):
|
def RegisterNamespace(self,xmlns,order='info'):
|
||||||
|
|
|
@ -42,7 +42,6 @@ class error:
|
||||||
"""Serialise exception into pre-cached descriptive string."""
|
"""Serialise exception into pre-cached descriptive string."""
|
||||||
return self._comment
|
return self._comment
|
||||||
|
|
||||||
BUFLEN=1024
|
|
||||||
class TCPsocket(PlugIn):
|
class TCPsocket(PlugIn):
|
||||||
""" This class defines direct TCP connection method. """
|
""" This class defines direct TCP connection method. """
|
||||||
def __init__(self, server=None):
|
def __init__(self, server=None):
|
||||||
|
@ -90,30 +89,21 @@ class TCPsocket(PlugIn):
|
||||||
del self._owner.Connection
|
del self._owner.Connection
|
||||||
|
|
||||||
def receive(self):
|
def receive(self):
|
||||||
""" Reads all pending incoming data.
|
""" Reads all pending incoming data. Calls owner's disconnected() method if appropriate."""
|
||||||
In case of disconnection calls owner's disconnected() method and then raises IOError exception."""
|
try: received = self._recv(1024000)
|
||||||
try: received = self._recv(BUFLEN)
|
|
||||||
except socket.sslerror,e:
|
|
||||||
self._seen_data=0
|
|
||||||
if e[0]==2: return ''
|
|
||||||
self.DEBUG('Socket error while receiving data','error')
|
|
||||||
self._owner.disconnected()
|
|
||||||
raise IOError("Disconnected from server")
|
|
||||||
except: received = ''
|
except: received = ''
|
||||||
|
|
||||||
while self.pending_data(0):
|
while select.select([self._sock],[],[],0)[0]:
|
||||||
try: add = self._recv(BUFLEN)
|
try: add = self._recv(1024000)
|
||||||
except: add=''
|
except: add=''
|
||||||
received +=add
|
received +=add
|
||||||
if not add: break
|
if not add: break
|
||||||
|
|
||||||
if len(received): # length of 0 means disconnect
|
if len(received): # length of 0 means disconnect
|
||||||
self._seen_data=1
|
|
||||||
self.DEBUG(received,'got')
|
self.DEBUG(received,'got')
|
||||||
else:
|
else:
|
||||||
self.DEBUG('Socket error while receiving data','error')
|
self.DEBUG('Socket error while receiving data','error')
|
||||||
self._owner.disconnected()
|
self._owner.disconnected()
|
||||||
raise IOError("Disconnected from server")
|
|
||||||
return received
|
return received
|
||||||
|
|
||||||
def send(self,raw_data):
|
def send(self,raw_data):
|
||||||
|
@ -178,23 +168,14 @@ class HTTPPROXYsocket(TCPsocket):
|
||||||
connector.append('Proxy-Authorization: Basic '+credentials)
|
connector.append('Proxy-Authorization: Basic '+credentials)
|
||||||
connector.append('\r\n')
|
connector.append('\r\n')
|
||||||
self.send('\r\n'.join(connector))
|
self.send('\r\n'.join(connector))
|
||||||
try: reply = self.receive().replace('\r','')
|
reply = self.receive().replace('\r','')
|
||||||
except IOError:
|
|
||||||
self.DEBUG('Proxy suddenly disconnected','error')
|
|
||||||
self._owner.disconnected()
|
|
||||||
return
|
|
||||||
try: proto,code,desc=reply.split('\n')[0].split(' ',2)
|
try: proto,code,desc=reply.split('\n')[0].split(' ',2)
|
||||||
except: raise error('Invalid proxy reply')
|
except: raise error('Invalid proxy reply')
|
||||||
if code<>'200':
|
if code<>'200':
|
||||||
self.DEBUG('Invalid proxy reply: %s %s %s'%(proto,code,desc),'error')
|
self.DEBUG('Invalid proxy reply: %s %s %s'%(proto,code,desc),'error')
|
||||||
self._owner.disconnected()
|
self._owner.disconnected()
|
||||||
return
|
return
|
||||||
while reply.find('\n\n') == -1:
|
while reply.find('\n\n') == -1: reply += self.receive().replace('\r','')
|
||||||
try: reply += self.receive().replace('\r','')
|
|
||||||
except IOError:
|
|
||||||
self.DEBUG('Proxy suddenly disconnected','error')
|
|
||||||
self._owner.disconnected()
|
|
||||||
return
|
|
||||||
self.DEBUG("Authentification successfull. Jabber server contacted.",'ok')
|
self.DEBUG("Authentification successfull. Jabber server contacted.",'ok')
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
@ -238,25 +219,14 @@ class TLS(PlugIn):
|
||||||
self._owner.Connection.send('<starttls xmlns="%s"/>'%NS_TLS)
|
self._owner.Connection.send('<starttls xmlns="%s"/>'%NS_TLS)
|
||||||
raise NodeProcessed
|
raise NodeProcessed
|
||||||
|
|
||||||
def pending_data(self,timeout=0):
|
|
||||||
""" Returns true if there possible is a data ready to be read. """
|
|
||||||
return self._tcpsock._seen_data or select.select([self._tcpsock._sock],[],[],timeout)[0]
|
|
||||||
|
|
||||||
def _startSSL(self):
|
def _startSSL(self):
|
||||||
""" Immidiatedly switch socket to TLS mode. Used internally."""
|
""" Immidiatedly switch socket to TLS mode. Used internally."""
|
||||||
""" Here we should switch pending_data to hint mode."""
|
|
||||||
tcpsock=self._owner.Connection
|
tcpsock=self._owner.Connection
|
||||||
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
|
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
|
||||||
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
|
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
|
||||||
tcpsock._sslServer = tcpsock._sslObj.server()
|
tcpsock._sslServer = tcpsock._sslObj.server()
|
||||||
tcpsock._recv = tcpsock._sslObj.read
|
tcpsock._recv = tcpsock._sslObj.read
|
||||||
tcpsock._send = tcpsock._sslObj.write
|
tcpsock._send = tcpsock._sslObj.write
|
||||||
|
|
||||||
tcpsock._seen_data=1
|
|
||||||
self._tcpsock=tcpsock
|
|
||||||
tcpsock.pending_data=self.pending_data
|
|
||||||
tcpsock._sock.setblocking(0)
|
|
||||||
|
|
||||||
self.starttls='success'
|
self.starttls='success'
|
||||||
|
|
||||||
def StartTLSHandler(self, conn, starttls):
|
def StartTLSHandler(self, conn, starttls):
|
||||||
|
|
Loading…
Add table
Reference in a new issue