lainchan / λ

Writing an HTTPS proxy

Bob Arctor · 2017-10-07 14:12
So I am writing an HTTP proxy in python3 that works totally fine with plain http. The problem is, as soon as I try to switch to https, the thing breaks down. This might sound like a really simple, dump question, but bear with me here. My approach is the following: The proxy provides a simple http server for the client to connect to. It reads the data sent by the client, makes a connection to the target server, and forwards the unmodified data. So far I've done the HTTP server part, as of now it just responds to GET requests with a sample HTML page. So, lets say I can view the sample page in the browser at http://localhost:8080, I can then enter the same data into my proxy settings and automaticaly get back the sample page as a response to any HTTP GET request I make on the device. So I thought I could do the same thing over HTTPS with a self signed SSL certificate, I used the same approach as above, I can access the sample page over a secure connection at https://localhost:8080, get no warning, since I installed the certificate on my client device, however, whenever I then try to make an HTTPS GET request, I get no response, the code that should serve the request does not even run. Now, I know that this kind of interception is possible, since I've done it on the same device before, only through burp suite, which also uses a self signed certificate. What am I missing here? How does burpsuite do it? I can post my code if necessary to further help the understanding of my problem. Also, sorry if this is not an especially interesting post that contributes a lot to this board, but since it is a long question, I thought it would warrant its own thread, maybe someone else can learn from it too.
Zhora · 2017-10-07 14:16
OP here, I might also add that this is not for any kind of nefarious purpose. My goal is to monitor web traffic from my iPhone and log connections to ad networks, in order to study the way apps track my behaviour.
Lady 3Jane.. · 2018-01-16 23:09
What IDE is that? More specifically, what color scheme?