Manage SSL (HTTPS) connections.

This commit is contained in:
Guillaume Ayoub
2010-01-19 17:49:32 +01:00
parent a8474449e2
commit 86dd1b0ef4
4 changed files with 54 additions and 20 deletions

View File

@ -20,7 +20,7 @@
# TODO: Manage errors (see xmlutils)
import posixpath
import socket
try:
from http import client, server
except ImportError:
@ -29,7 +29,24 @@ except ImportError:
from radicale import config, support, xmlutils
class CalendarHandler(server.BaseHTTPRequestHandler):
HTTPServer = server.HTTPServer
class HTTPSServer(HTTPServer):
def __init__(self, address, handler):
# Fails with Python 2.5, import if needed
import ssl
super(HTTPSServer, self).__init__(address, handler)
self.socket = ssl.wrap_socket(
socket.socket(self.address_family, self.socket_type),
server_side=True,
certfile=config.get("server", "certificate"),
keyfile=config.get("server", "key"),
ssl_version=ssl.PROTOCOL_SSLv23)
self.server_bind()
self.server_activate()
class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
"""HTTP requests handler for calendars."""
def _parse_path(self):
path = self.path.strip("/").split("/")

View File

@ -43,12 +43,12 @@ items = _config.items
_initial = {
"server": {
"protocol": "http",
"name": "",
"host": "",
"port": "5232",
"daemon": "False",
#"certificate": "/etc/apache2/ssl/server.crt",
#"privatekey": "/etc/apache2/ssl/server.key",
"ssl": "False",
"certificate": "/etc/apache2/ssl/server.crt",
"key": "/etc/apache2/ssl/server.key",
#"log": "/var/www/radicale/server.log",
},
"encoding": {