Debugging Tune SDK Integration Using Mitmproxy

mitmproxy HTTP Proxy

mitmproxy (man-in-the-middle) HTTP proxy allows you to view the network request-response contents being sent over the network. This technique comes in handy when debugging Tune SDK integration and to ensure that an app downloaded from the App Store fires the expected network requests. On Mac OS X, mitmproxy provides a great free option to do just that.

Install mitmproxy on the Mac

Download and Install

Install from command-line (Terminal window) using pip.

$ pip install mitmproxy

OR

  • Download latest mitmproxy.
  • Un-archive the downloaded file, it should contain the mitmproxy module.

You can find more info at https://mitmproxy.org.

Find Out the IP Address of Your Mac

Open a Terminal window and run the following command:

$ ifconfig | grep 192

Output similar to the following appears:

inet 192.168.12.123 netmask 0xffffff00 broadcast 192.168.87.255

In the previous example, the Mac IP address is: 192.168.12.123
If you see multiple IP addresses in the ifconfig output, then one of those IP addresses (generally the first) will be the correct IP address to use as the proxy address.

Run mitmproxy

Open a Terminal window.
If you used the first method (using pip) to install, then mitmproxy should be available anywhere and can be run as follows:

$ mitmproxy

If using the second method of downloaded archive, you should open the folder that contains the mitmproxy module:

$ ./mitmproxy

A window similar to the following appears:

mitmproxy_window-300x217

Add Ignore-Pattern

By default, mitmproxy intercepts all network requests. To intercept only some specific requests, set an ignore-pattern in mitmproxy. Requests that don’t match the pattern will bypass mitmproxy. Adding an ignore-pattern is especially important if your app accesses the iTunes App Store for in-app purchases or if you need to download an app from the App Store (because the iTunes App Store cannot be accessed through an HTTP proxy due to SSL certificate pinning restrictions).

To intercept requests fired only by Tune SDK:

    1. Once mitmproxy starts, click capital ‘i’ to see the list of host regex patterns.
    2. Click ‘a’ to add a new pattern and paste the following:
^((?!mobileapptr|tuneapi|measurementapi).)*$
  1. Save the pattern by clicking — Right Arrow, Right Arrow, Tab. The window should look similar to: IMAGE
  2. Click ‘q’ to go return one screen.

Setup Your Mobile Device To Use mitmproxy Running On Your Mac

  1. Make sure mitmproxy is running on your Mac.
  2. On your mobile device, open the network settings Wifi section.
  3. Select the same Wifi network as the one on your Mac.
  4. Edit the wifi network settings to set an http proxy. Under the HTTP Proxy settings:
    • Select “Manual” option.
    • Set the value of Server to the IP address of your Mac (192.168.12.123 in the above example).
    • Set the value of Port to the port value that shows up in the mitmproxy window (8080 in the above example).
    • Leave authentication, username, and password empty.
  5. Tune SDKs use HTTPS requests. To allow the proxy to handle the HTTPS traffic, a certificate needs to be installed on your mobile device. To install the certificate:
    • Open “mitm.it” in the mobile web browser. This should open a webpage that will allow you to download the mitmproxy certificate.
    • Click the icon for your mobile platform: iOS, Android, etc.
    • When the downloaded file opens automatically, click Install to install the proxy certificate.

Now you can view the network traffic from your mobile device through mitmproxy.

NOTE: Some of the apps may not be able to access the internet when using mitmproxy, notably parts of the Apple iTunes ‘App Store’ app.

Verify Expected Network Results

  1. Run your app and check the mitmproxy window to make sure that the expected network requests are being fired for each Tune measure call.
  2. A network request list appears
  3. When you are finished using mitmproxy:
    • Disable the http proxy on your mobile device.
    • Quit mitmproxy module on your MAC.

No Comments

Leave a reply