How To Combine Charles With Tunnel Bear

The Short Answer

It's important to start proxying in the correct sequence. Otherwise, Charles won't proxy through Tunnel Bear.

1. Run Charles
2. Charles -> Proxy -> Windows Proxy (or MacOS Proxy on a Mac)
3. Charles -> Stop Recording
4. Charles -> Stop SSL Proxying
5. Run Tunnel Bear
6. Charles -> Start Recording
7. Charles -> Start SSL Proxying

Background
Writing software for an American company while in Mexico, I often have to tunnel to a US IP address in order to view ads targeted at US consumers. (Yes, part of my job is staring at ads, and making sure I see the right ones. Ads are currently a big part of how I and my coworkers pay our bills.) Similarly, certain features of the app I currently work on are geo-fenced, in order to avoid, for example, showing US-licensed video content outside the US. So I run Tunnel Bear on my phone, then run may app, and the server-side sees me as a US-based user. My tunneling tool of choice is Tunnel Bear. It works, it's simple, it's reasonably priced... and it's cute.

In order to test the app's network activity, I often use Charles. The Charles proxy runs on my laptop, and my Android phone is configured to route all network traffic through that proxy. This allows me to see all the network traffic for my app.

But what happens when I need to view network activity via the Charles proxy and tunnel to a US IP address? If I config my phone to proxy through Charles, I can't also proxy through Tunnel Bear on my phone — since the whole point of Tunnel Bear is to make it easy. So I run both Tunnel Bear and Charles on my laptop, and the network requests that originate from my phone are routed through Charles, then through Tunnel Bear. But this only works if the two proxies are brought to life in the correct order. I had occasionally gotten it to work, but it was this answer on Stack Overflow that led me to a repeatable sequence, listed in the Short Answer section above. I've found that step 2 can occur later in the process and it still works, but I've kept the original order since I don't see any advantage to changing it.

What's going on under the covers? I have some idea... but my grasp of the networking specifics is too sketchy to warrant my sharing fuzzy guesswork with you. So I'll leave it as a Recipe For Success post, and hopefully it allows you to clear this hurdle and move onto more interesting work.



comments powered by Disqus