Bug 1311515 - include information on whether system is at risk of bug 1296630 in the update ping. r=felipc
authorRobert Strong <robert.bugzilla@gmail.com>
Fri, 28 Oct 2016 13:57:17 -0700
changeset 320078 33c2241696c07a203f5355771a40a8c28a0767b5
parent 320077 0a1486cf11b228e41d27499b79b1e3ea6be3e28f
child 320079 62f38c70d152bbd94d617ecf64b76453bc5f57c3
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipc
bugs1311515, 1296630
milestone52.0a1
Bug 1311515 - include information on whether system is at risk of bug 1296630 in the update ping. r=felipc
browser/extensions/aushelper/bootstrap.js
browser/extensions/aushelper/install.rdf.in
browser/extensions/aushelper/moz.build
browser/extensions/moz.build
new file mode 100644
--- /dev/null
+++ b/browser/extensions/aushelper/bootstrap.js
@@ -0,0 +1,129 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* 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/. */
+
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+const APP_UPDATE_URL_PREF = "app.update.url";
+const REPLACE_KEY = "%OS_VERSION%";
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/TelemetryLog.jsm");
+
+function startup() {
+  if (Services.appinfo.OS != "WINNT") {
+    return;
+  }
+
+  const regCPUPath = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
+  let wrk;
+  try {
+    wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(Ci.nsIWindowsRegKey);
+    wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE, regCPUPath, wrk.ACCESS_READ);
+  } catch (e) {
+    Cu.reportError("Unable to open registry. Exception: " + e);
+    TelemetryLog.log("AUSHELPER_FATAL_ERROR", [e]);
+  }
+
+  // If any of the following values are successfully retrieved and they don't
+  // match the condition for that value then it is safe to update. Hence why the
+  // following checks are somewhat convoluted. The possible values for the
+  // variable set by each check is as follows:
+  //
+  //          | Match | No Match | Error |
+  // variable |  true |   false  |  null |
+
+  let cpuVendorIDMatch = false;
+  try {
+    let cpuVendorID = wrk.readStringValue("VendorIdentifier");
+    if (cpuVendorID.toLowerCase() == "genuineintel") {
+      cpuVendorIDMatch = true;
+    }
+  } catch (e) {
+    cpuVendorIDMatch = null;
+    Cu.reportError("Error getting CPU vendor indentifier. Exception: " + e);
+    TelemetryLog.log("AUSHELPER_CPU_VENDOR_ID_ERROR", [e]);
+  }
+
+  let cpuIDMatch = false;
+  try {
+    let cpuID = wrk.readStringValue("Identifier");
+    if (cpuID.toLowerCase().indexOf("family 6 model 61 stepping 4") != -1) {
+      cpuIDMatch = true;
+    }
+  } catch (e) {
+    cpuIDMatch = null;
+    Cu.reportError("Error getting CPU indentifier. Exception: " + e);
+    TelemetryLog.log("AUSHELPER_CPU_ID_ERROR", [e]);
+  }
+
+  let microCodeVersions = [0xe, 0x11, 0x12, 0x13, 0x16, 0x18, 0x19];
+  let cpuRevMatch = false;
+  try {
+    let keyNames = ["Update Revision", "Update Signature"];
+    for (let i = 0; i < keyNames.length; ++i) {
+      try {
+        let regVal = wrk.readBinaryValue(keyNames[i]);
+        if (regVal.length == 8) {
+          let hexVal = [];
+          // We are only inyterested in the highest byte and return the little
+          // endian value for it.
+          for (let j = 4; j < 8; j++) {
+            let c = regVal.charCodeAt(j).toString(16);
+            if (c.length == 1) {
+              c = "0" + c;
+            }
+            hexVal.unshift(c);
+          }
+          if (microCodeVersions.indexOf(parseInt(hexVal.join(''))) != -1) {
+            cpuRevMatch = true;
+          }
+          break;
+        }
+      } catch (e) {
+        if (i == keyNames.length - 1) {
+          // The registry key name's value was not successfully queried.
+          cpuRevMatch = null;
+          Cu.reportError("Error getting CPU revision. Exception: " + e);
+          TelemetryLog.log("AUSHELPER_CPU_REV_ERROR", [e]);
+        }
+      }
+    }
+  } catch (ex) {
+    cpuRevMatch = null;
+    Cu.reportError("Error getting CPU revision. Exception: " + ex);
+    TelemetryLog.log("AUSHELPER_CPU_REV_ERROR", [ex]);
+  }
+
+  let resultCode = 3;
+  let newValue = "(unkBug1296630v1)";
+  // The following uses strict equality checks since the values can be true,
+  // false, or null.
+  if (cpuVendorIDMatch === false || cpuIDMatch === false || cpuRevMatch === false) {
+    // Since one of the values is false then the system won't be affected by
+    // bug 1296630 according to the conditions set out in bug 1311515.
+    newValue = "(noBug1296630v1)";
+    resultCode = 0;
+  } else if (cpuVendorIDMatch === null || cpuIDMatch === null || cpuRevMatch === null) {
+    // Since one of the values is null we can't say for sure if the system will
+    // be affected by bug 1296630.
+    newValue = "(errBug1296630v1)";
+    resultCode = 2;
+  } else if (cpuVendorIDMatch === true && cpuIDMatch === true && cpuRevMatch === true) {
+    // Since all of the values are true we can say that the system will be
+    // affected by bug 1296630.
+    newValue = "(yesBug1296630v1)";
+    resultCode = 1;
+  }
+
+  let defaultBranch = Services.prefs.getDefaultBranch("");
+  let curPrefValue = defaultBranch.getCharPref(APP_UPDATE_URL_PREF);
+  let newPrefValue = curPrefValue.replace(REPLACE_KEY + "/", REPLACE_KEY + newValue + "/");
+  defaultBranch.setCharPref(APP_UPDATE_URL_PREF, newPrefValue);
+  TelemetryLog.log("AUSHELPER_RESULT", [resultCode]);
+}
+
+function shutdown() {}
+function install() {}
+function uninstall() {}
new file mode 100644
--- /dev/null
+++ b/browser/extensions/aushelper/install.rdf.in
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!-- 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/. -->
+
+#filter substitution
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>aushelper@mozilla.org</em:id>
+    <em:version>1.0</em:version>
+    <em:type>2</em:type>
+    <em:bootstrap>true</em:bootstrap>
+    <em:multiprocessCompatible>true</em:multiprocessCompatible>
+
+    <!-- Target Application this extension can install into,
+        with minimum and maximum supported versions. -->
+    <em:targetApplication>
+      <Description>
+        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+        <em:minVersion>@MOZ_APP_VERSION@</em:minVersion>
+        <em:maxVersion>@MOZ_APP_MAXVERSION@</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+    <!-- Front End MetaData -->
+    <em:name>Application Update Service Helper</em:name>
+    <em:description>Sets value(s) in the update url based on custom checks.</em:description>
+  </Description>
+</RDF>
new file mode 100644
--- /dev/null
+++ b/browser/extensions/aushelper/moz.build
@@ -0,0 +1,16 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
+DEFINES['MOZ_APP_MAXVERSION'] = CONFIG['MOZ_APP_MAXVERSION']
+
+FINAL_TARGET_FILES.features['aushelper@mozilla.org'] += [
+  'bootstrap.js'
+]
+
+FINAL_TARGET_PP_FILES.features['aushelper@mozilla.org'] += [
+  'install.rdf.in'
+]
--- a/browser/extensions/moz.build
+++ b/browser/extensions/moz.build
@@ -1,15 +1,16 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 DIRS += [
+    'aushelper',
     'e10srollout',
     'pdfjs',
     'pocket',
     'webcompat',
 ]
 
 # Only include the following system add-ons if building Aurora or Nightly
 if 'a' in CONFIG['GRE_MILESTONE']: