Catch and handle SSL connection errors.

This commit is contained in:
Aldo Cortesi 2012-07-01 12:10:32 +12:00
parent 4e9d4e8ddd
commit 90365e270e
2 changed files with 15 additions and 4 deletions

View File

@ -88,7 +88,10 @@ class ServerConnection(tcp.TCPClient):
path = os.path.join(self.config.clientcerts, self.host) + ".pem" path = os.path.join(self.config.clientcerts, self.host) + ".pem"
if os.path.exists(clientcert): if os.path.exists(clientcert):
clientcert = path clientcert = path
try:
self.convert_to_ssl(clientcert=clientcert, sni=self.host) self.convert_to_ssl(clientcert=clientcert, sni=self.host)
except tcp.NetLibError, v:
raise ProxyError(400, str(v))
def send(self, request): def send(self, request):
self.requestcount += 1 self.requestcount += 1
@ -260,7 +263,10 @@ class ProxyHandler(tcp.BaseHandler):
if not self.ssl_established and (port in self.config.transparent_proxy["sslports"]): if not self.ssl_established and (port in self.config.transparent_proxy["sslports"]):
scheme = "https" scheme = "https"
certfile = self.find_cert(host, port, None) certfile = self.find_cert(host, port, None)
try:
self.convert_to_ssl(certfile, self.config.certfile or self.config.cacert) self.convert_to_ssl(certfile, self.config.certfile or self.config.cacert)
except tcp.NetLibError, v:
raise ProxyError(400, str(v))
else: else:
scheme = "http" scheme = "http"
host = self.sni or host host = self.sni or host
@ -312,7 +318,10 @@ class ProxyHandler(tcp.BaseHandler):
) )
self.wfile.flush() self.wfile.flush()
certfile = self.find_cert(host, port, None) certfile = self.find_cert(host, port, None)
try:
self.convert_to_ssl(certfile, self.config.certfile or self.config.cacert) self.convert_to_ssl(certfile, self.config.certfile or self.config.cacert)
except tcp.NetLibError, v:
raise ProxyError(400, str(v))
self.proxy_connect_state = (host, port, httpversion) self.proxy_connect_state = (host, port, httpversion)
line = self.rfile.readline(line) line = self.rfile.readline(line)
if self.proxy_connect_state: if self.proxy_connect_state:

View File

@ -1,7 +1,7 @@
import os import os
from cStringIO import StringIO from cStringIO import StringIO
import libpry import libpry
from libmproxy import dump, flow from libmproxy import dump, flow, proxy
import tutils import tutils
def test_strfuncs(): def test_strfuncs():
@ -20,6 +20,8 @@ class TestDumpMaster:
def _cycle(self, m, content): def _cycle(self, m, content):
req = tutils.treq() req = tutils.treq()
req.content = content req.content = content
l = proxy.Log("connect")
m.handle_log(l)
cc = req.client_conn cc = req.client_conn
cc.connection_error = "error" cc.connection_error = "error"
resp = tutils.tresp(req) resp = tutils.tresp(req)