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 such as
owasp_zap_root_ca.cer. You also have to make sure that ZAP does not listen on
localhost, but instead 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.
Creating a certificate database
Accepting certificates is a thing that happens in settings. As discussed elsewhere, these are stored in profiles. So here's a short primer on Firefox profiles:
Start the Firefox profile manager suing the -P option on the command line, and make sure that the Firefox you start up does not use any existing Firefox sessions (
On Linux, you need to do:
firefox -P -no-remote
On Mac OS X:
/Applications/Firefox.app/Contents/MacOS/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 created by your proxy 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 database for our B2G profile. The name of your Firefox profile directory is a random string that ends with zapped. The location depends on your operating system; see Runtime Directories for details on where it can be found. 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/, overwriting the existing file.
Setting up B2G
The next step is to set 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,
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.
At this point, you should be ready to go.. Start B2G Desktop again and try some browsing. Network traffic should appear in ZAP.