Bug 1210573 - Add attribute 'packageIdentifier' to nsIPackagedAppUtils. r=valentin.
authorHenry <hchang@mozilla.com>
Wed, 07 Oct 2015 20:02:00 +0200
changeset 266845 189ab4d27daf760a4f5be489d7f860ceb97eebd7
parent 266844 2873ffc036efddbafb37e4181c6b53a5439ee2a1
child 266846 b185293e7db6b8a3f48389e457ba1edc71327bc8
push id29499
push userkwierso@gmail.com
push dateThu, 08 Oct 2015 21:29:10 +0000
treeherdermozilla-central@46da59584acb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1210573
milestone44.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 1210573 - Add attribute 'packageIdentifier' to nsIPackagedAppUtils. r=valentin.
netwerk/base/nsIPackagedAppUtils.idl
netwerk/protocol/http/PackagedAppUtils.js
netwerk/test/unit/test_packaged_app_utils.js
--- a/netwerk/base/nsIPackagedAppUtils.idl
+++ b/netwerk/base/nsIPackagedAppUtils.idl
@@ -19,17 +19,17 @@ interface nsIVerificationCallback;
  * store the hash values of each resource. When a resource is ready, Necko
  * will calculate its hash value (including the header like Content-Location: xxx),
  * and calls checkIntegrity(...) to verify the integrity.
  *
  * For more detail:
  *   https://wiki.mozilla.org/FirefoxOS/New_security_model/Packaging
  */
 
