Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Suppress SSL certificate errors. #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions httpproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import socket
import SocketServer
import ssl
import sys
import time
import urlparse

Expand All @@ -29,6 +30,18 @@
import sslproxy


def _HandleSSLCertificateError():
"""
This method is intended to be called from
BaseHTTPServer.HTTPServer.handle_error().
"""
exc_type, exc_value, exc_traceback = sys.exc_info()
if isinstance(exc_value, ssl.SSLError):
return

raise


class HttpProxyError(Exception):
"""Module catch-all error."""
pass
Expand Down Expand Up @@ -320,6 +333,9 @@ def get_certificate(self, host):
self._host_to_cert_map[host] = cert
return cert

def handle_error(self, request, client_address):
_HandleSSLCertificateError()


class SingleCertHttpsProxyServer(HttpProxyServer):
"""SSL server."""
Expand All @@ -333,10 +349,16 @@ def __init__(self, http_archive_fetch, custom_handlers,
do_handshake_on_connect=False)
# Ancestor class, DaemonServer, calls serve_forever() during its __init__.

def handle_error(self, request, client_address):
_HandleSSLCertificateError()


class HttpToHttpsProxyServer(HttpProxyServer):
"""Listens for HTTP requests but sends them to the target as HTTPS requests"""

def __init__(self, http_archive_fetch, custom_handlers, **kwargs):
HttpProxyServer.__init__(self, http_archive_fetch, custom_handlers,
is_ssl=True, protocol='HTTP-to-HTTPS', **kwargs)

def handle_error(self, request, client_address):
_HandleSSLCertificateError()