modules/libjar/test/chrome/test_bug386153.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=386153
     5 -->
     6 <head>
     7   <title>Test for Bug 386153</title>
     8   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    10   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386153">Mozilla Bug 386153</a>
    14 <p id="display"></p>
    15 <div id="content" style="display: none">
    17 </div>
    18 <pre id="test">
    19 <script type="application/javascript">
    21 /** Test for Bug 386153 **/
    23 const Cc = Components.classes;
    24 const Ci = Components.interfaces;
    26 // Opens a zip file from the test directory.
    27 function openZip(path) {
    29   var location = window.location.href;
    30   location = getRootDirectory(location);
    31   var jar = getJar(location);
    32   if (jar != null) {
    33     var resolved = extractJarToTmp(jar);
    34   } else {
    35     var resolvedURI = getResolvedURI(window.location.href);
    36     var resolved = getChromeDir(resolvedURI);
    37   }
    38   resolved.append(path);
    40   var zip = Cc["@mozilla.org/libjar/zip-reader;1"].
    41             createInstance(Ci.nsIZipReader);
    42   zip.open(resolved);
    43   return zip;
    44 }
    46 // Gets the pretty name from the signing cert or null if the zip is unsigned.
    47 function getSigner(zip) {
    48   var principal = zip.getCertificatePrincipal(null);
    49   if (principal && principal.hasCertificate)
    50     return principal.prettyName;
    51   return null;
    52 }
    54 function verifySigning(zip) {
    55   var principal = zip.getCertificatePrincipal(null);
    56   var count = 0;
    57   var entries = zip.findEntries(null);
    58   while (entries.hasMore()) {
    59     var entry = entries.getNext();
    60     // Nothing in META-INF is in the manifest.
    61     if (entry.substr(0, 9) == "META-INF/")
    62       continue;
    63     // Directory entries aren't in the manifest.
    64     if (entry.substr(-1) == "/")
    65       continue;
    66     count++;
    67     var entryPrincipal = zip.getCertificatePrincipal(entry);
    68     if (!entryPrincipal || !principal.equals(entryPrincipal))
    69       return false;
    70   }
    71   return zip.manifestEntriesCount == count;
    72 }
    74 var zip = openZip("unsigned.zip");
    75 is(getSigner(zip), null, "Should not be signed");
    77 zip = openZip("signed.zip");
    78 is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
    79 ok(verifySigning(zip), "Should be correctly signed");
    81 zip = openZip("signed-added.zip");
    82 is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
    83 ok(!verifySigning(zip), "Should be incorrectly signed");
    85 zip = openZip("signed-tampered.zip");
    86 is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
    87 ok(!verifySigning(zip), "Should be incorrectly signed");
    89 zip = openZip("signed-badca.zip");
    90 is(getSigner(zip), null, "Should not appear to be signed");
    92 </script>
    93 </pre>
    94 </body>
    95 </html>

mercurial