From 2ac8ce06cdc33e19205acfadce69bd39e5038bac Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Wed, 17 Jun 2020 20:43:26 -0400 Subject: [PATCH] Initial prototype of proxy to allow plaintext gateway to HTTPS --- dehttps-proxy.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 dehttps-proxy.py diff --git a/dehttps-proxy.py b/dehttps-proxy.py new file mode 100755 index 0000000..9ad2aae --- /dev/null +++ b/dehttps-proxy.py @@ -0,0 +1,37 @@ +#!/usr/bin/python3 + +# +# Very simple prototype of an HTTP server that can perform HTTPS +# requests on behalf of a plaintext client. +# +# Bobbi June 2020 +# +# If this client is running on port 8000, then fetching: +# http://raspberrypi:8000/www.google.com +# Will fetch https://www.google.com +# + +import http.server, socketserver +import requests, sys + +PORT = 8000 + +class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + + def __init__(self, req, client_addr, server): + http.server.SimpleHTTPRequestHandler.__init__(self, req, client_addr, server) + + def do_GET(self): + url = 'https:/' + self.path + print('Getting {} ...'.format(url)) + file = requests.get(url, allow_redirects=True) + self.send_response(200) + self.send_header("Content-type", "text/html") + self.send_header("Content-length", len(file.content)) + self.end_headers() + self.wfile.write(file.content) + +handler = MyHTTPRequestHandler +httpd = socketserver.TCPServer(("", PORT), handler) +httpd.serve_forever() +