-[scriptable, uuid(d0a98a69-a215-4cf9-abb3-7a0b9237cd27)]
+[scriptable, uuid(cc245638-6a38-4f70-8d77-21c55aabd636)]
 interface nsIPackagedAppUtils : nsISupports
 {
   /**
    * @aHeader is the package's header including
    *   - "manifest-signature: xxxxxx" (base64 encoding)
    * @aManifest is the manifest of the package
    *   - the multipart header is included
    *   - manifest must be the first resource of the package
@@ -43,16 +43,22 @@ interface nsIPackagedAppUtils : nsISuppo
    * @aFileName is the name of a resource in the package
    * @aHashValue is the hash value of this resource named aFileName
    *   - aHashValue should be computed by the caller of this method
    * @aCallback is the callback, see comments of nsIVerificationCallback below
    */
   void checkIntegrity(in ACString aFileName,
                       in ACString aHashValue,
                       in nsIVerificationCallback aVerifier);
+
+  /**
+   * The package identifier for signed package. Only available after the
+   * manifest is verified.
+   */
+  readonly attribute ACString packageIdentifier;
 };
 
 /**
   * The callback passed to verifyManifest and checkIntegrity
   */
 [scriptable, uuid(e1912028-93e5-4378-aa3f-a58702937169)]
 interface nsIVerificationCallback : nsISupports
 {
--- a/netwerk/protocol/http/PackagedAppUtils.js
+++ b/netwerk/protocol/http/PackagedAppUtils.js
@@ -8,17 +8,17 @@
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const PACKAGEDAPPUTILS_CONTRACTID = "@mozilla.org/network/packaged-app-utils;1";
 const PACKAGEDAPPUTILS_CID = Components.ID("{fe8f1c2e-3c13-11e5-9a3f-bbf47d1e6697}");
 
 function PackagedAppUtils() {
-
+  this.packageIdentifier = '';
 }
 
 var DEBUG = 0
 function debug(s) {
   if (DEBUG) {
     dump("-*- PackagedAppUtils: " + s + "\n");
   }
 }
@@ -52,17 +52,19 @@ PackagedAppUtils.prototype = {
       // Base64 decode
       signature = atob(signature);
 
       // Remove header
       let manifestBody = aManifest.substr(aManifest.indexOf('\r\n\r\n') + 4);
       debug("manifestBody: " + manifestBody);
 
       // Parse manifest, store resource hashes
-      this.resources = JSON.parse(manifestBody)["moz-resources"];
+      let manifestObj = JSON.parse(manifestBody);
+      this.resources = manifestObj["moz-resources"];
+      this.packageIdentifier = manifestObj["package-identifier"];
     } catch (e) {
       debug("JSON parsing failure");
       aCallback.fireVerifiedEvent(true, false);
       return;
     }
 
     let manifestStream = Cc["@mozilla.org/io/string-input-stream;1"]
                            .createInstance(Ci.nsIStringInputStream);
--- a/netwerk/test/unit/test_packaged_app_utils.js
+++ b/netwerk/test/unit/test_packaged_app_utils.js
@@ -1,24 +1,24 @@
 const header_missing_signature = "header1: content1";
 const header_invalid_signature = "header1: content1\r\n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5pWeXuTZ459qDxOnQd+GrOe4dIeqflk0hA2xYKe3SfF+QlK8EO370B8Dj8RX230OATM1E3OtYyALe34KW3wM9Qm9rb0eViDnVyDiCWkhhQnw5yPg/XQfloug2itRYuCnfUoRt8xfeHgwz2Ymz8cUADn3KpTGCAf4wggH6AgEBMHgwczELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MSQwIgYDVQQKExtFeGFtcGxlIFRydXN0ZWQgQ29ycG9yYXRpb24xGTAXBgNVBAMTEFRydXN0ZWQgVmFsaWQgQ0ECAQIwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE1MTAwMTIxMTEwNlowIwYJKoZIhvcNAQkEMRYEFHAisUYrrt+gBxYFhZ5KQQusOmN3MA0GCSqGSIb3DQEBAQUABIIBACHW4V0BsPWOvWrGOTRj6mPpNbH/JI1bN2oyqQZrpUQoaBY+BbYxO7TY4Uwe+aeIR/TTPJznOMF/dl3Bna6TPabezU4ylg7TVFI6W7zC5f5DZKp+Xv6uTX6knUzbbW1fkJqMtE8hGUzYXc3/C++Ci6kuOzrpWOhk6DpJHeUO/ioV56H0+QK/oMAjYpEsOohaPqvTPNOBhMQ0OQP3bmuJ6HcjZ/oz96PpzXUPKT1tDe6VykIYkV5NvtC8Tu2lDbYvp9ug3gyDgdyNSV47y5i/iWkzEhsAJB+9Z50wKhplnkxxVHEXkB/6tmfvExvQ28gLd/VbaEGDX2ljCaTSUjhD0o0=\r\n";
 
 const manifest = "Content-Location: manifest.webapp\r\n" +
   "Content-Type: application/x-web-app-manifest+json\r\n\r\n" +
 `{
   "name": "My App",
   "moz-resources": [
     {
       "src": "page2.html",
       "integrity": "JREF3JbXGvZ+I1KHtoz3f46ZkeIPrvXtG4VyFQrJ7II="
     },
     {
       "src": "index.html",
-      "integrity": "B5Phw8L1tpyRBkI0gwg/evy1fgtMlMq3BIY3Q8X0rYU="
+      "integrity": "zEubR310nePwd30NThIuoCxKJdnz7Mf5z+dZHUbH1SE="
     },
     {
       "src": "scripts/script.js",
       "integrity": "6TqtNArQKrrsXEQWu3D9ZD8xvDRIkhyV6zVdTcmsT5Q="
     },
     {
       "src": "scripts/library.js",
       "integrity": "TN2ByXZiaBiBCvS4MeZ02UyNi44vED+KjdjLInUl4o8="
@@ -29,17 +29,17 @@ const manifest = "Content-Location: mani
       "systemXHR": {
         "description": "Needed to download stuff"
       },
       "devicestorage:pictures": {
         "description": "Need to load pictures"
       }
     }
   ],
-  "moz-uuid": "some-uuid",
+  "package-identifier": "611FC2FE-491D-4A47-B3B3-43FBDF6F404F",
   "moz-package-location": "https://example.com/myapp/app.pak",
   "description": "A great app!"
 }`;
 
 const manifest_missing_moz_resources = "Content-Location: manifest.webapp\r\n" +
   "Content-Type: application/x-web-app-manifest+json\r\n\r\n" +
 `{
   "name": "My App",
@@ -81,16 +81,24 @@ function test_verify_manifest(aHeader, a
   return function() {
     do_test_pending();
     packagedAppUtils = Cc["@mozilla.org/network/packaged-app-utils;1"].
                        createInstance(Ci.nsIPackagedAppUtils);
     let fakeVerifier = {
       fireVerifiedEvent: function(aForManifest, aSuccess) {
         ok(aForManifest, "aForManifest should be true");
         equal(aSuccess, aShouldSucceed, "Expected verification result: " + aShouldSucceed);
+
+        // Verify packageIdentifier if it's a successful verification.
+        if (aShouldSucceed) {
+           equal(packagedAppUtils.packageIdentifier,
+                 '611FC2FE-491D-4A47-B3B3-43FBDF6F404F',
+                 'package identifier');
+        }
+
         do_test_finished();
         run_next_test();
       }
     };
     packagedAppUtils.verifyManifest(aHeader, aManifest, fakeVerifier);
   }
 }