From 5eeb52183a24a6a5dd7f9a37ef342dfd3cfd279c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 13 May 2013 09:03:48 +1200 Subject: [PATCH] Adapt for new request_client_cert option in netlib. --- libpathod/pathod.py | 11 +++++++---- test/test_pathoc.py | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 4d8a02035..34afaa5a5 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -9,10 +9,11 @@ class PathodError(Exception): pass class SSLOptions: - def __init__(self, certfile=None, keyfile=None, not_after_connect=None): + def __init__(self, certfile=None, keyfile=None, not_after_connect=None, request_client_cert=False): self.keyfile = keyfile or utils.data.path("resources/server.key") self.certfile = certfile or utils.data.path("resources/server.crt") self.not_after_connect = not_after_connect + self.request_client_cert = request_client_cert class PathodHandler(tcp.BaseHandler): @@ -76,7 +77,8 @@ class PathodHandler(tcp.BaseHandler): self.convert_to_ssl( self.server.ssloptions.certfile, self.server.ssloptions.keyfile, - handle_sni = self.handle_sni + handle_sni = self.handle_sni, + request_client_cert = self.server.ssloptions.request_client_cert ) except tcp.NetLibError, v: s = str(v) @@ -181,7 +183,8 @@ class PathodHandler(tcp.BaseHandler): self.convert_to_ssl( self.server.ssloptions.certfile, self.server.ssloptions.keyfile, - handle_sni = self.handle_sni + handle_sni = self.handle_sni, + request_client_cert = self.server.ssloptions.request_client_cert ) except tcp.NetLibError, v: s = str(v) @@ -222,7 +225,7 @@ class Pathod(tcp.TCPServer): """ addr: (address, port) tuple. If port is 0, a free port will be automatically chosen. - ssloptions: a dictionary containing certfile and keyfile specifications. + ssloptions: an SSLOptions object. craftanchor: string specifying the path under which to anchor response generation. staticdir: path to a directory of static resources, or None. anchors: A list of (regex, spec) tuples, or None. diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 5391167fe..31d73111c 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -1,5 +1,5 @@ import json, cStringIO -from libpathod import pathoc, test, version +from libpathod import pathoc, test, version, pathod import tutils def test_response(): @@ -8,10 +8,12 @@ def test_response(): class _TestDaemon: + ssloptions = pathod.SSLOptions() @classmethod def setUpAll(self): self.d = test.Daemon( ssl=self.ssl, + ssloptions=self.ssloptions, staticdir=tutils.test_data.path("data"), anchors=[("/anchor/.*", "202")] ) @@ -36,6 +38,7 @@ class _TestDaemon: class TestDaemonSSL(_TestDaemon): ssl = True + ssloptions = pathod.SSLOptions(request_client_cert=True) def test_sni(self): c = pathoc.Pathoc( "127.0.0.1",