##// END OF EJS Templates
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later...
Mads Kiilerich -
r12784:763be3cd default
parent child Browse files
Show More
@@ -214,6 +214,26 b' class _httprequesthandleropenssl(_httpre'
214 self.close_connection = True
214 self.close_connection = True
215 pass
215 pass
216
216
217 class _httprequesthandlerssl(_httprequesthandler):
218 """HTTPS handler based on Pythons ssl module (introduced in 2.6)"""
219
220 url_scheme = 'https'
221
222 @staticmethod
223 def preparehttpserver(httpserver, ssl_cert):
224 try:
225 import ssl
226 ssl.wrap_socket
227 except ImportError:
228 raise util.Abort(_("SSL support is unavailable"))
229 httpserver.socket = ssl.wrap_socket(httpserver.socket, server_side=True,
230 certfile=ssl_cert, ssl_version=ssl.PROTOCOL_SSLv3)
231
232 def setup(self):
233 self.connection = self.request
234 self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
235 self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
236
217 try:
237 try:
218 from threading import activeCount
238 from threading import activeCount
219 _mixin = SocketServer.ThreadingMixIn
239 _mixin = SocketServer.ThreadingMixIn
@@ -265,7 +285,10 b' class IPv6HTTPServer(MercurialHTTPServer'
265 def create_server(ui, app):
285 def create_server(ui, app):
266
286
267 if ui.config('web', 'certificate'):
287 if ui.config('web', 'certificate'):
268 handler = _httprequesthandleropenssl
288 if sys.version_info >= (2, 6):
289 handler = _httprequesthandlerssl
290 else:
291 handler = _httprequesthandleropenssl
269 else:
292 else:
270 handler = _httprequesthandler
293 handler = _httprequesthandler
271
294
@@ -181,7 +181,6 b' def has_outer_repo():'
181
181
182 def has_ssl():
182 def has_ssl():
183 try:
183 try:
184 from OpenSSL.SSL import SysCallError, ZeroReturnError
185 import ssl
184 import ssl
186 return True
185 return True
187 except ImportError:
186 except ImportError:
@@ -207,7 +206,7 b' checks = {'
207 "outer-repo": (has_outer_repo, "outer repo"),
206 "outer-repo": (has_outer_repo, "outer repo"),
208 "p4": (has_p4, "Perforce server and client"),
207 "p4": (has_p4, "Perforce server and client"),
209 "pygments": (has_pygments, "Pygments source highlighting library"),
208 "pygments": (has_pygments, "Pygments source highlighting library"),
210 "ssl": (has_ssl, "python ssl and openssl modules"),
209 "ssl": (has_ssl, "python >= 2.6 ssl module"),
211 "svn": (has_svn, "subversion client and admin tools"),
210 "svn": (has_svn, "subversion client and admin tools"),
212 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
211 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
213 "symlink": (has_symlink, "symbolic links"),
212 "symlink": (has_symlink, "symbolic links"),
@@ -1,12 +1,7 b''
1 Proper https client requires the built-in ssl from Python 2.6,
1 Proper https client requires the built-in ssl from Python 2.6.
2 and https serve requires the full OpenSSL module.
3
2
4 $ "$TESTDIR/hghave" ssl || exit 80
3 $ "$TESTDIR/hghave" ssl || exit 80
5
4
6 HTTPS serve seems to be broken on Python 2.7:
7
8 $ [ "`python -c 'import sys; print sys.version_info[:2]'`" = '(2, 6)' ] || exit 80
9
10 Certificates created with:
5 Certificates created with:
11 printf '.\n.\n.\n.\n.\nlocalhost\nhg@localhost\n' | \
6 printf '.\n.\n.\n.\n.\nlocalhost\nhg@localhost\n' | \
12 openssl req -newkey rsa:512 -keyout priv.pem -nodes -x509 -days 9000 -out pub.pem
7 openssl req -newkey rsa:512 -keyout priv.pem -nodes -x509 -days 9000 -out pub.pem
General Comments 0
You need to be logged in to leave comments. Login now