Merge pull request #129 from mkai/_py26_ciphers_fix

Add SSL ciphers argument only if supported, fixes Python 2.6 compat
This commit is contained in:
Guillaume Ayoub 2014-03-19 14:13:29 +01:00
commit d053257643

View File

@ -29,6 +29,7 @@ should have been included in this package.
""" """
import os import os
import sys
import pprint import pprint
import base64 import base64
import posixpath import posixpath
@ -93,14 +94,18 @@ class HTTPSServer(HTTPServer):
"Error while reading SSL %s %r: %s" % ( "Error while reading SSL %s %r: %s" % (
name, filename, exception)) name, filename, exception))
self.socket = ssl.wrap_socket( ssl_kwargs = dict(
self.socket,
server_side=True, server_side=True,
certfile=config.get("server", "certificate"), certfile=config.get("server", "certificate"),
keyfile=config.get("server", "key"), keyfile=config.get("server", "key"),
ssl_version=getattr(ssl, config.get("server", "protocol"), ssl_version=getattr(ssl, config.get("server", "protocol"),
ssl.PROTOCOL_SSLv23), ssl.PROTOCOL_SSLv23)
ciphers=config.get("server", "ciphers") or None) )
# add ciphers argument only if supported (Python 2.7+)
if sys.version_info >= (2, 7):
ssl_kwargs["ciphers"] = config.get("server", "ciphers") or None
self.socket = ssl.wrap_socket(self.socket, **ssl_kwargs)
self.server_bind() self.server_bind()
self.server_activate() self.server_activate()