First, let's get started with ZAP: ZAP is an intercepting proxy that intercepts and re-encrypts HTTPS traffic for easy debugging. Click on the big blue button on the ZAP homepage to download it. If you choose to use another proxy (I hear Burp Proxy is a common choice) feel free to do so, as our approach should work with both. Now, whichever proxy you use. Let it export its certificate to a file, e.g., owasp_zap_root_ca.cer. You also have to make sure that ZAP does not listen on localhost, but on your public ethernet IP address. This is because b2g-desktop's localhost does not point to your desktop computer, but something within the b2g binary itself. For our example, we will use my IP address, 10.264.1.5.
Accepting certificates is a thing that happens in settings. As we had it earlier, these are stored in profiles. So here's a short primer in Firefox profiles:
Start the Firefox profile manager (-P), and make sure that the firefox to be called does not use any existing firefox sessions (-no-remote):
firefox -P -no-remote
Now create a new profile, called zapped. Go to the certificate settings: Edit, Preferences, Advanced, Encryption, View Certificates, Import. Now select the owasp_zap_root_ca.cer file and tell Firefox that it should trust this CA to identify web sites (this is really only valid for this profile).
Having used Firefox to create a certificate database for us, we can now use this db for our b2g profile. The name of your firefox profile directory is a randomg string that ends with zapped. The location depends on your operating system and can be determined by following this MozillaZine article. We only need the cert8.db file, which is the profile's certificate database. Copy it over to your b2g profile directory b2g/gaia/profile/ and overwrite the existing file.
The next step is setting ZAP as the default proxy for all network communication. The proxy settings are currently not available from the Firefox OS user interface, just like the certificate settings.
So we will append these custom settings to the preferences file, b2g/gaia/profile/prefs.js:
user_pref("network.proxy.backup.ftp", "10.264.1.5"); user_pref("network.proxy.backup.ftp_port", 8080); user_pref("network.proxy.backup.socks", "10.264.1.5"); user_pref("network.proxy.backup.socks_port", 8080); user_pref("network.proxy.backup.ssl", "10.264.1.5"); user_pref("network.proxy.backup.ssl_port", 8080); user_pref("network.proxy.ftp", "10.264.1.5"); user_pref("network.proxy.ftp_port", 8080); user_pref("network.proxy.http", "10.264.1.5"); user_pref("network.proxy.http_port", 8080); user_pref("network.proxy.no_proxies_on", ""); user_pref("network.proxy.share_proxy_settings", true); user_pref("network.proxy.socks", "10.264.1.5"); user_pref("network.proxy.socks_port", 8080); user_pref("network.proxy.ssl", "10.264.1.5"); user_pref("network.proxy.ssl_port", 8080); user_pref("network.proxy.type", 1);
Remember to replace my IP address 10.264.1.5 with yours, and if your proxy does not listen on port 8080, make sure you change it in this file too.
Now we should be good to go. Start b2g again and try some browsing. Things should show in ZAP now!