Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1552

Show
Ignore:
Timestamp:
12/21/06 17:44:55
Author:
fumanchu
Message:

Final fix for #625 (SSL: Writing to timed out socket didn't fail as it should have). Basically, SSL errors raise for write methods, and return "" for read methods.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/wsgiserver.py

    r1550 r1552  
    462462 
    463463 
    464 def _ssl_wrap_method(method): 
     464def _ssl_wrap_method(method, is_reader=False): 
     465    """Wrap the given method with SSL error-trapping. 
     466     
     467    is_reader: if False (the default), EOF errors will be raised. 
     468        If True, EOF errors will return "" (to emulate normal sockets). 
     469    """ 
    465470    def ssl_method_wrapper(self, *args, **kwargs): 
    466471##        print (id(self), method, args, kwargs) 
     
    476481                time.sleep(self.ssl_retry) 
    477482            except SSL.SysCallError, e: 
    478                 if e.args == (-1, 'Unexpected EOF'): 
     483                if is_reader and e.args == (-1, 'Unexpected EOF'): 
    479484                    return "" 
    480485                 
    481486                errno = e.args[0] 
    482                 if errno not in socket_errors_to_ignore: 
    483                     raise socket.error(errno) 
    484                  
    485                 return "" 
     487                if is_reader and errno in socket_errors_to_ignore: 
     488                    return "" 
     489                raise socket.error(errno) 
    486490            except SSL.Error, e: 
    487                 if e.args == (-1, 'Unexpected EOF'): 
     491                if is_reader and e.args == (-1, 'Unexpected EOF'): 
    488492                    return "" 
    489                 elif e.args[0][0][2] == 'ssl handshake failure': 
     493                if is_reader and e.args[0][0][2] == 'ssl handshake failure': 
    490494                    return "" 
    491                 else: 
    492                     raise 
     495                raise 
    493496            if time.time() - start > self.ssl_timeout: 
    494497                raise socket.timeout("timed out") 
     
    505508    write = _ssl_wrap_method(socket._fileobject.write) 
    506509    writelines = _ssl_wrap_method(socket._fileobject.writelines) 
    507     read = _ssl_wrap_method(socket._fileobject.read
    508     readline = _ssl_wrap_method(socket._fileobject.readline
    509     readlines = _ssl_wrap_method(socket._fileobject.readlines
     510    read = _ssl_wrap_method(socket._fileobject.read, is_reader=True
     511    readline = _ssl_wrap_method(socket._fileobject.readline, is_reader=True
     512    readlines = _ssl_wrap_method(socket._fileobject.readlines, is_reader=True
    510513 
    511514 

Hosted by WebFaction

Log in as guest/cpguest to create tickets