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

Changeset 1928

Show
Ignore:
Timestamp:
03/17/08 15:48:25
Author:
fumanchu
Message:

Minimize risk of dirty conn close when fatal SSL alerts are raised.

Files:

Legend:

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

    r1920 r1928  
    678678class NoSSLError(Exception): 
    679679    """Exception raised when a client speaks HTTP to an HTTPS socket.""" 
     680    pass 
     681 
     682 
     683class FatalSSLAlert(Exception): 
     684    """Exception raised when the SSL implementation signals a fatal alert.""" 
    680685    pass 
    681686 
     
    861866                    pass 
    862867                 
    863                 if is_reader and thirdarg == 'ssl handshake failure': 
    864                     # Return "" to simulate EOF which will close the conn. 
    865                     return "" 
    866868                if thirdarg == 'http request': 
    867869                    # The client is talking HTTP to an HTTPS server. 
    868870                    raise NoSSLError() 
    869                 if is_reader and thirdarg == 'decryption failed or bad record mac': 
    870                     # Return "" to simulate EOF which will close the conn. 
    871                     return "" 
    872                 else: 
    873                     raise 
     871                raise FatalSSLAlert(*e.args) 
    874872            except: 
    875873                raise 
     
    957955            if errnum not in socket_errors_to_ignore: 
    958956                if req: 
    959                     fd = open("ssl_errors.txt", "a") 
    960                     fd.write("1" * 80) 
    961                     fd.write("\n") 
    962                     fd.write(str(type(e))) 
    963                     fd.write(format_exc()) 
    964957                    req.simple_response("500 Internal Server Error", 
    965958                                        format_exc()) 
     
    967960        except (KeyboardInterrupt, SystemExit): 
    968961            raise 
     962        except FatalSSLAlert, e: 
     963            # Close the connection. 
     964            return 
    969965        except NoSSLError: 
    970966            # Unwrap our wfile 
     
    974970                                "this server only speaks HTTPS on this port.") 
    975971        except Exception, e: 
    976             fd = open("ssl_errors.txt", "a") 
    977             fd.write("2" * 80) 
    978             fd.write("\n") 
    979             fd.write(format_exc()) 
    980972            if req: 
    981973                req.simple_response("500 Internal Server Error", format_exc()) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets