|
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"> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript"> |
|
20 |
|
21 /** Test for Bug 386153 **/ |
|
22 |
|
23 const Cc = Components.classes; |
|
24 const Ci = Components.interfaces; |
|
25 |
|
26 // Opens a zip file from the test directory. |
|
27 function openZip(path) { |
|
28 |
|
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); |
|
39 |
|
40 var zip = Cc["@mozilla.org/libjar/zip-reader;1"]. |
|
41 createInstance(Ci.nsIZipReader); |
|
42 zip.open(resolved); |
|
43 return zip; |
|
44 } |
|
45 |
|
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 } |
|
53 |
|
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 } |
|
73 |
|
74 var zip = openZip("unsigned.zip"); |
|
75 is(getSigner(zip), null, "Should not be signed"); |
|
76 |
|
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"); |
|
80 |
|
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"); |
|
84 |
|
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"); |
|
88 |
|
89 zip = openZip("signed-badca.zip"); |
|
90 is(getSigner(zip), null, "Should not appear to be signed"); |
|
91 |
|
92 </script> |
|
93 </pre> |
|
94 </body> |
|
95 </html> |