Bug 1359127 - Initial Mozharness support for mitmproxy r=aki
authorArmen Zambrano G. <armenzg@mozilla.com>
Mon, 01 May 2017 14:58:01 -0400
changeset 356505 b06d3343f43a1ceacf22293e5a3650195a6211fc
parent 356504 f7d6828ad9d94faa983d05fa10f6259ba64265db
child 356506 5510b2c782088b5040df1132fbc06c55cf5a9117
push id31767
push usercbook@mozilla.com
push dateFri, 05 May 2017 13:15:58 +0000
treeherdermozilla-central@8872ad4d52b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaki
bugs1359127
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359127 - Initial Mozharness support for mitmproxy r=aki This change allows a script to have mitmproxy set up support. This will make a Firefox installation to import the cert from the mitmproxy and selecting it as a proxy. MozReview-Commit-ID: FweyOCzWyN9
testing/mozharness/mozharness/mozilla/mitmproxy.py
new file mode 100644
--- /dev/null
+++ b/testing/mozharness/mozharness/mozilla/mitmproxy.py
@@ -0,0 +1,47 @@
+'''This helps loading mitmproxy's cert and change proxy settings for Firefox.'''
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+import os
+from mozharness.mozilla.firefox.autoconfig import write_autoconfig_files
+
+DEFAULT_CERT_PATH = os.path.join(os.getenv('HOME'),
+                                 '.mitmproxy', 'mitmproxy-ca-cert.cer')
+MITMPROXY_SETTINGS = '''// Start with a comment
+// Load up mitmproxy cert
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(Ci.nsIX509CertDB);
+var certdb2 = certdb;
+
+try {
+certdb2 = Cc["@mozilla.org/security/x509certdb;1"].getService(Ci.nsIX509CertDB2);
+} catch (e) {}
+
+cert = "%(cert)s";
+certdb2.addCertFromBase64(cert, "C,C,C", "");
+
+// Use mitmdump as the proxy
+// Manual proxy configuration
+pref("network.proxy.type", 1);
+pref("network.proxy.http", "127.0.0.1");
+pref("network.proxy.http_port", 8080);
+pref("network.proxy.ssl", "127.0.0.1");
+pref("network.proxy.ssl_port", 8080);
+'''
+
+
+def configure_mitmproxy(fx_install_dir, certificate_path=DEFAULT_CERT_PATH):
+        certificate = _read_certificate(certificate_path)
+        write_autoconfig_files(fx_install_dir=fx_install_dir,
+                               cfg_contents=MITMPROXY_SETTINGS % {
+                                  'cert': certificate})
+
+
+def _read_certificate(certificate_path):
+    ''' Return the certificate's hash from the certificate file.'''
+    # NOTE: mitmproxy's certificates do not exist until one of its binaries
+    #       has been executed once on the host
+    with open(certificate_path, 'r') as fd:
+        contents = fd.read()
+    return ''.join(contents.splitlines()[1:-1])