-
Notifications
You must be signed in to change notification settings - Fork 0
/
https_transparent.py
41 lines (30 loc) · 1.15 KB
/
https_transparent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from proxy2 import *
class ThreadingHTTPSServer(ThreadingHTTPServer):
address_family = socket.AF_INET6
daemon_threads = True
cakey = 'ca.key'
cacert = 'ca.crt'
def get_request(self):
request, client_address = self.socket.accept()
request = ssl.wrap_socket(request, keyfile=self.cakey, certfile=self.cacert, server_side=True)
return request, client_address
def handle_error(self, request, client_address):
# surpress socket/ssl related errors
cls, e = sys.exc_info()[:2]
if cls is socket.error or cls is ssl.SSLError:
pass
else:
return HTTPServer.handle_error(self, request, client_address)
def test(HandlerClass=ProxyRequestHandler, ServerClass=ThreadingHTTPSServer, protocol="HTTP/1.1"):
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 3129
server_address = ('', port)
HandlerClass.protocol_version = protocol
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
print "Serving HTTPS Proxy on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
if __name__ == '__main__':
test()