diff options
-rw-r--r-- | netlib/certutils.py | 1 | ||||
-rw-r--r-- | netlib/http.py | 9 | ||||
-rw-r--r-- | netlib/tcp.py | 10 | ||||
-rw-r--r-- | test/test_tcp.py | 4 |
4 files changed, 13 insertions, 11 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py index b3ba1dcf..859c93f1 100644 --- a/netlib/certutils.py +++ b/netlib/certutils.py @@ -118,7 +118,6 @@ def dummy_cert(fp, ca, commonname, sans): fp.close() - class CertStore: """ Implements an on-disk certificate store. diff --git a/netlib/http.py b/netlib/http.py index 29bcf43d..58993686 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -9,6 +9,9 @@ class HttpError(Exception): return "HttpError(%s, %s)"%(self.code, self.msg) +class HttpErrorConnClosed(HttpError): pass + + def parse_url(url): """ Returns a (scheme, host, port, path) tuple, or None on error. @@ -73,7 +76,7 @@ def read_chunked(code, fp, limit): while 1: line = fp.readline(128) if line == "": - raise HttpError(code, "Connection closed prematurely") + raise HttpErrorConnClosed(code, "Connection closed prematurely") if line != '\r\n' and line != '\n': try: length = int(line, 16) @@ -95,7 +98,7 @@ def read_chunked(code, fp, limit): while 1: line = fp.readline() if line == "": - raise HttpError(code, "Connection closed prematurely") + raise HttpErrorConnClosed(code, "Connection closed prematurely") if line == '\r\n' or line == '\n': break return content @@ -279,7 +282,7 @@ def read_response(rfile, method, body_size_limit): if line == "\r\n" or line == "\n": # Possible leftover from previous message line = rfile.readline() if not line: - raise HttpError(502, "Server disconnect.") + raise HttpErrorConnClosed(502, "Server disconnect.") parts = line.strip().split(" ", 2) if len(parts) == 2: # handle missing message gracefully parts.append("") diff --git a/netlib/tcp.py b/netlib/tcp.py index 0a15d2ac..d909a5a4 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -179,17 +179,17 @@ class TCPClient: self.cert = None self.ssl_established = False - def convert_to_ssl(self, clientcert=None, sni=None, method=TLSv1_METHOD, options=None): + def convert_to_ssl(self, cert=None, sni=None, method=TLSv1_METHOD, options=None): """ - clientcert: Path to a file containing both client cert and private key. + cert: Path to a file containing both client cert and private key. """ context = SSL.Context(method) if options is not None: context.set_options(options) - if clientcert: + if cert: try: - context.use_privatekey_file(clientcert) - context.use_certificate_file(clientcert) + context.use_privatekey_file(cert) + context.use_certificate_file(cert) except SSL.Error, v: raise NetLibError("SSL client certificate error: %s"%str(v)) self.connection = SSL.Connection(context, self.connection) diff --git a/test/test_tcp.py b/test/test_tcp.py index 5b616969..de14ab25 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -149,7 +149,7 @@ class TestSSLClientCert(test.ServerTestBase): def test_clientcert(self): c = tcp.TCPClient("127.0.0.1", self.port) c.connect() - c.convert_to_ssl(clientcert=tutils.test_data.path("data/clientcert/client.pem")) + c.convert_to_ssl(cert=tutils.test_data.path("data/clientcert/client.pem")) assert c.rfile.readline().strip() == "1" def test_clientcert_err(self): @@ -158,7 +158,7 @@ class TestSSLClientCert(test.ServerTestBase): tutils.raises( tcp.NetLibError, c.convert_to_ssl, - clientcert=tutils.test_data.path("data/clientcert/make") + cert=tutils.test_data.path("data/clientcert/make") ) |