Skip to content

Commit ee9270c

Browse files
author
Ralf Schlatterbeck
committed
Correct initial- and end-handshakes for SSL
1 parent 9e61527 commit ee9270c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Fixes:
1010
This also fixes a case where a WantReadError is raised and apparently
1111
the bytes already read are dropped (seems the WantReadError is really
1212
an error, not just an indication to retry).
13+
- Correct initial- and end-handshakes for SSL
1314

1415
2009-10-09 1.4.10 (r4374)
1516

roundup/scripts/roundup_server.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
except ImportError:
3030
SSL = None
3131

32-
from time import sleep
33-
3432
# python version check
3533
from roundup import configuration, version_check
3634
from roundup import __version__ as roundup_version
@@ -76,7 +74,7 @@
7674

7775
def auto_ssl():
7876
print _('WARNING: generating temporary SSL certificate')
79-
import OpenSSL, time, random, sys
77+
import OpenSSL, random
8078
pkey = OpenSSL.crypto.PKey()
8179
pkey.generate_key(OpenSSL.crypto.TYPE_RSA, 768)
8280
cert = OpenSSL.crypto.X509()
@@ -128,15 +126,15 @@ def readline(self, *args):
128126
try:
129127
return self.__fileobj.readline(*args)
130128
except SSL.WantReadError:
131-
sleep (.1)
129+
time.sleep(.1)
132130

133131
def read(self, *args):
134132
""" SSL.Connection can return WantRead """
135133
while True:
136134
try:
137135
return self.__fileobj.read(*args)
138136
except SSL.WantReadError:
139-
sleep (.1)
137+
time.sleep(.1)
140138

141139
def __getattr__(self, attrib):
142140
return getattr(self.__fileobj, attrib)
@@ -590,6 +588,20 @@ class RequestHandler(RoundupRequestHandler):
590588
DEBUG_MODE = self["MULTIPROCESS"] == "debug"
591589
CONFIG = self
592590

591+
def setup(self):
592+
if self.CONFIG["SSL"]:
593+
# perform initial ssl handshake. This will set
594+
# internal state correctly so that later closing SSL
595+
# socket works (with SSL end-handshake started)
596+
self.request.do_handshake()
597+
RoundupRequestHandler.setup(self)
598+
599+
def finish(self):
600+
RoundupRequestHandler.finish(self)
601+
if self.CONFIG["SSL"]:
602+
self.request.shutdown()
603+
self.request.close()
604+
593605
if self["SSL"]:
594606
base_server = SecureHTTPServer
595607
else:

0 commit comments

Comments
 (0)