Code

Correct initial- and end-handshakes for SSL
authorschlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 14 Oct 2009 10:06:49 +0000 (10:06 +0000)
committerschlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 14 Oct 2009 10:06:49 +0000 (10:06 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4380 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/scripts/roundup_server.py

index 6c6c2db35d292ffa401ea6d1af178aef27e5e0e3..2ebb1d330b0568845f72df9197765b123e2520e3 100644 (file)
@@ -10,6 +10,7 @@ Fixes:
   This also fixes a case where a WantReadError is raised and apparently
   the bytes already read are dropped (seems the WantReadError is really
   an error, not just an indication to retry).
+- Correct initial- and end-handshakes for SSL
 
 2009-10-09 1.4.10 (r4374)
 
index 2ebd56ea3c79e3bb26f8b3ea0df00d0bd573eb6a..2e26218fe0b6930312661465dcdd056e776872e7 100644 (file)
@@ -29,8 +29,6 @@ try:
 except ImportError:
     SSL = None
 
-from time import sleep
-
 # python version check
 from roundup import configuration, version_check
 from roundup import __version__ as roundup_version
@@ -76,7 +74,7 @@ DEFAULT_MULTIPROCESS = MULTIPROCESS_TYPES[-1]
 
 def auto_ssl():
     print _('WARNING: generating temporary SSL certificate')
-    import OpenSSL, time, random, sys
+    import OpenSSL, random
     pkey = OpenSSL.crypto.PKey()
     pkey.generate_key(OpenSSL.crypto.TYPE_RSA, 768)
     cert = OpenSSL.crypto.X509()
@@ -128,7 +126,7 @@ class SecureHTTPServer(BaseHTTPServer.HTTPServer):
                         try:
                             return self.__fileobj.readline(*args)
                         except SSL.WantReadError:
-                            sleep (.1)
+                            time.sleep(.1)
 
                 def read(self, *args):
                     """ SSL.Connection can return WantRead """
@@ -136,7 +134,7 @@ class SecureHTTPServer(BaseHTTPServer.HTTPServer):
                         try:
                             return self.__fileobj.read(*args)
                         except SSL.WantReadError:
-                            sleep (.1)
+                            time.sleep(.1)
 
                 def __getattr__(self, attrib):
                     return getattr(self.__fileobj, attrib)
@@ -590,6 +588,20 @@ class ServerConfig(configuration.Config):
             DEBUG_MODE = self["MULTIPROCESS"] == "debug"
             CONFIG = self
 
+            def setup(self):
+                if self.CONFIG["SSL"]:
+                    # perform initial ssl handshake. This will set
+                    # internal state correctly so that later closing SSL
+                    # socket works (with SSL end-handshake started)
+                    self.request.do_handshake()
+                RoundupRequestHandler.setup(self)
+
+            def finish(self):
+                RoundupRequestHandler.finish(self)
+                if self.CONFIG["SSL"]:
+                    self.request.shutdown()
+                    self.request.close()
+
         if self["SSL"]:
             base_server = SecureHTTPServer
         else: