Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
4ae574b
Created a simple utility to help automate the task of creating a vali…
May 22, 2014
28063e4
Merge branch 'master' into makeJSONManifest
May 27, 2014
5c4e544
Remove example usage from comments
May 27, 2014
b79c7aa
Remove db_signature field from update object since the update_signatu…
May 27, 2014
231faa8
starting code for checking for updates
May 28, 2014
9bd9b26
Removed unnecessary uses of string conversions
May 29, 2014
675fe0d
Check version of the ruleset release
May 30, 2014
badb392
Outline code to start handling the new database file source
May 30, 2014
db775b2
Use the XPCOM interface for creating XMLHttpRequests.
May 30, 2014
8617a9b
Build the skeleton for applying the update
May 30, 2014
0d2b220
Write comments describing the function and parameters to each function
May 31, 2014
8cd6463
Fill out the helper functions
Jun 1, 2014
a6480c5
Merge branch 'master' into rulesetUpdating
Jun 2, 2014
5bf27fe
Prefix function call with this
Jun 2, 2014
79a09cc
Check the release type of the extension to make sure only ruleset rel…
Jun 2, 2014
099cf24
Use Char type to properly access preferences
Jun 3, 2014
550151c
Check the version of the ruleset release, branch type, and database f…
Jun 3, 2014
9b1161a
Wrote a closure-producing function that can be clearly called from se…
Jun 8, 2014
5ab7ee1
Merge branch 'master' into rulesetUpdating
Jun 8, 2014
7de288c
Change json builder script to reflect changes to version spec
Jun 8, 2014
eaff577
Compute the hash of the update object automatically and deterministic…
Jun 12, 2014
09c68af
update utility to match new spec, hash db file and b64 encode, write …
Jun 16, 2014
eb38eae
Create a little testing environment for proof-of-concepts regarding u…
Jun 16, 2014
f812b6b
Added some nice sanity testing
Jun 16, 2014
48d05be
Created proof-of-concept signature verifier along with data needed to…
Jun 19, 2014
f2e79ae
Making the update.json specification document part of the repo to all…
Jun 19, 2014
86d2b0d
Include link to the old gist in the spec doc so people can see commen…
Jun 19, 2014
4b1194f
Merge branch 'master' into makeJSONManifest
Jun 19, 2014
045f745
Reword explanation about why XHR is used instead of the builtin exten…
Jun 19, 2014
aca548f
Explain that the header and footer need to be removed from the signat…
Jun 19, 2014
307de5e
Specify update checking wait interval in terms of milliseconds
Jun 19, 2014
d3eaa98
Mention the fact that the way error reports is to be handled hasn't b…
Jun 19, 2014
42eb333
Better wording for how update is applied and reference to pseudocode
Jun 19, 2014
ba77983
Change date format to dd-mm-yyyy
Jun 19, 2014
267cff4
Update pseudocode with some more security checks and reference to the…
Jun 19, 2014
4491874
Set inauthentic to false after everything succeeds
Jun 19, 2014
09acae0
Add a field to the JSON document spec to specify the hash function to…
Jun 19, 2014
3108ec7
Add support for specifying hash function to use and related sanity ch…
Jun 19, 2014
e03b106
changed date format to dd-mm-yyyy
Jun 19, 2014
7695107
Instructions about removing the header and footer from the public key…
Jun 19, 2014
276135a
trying to fix up the test
Jun 20, 2014
5d47b47
Merge branch 'master' into rulesetUpdating
Jun 20, 2014
1a0d5ed
Added function to HTTPSEverywhere prototype to allow for repeating XH…
Jun 20, 2014
999b110
Working on a rewrite to meet new spec reqs
Jun 20, 2014
4d58418
Write update.json in a more human-readible form that is still parseab…
Jun 20, 2014
466be71
Include instructions for computing the digest of update.json to sign …
Jun 20, 2014
aa33e09
Finished updating rulesetUpdate to meet new spec requirements
Jun 20, 2014
972c4df
Change order of fields in json spec to match output order
Jun 20, 2014
52058e1
Encode the hash of the database file as hex to match how the JS code …
Jun 20, 2014
3d0019c
Clarify that the hash field is hex-encoded and order the fields alpha…
Jun 20, 2014
149cc95
Forgot a bloody comma
Jun 20, 2014
aa79bd5
Fixed innappropriate quote
Jun 20, 2014
4681cd8
Merge branch 'master' into makeJSONManifest
Jun 24, 2014
9e0718d
Merge branch 'makeJSONManifest' into rulesetUpdating
Jun 24, 2014
8d69b76
Merge branch 'master' into rulesetUpdating
Jun 30, 2014
d03e1bf
Add commas to key-value pair separator
Jun 30, 2014
8eb59ef
Create new example data
Jun 30, 2014
a687f91
fixed typing mistake in accessing of Ci.nsICryptoHash
Jun 30, 2014
160564b
Write a test for update.json signature verification
Jun 30, 2014
e40bab2
Merge branch 'master' into rulesetUpdating
Jun 30, 2014
65d10f8
asserting inside a callback caused test to be considered empty and fa…
Jun 30, 2014
cde74ce
Fixing the silly things I did
Jun 30, 2014
c8e0c50
Simplify expression
Jun 30, 2014
f2ad886
Was addressing the wrong attribute of the converter object
Jun 30, 2014
e7d2c6b
write values as strings instead of calling Array.join
Jun 30, 2014
64c2684
Add test for hashing of update.json and also hardcoded the data properly
Jul 1, 2014
49ce44c
test that the verifier component was created successfully
Jul 2, 2014
691d348
Creating new testing data
Jul 3, 2014
c18f81f
Create new testing keys, data, and signature
Jul 3, 2014
9727808
Update to use new data
Jul 3, 2014
d5b64e1
Accidentally added a \n to update.json when experimenting- accounting…
Jul 3, 2014
71baef6
Import and test atob and btoa
Jul 3, 2014
659def1
Should not need to convert the signature to binary-encoding
Jul 3, 2014
cea04b6
Ignore me
Jul 4, 2014
1b7b5e3
Revert "Ignore me"
Jul 4, 2014
124a9e8
Write instructions for signing and verifying signatures using openssl…
Jul 4, 2014
fe44984
New test data with signature and digest that can be verified with new…
Jul 4, 2014
b54940d
Write an endline at the end of update.json
Jul 4, 2014
1637dbe
New data
Jul 4, 2014
c69fed6
Adding new data
Jul 4, 2014
823137e
Finished adding new data but the test still fails
Jul 4, 2014
c28e6e2
Try the test with a 1024-bit key and signature based thereupon in cas…
Jul 4, 2014
8bc530f
Mention that the public key can also be DER and then Base64 encoded
Jul 6, 2014
7d234aa
Data generated with a 1024-bit RSA key
Jul 7, 2014
8b3c85d
Include Yan's patch that uses data generated with NSS-tools and passe…
Jul 7, 2014
3a97da9
Wrote tests for version comparison
Jul 16, 2014
7b700f9
Fixed my test mistake
Jul 16, 2014
f1eceae
Remove log function definition from RulesetUpdater code in favor of s…
Jul 16, 2014
ed9ce89
Initialize ruleset updater in HTTPSEverywhere initialization code and…
Jul 16, 2014
108dd60
Add default preference values for prefs needed by RS Updater
Jul 18, 2014
a8ff724
cleaned up version comparison test
Jul 18, 2014
0b63b8b
Simple script to run a server that files can be fetched from for testing
Jul 18, 2014
7e05cef
Add some test data to be requested with an XHR
Jul 20, 2014
c5548b6
Implement tests for the try_request function used to periodically fet…
Jul 20, 2014
5659d48
Testing XHRs is not working out because asserts cannot occur in callb…
Jul 20, 2014
097312c
Added required preferences
Jul 28, 2014
0d50aac
Added data for testing purposes
Jul 28, 2014
94f066e
Added logging for program flow inspection
Jul 28, 2014
ffc630a
Added a ruleset database file to testing directory for fetch tests
Jul 29, 2014
2f9ed28
Created new update.json for practical testing, a script to run a simp…
Jul 29, 2014
eb84c87
Use a less verbose logging level
Jul 29, 2014
a4ebd28
Refactor to define RulesetUpdater as an object literal to avoid cycli…
Jul 31, 2014
b01b120
Expose module-level constants through functions
Jul 31, 2014
f9651d6
Default the ruleset version to 4.0.17.0 so that the first version to …
Jul 31, 2014
f17f2b0
Start ruleset update information fetching from code that executes onc…
Jul 31, 2014
73fa596
Had to completely refactor again to conform to JS's interpreter's top…
Jul 31, 2014
663bd0f
Resolve merge conflicts
Jul 31, 2014
3d9384b
Retrying signature generation and making sure the hash is correct
Aug 1, 2014
e3466fa
Re-entered key
Aug 1, 2014
e485059
Copied the correct signature in
Aug 1, 2014
9842544
Clear data for new data to be entered
Aug 1, 2014
9aa5463
Trying test with new data
Aug 1, 2014
32f3a26
Revert "Trying test with new data"
Aug 1, 2014
da7fb6f
Revert "Clear data for new data to be entered"
Aug 1, 2014
cac670e
Remove stuff accidentally merged from features/tests a while ago
Aug 3, 2014
a899290
Generated new test data but signature verification still fails; signa…
Aug 4, 2014
c60bb6b
Add a preference to toggle the ruleset updater and move the code to m…
Aug 5, 2014
ccfd71d
Set the ruleset update interval to be a preference
Aug 5, 2014
d6f181f
Added UI element for toggling the ruleset updater
Aug 5, 2014
9c78f01
If we do NOT hash UPDATE_JSON and use the signature taken over update…
Aug 8, 2014
37471ee
Clean up pubkey and signature
Aug 8, 2014
577d5b4
Use the test data that passed the unit tests for the last phase of te…
Aug 8, 2014
6e3077f
Updated preferences and did some bugfixing
Aug 8, 2014
4e0e447
Use new test data in rulesetUpdater
Aug 8, 2014
32fc580
New data
Aug 9, 2014
92c7658
Use Downloads.jsm to download rulesets.sqlite so the binary data does…
Aug 9, 2014
64468c5
Had trouble with OS.Path for some reason
Aug 9, 2014
a5c8a88
Try to report errors
Aug 9, 2014
6a0e4ae
Do some renaming to avoid name conflicts with the OS object from osfi…
Aug 9, 2014
44fb14b
Put ruleset database in a place where it can be safely replaced and r…
Aug 10, 2014
dea6348
Removed unused code
Aug 10, 2014
1e730ac
Move volatile db initialization to HTTPSEverywhere
Aug 10, 2014
976b346
Change names to avoid name clashes with osfile module
Aug 13, 2014
712773c
Use a bytearray to download ruleset database file with XHR
Aug 13, 2014
28f30fa
Perform database operations to copy new ruleset contents to rulesets.…
Aug 14, 2014
92def22
Revert back to using the builtin ruleset database file
Aug 14, 2014
23f7442
Removed old extra definitions of constant
Aug 14, 2014
2e8c408
Did some bugfixing
Aug 14, 2014
9cafe67
Describe process of generating a key and signing update.json using th…
Aug 14, 2014
1a1c458
Fixed a couple typos
Aug 14, 2014
d1148d4
Reinsert dropped prefixing 0s to hex strings
Aug 14, 2014
2080062
Ignore hashing test to continue testing with bad update.json data cau…
Aug 15, 2014
2fe9cac
Store newly downloaded ruleset dbs in profiledir and load from there …
Aug 15, 2014
a88f66f
Add hash comparison test back in
Aug 15, 2014
55a96f0
Removed my testing data which is known to be faulty after fixing d114…
Aug 15, 2014
bc25955
Clean up my code and rewrite better comments
Aug 15, 2014
f3056ae
Merge branch 'master' into rulesetUpdating
Aug 15, 2014
6075e9f
Removed URLs serving test data
Aug 15, 2014
b6d8424
Remove old signature verification testing data
Aug 15, 2014
9e4bca9
Revert "Remove stuff accidentally merged from features/tests a while …
Aug 15, 2014
3c6de33
Reset log level
Aug 15, 2014
bf200f1
Turn the ruleset updater on and off when the user toggles the checkbo…
Aug 15, 2014
aa65615
Fix typo
Aug 15, 2014
b7967f8
Update the updateJSONSpec
Aug 15, 2014
44343b5
Use strict equality comparing hash strings
Aug 15, 2014
b27a090
Rename rulesetUpdate.js to RulesetUpdater.js for consistency
Aug 15, 2014
fd6e4bd
Remove old fild
Aug 15, 2014
bdcf8fb
Making changes to appease the mentor gods
Aug 15, 2014
94312dd
Merge remote-tracking branch 'upstream/master'
Aug 16, 2014
cbe4311
Merge branch 'feature/tests'
Aug 16, 2014
ca8dc59
Use the new AddonManager module to get the addon version number
Aug 16, 2014
80b0aa8
Try to determine the branch name of the extension from the version st…
Aug 16, 2014
8f094cc
Prefix temp file with 32 random bytes
Aug 16, 2014
9dce2bf
Fixed a syntax error and changed a WARN log to more appropriate NOTE
Aug 16, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions doc/updateJSONSpec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
Previous Commentary
===================

This document used to be hosted as a Gist, and there was some commentary on the document
on the relevant gist page. That commentary can be [found here](https://gist.github.com/redwire/2e1d8377ea58e43edb40).

update.json and update.json.sig
===============================

The file `update.json` provides information about the currently deployed HTTPS Everywhere
ruleset library. The file contains the same kind of information as is stored in the
`update.rdf` file used to tell the HTTPS Everywhere extension where to fetch and how to
verify updates to the whole extension.

The utility script `https_everywhere/utils/ruleset_update_manifest.py` automates most of
the process of creating `update.json`, and is simply run with the command:

python utils/ruleset_update_manifest.py

Signing the `update.json` file requires the use of NSS tools and pk1sign, which should
come with the NSS tools. They can be installed on Debian-based Gnu+Linux systems via:

sudo apt-get install libnss3-tools

A signing key can be created using the following commands:

# Make the NSS keyring directory
mkdir nssdb
# Initialize the directory to be used as a keyring
certutil -N -d nssdb
# Generate a 2048-bit self-signed object signing certificate nicknamed "httpse"
certutil -S -n httpse -g 2048 -d nssdb -t "p,p,u" -s "CN=EFF" -x

Finally, issuing the following command will output both the signature of `update.json`
and the public key used to verify it, both base64 encoded.

pk1sign -i update.json -k httpse -d nssdb

Fetching
========

Retrieving updates for only a part of an extension is not possible using the builtin
extension update mechanisms supported by Firefox. However, fetching files using standard
XMLHTTPRequests from within the extension is trivial to accomplish and does not require trying
to force the browser to prematurely check for updates or apply changes only to parts of the
extension.
Thus, a simple XHR will be used to fetch `update.json` from eff.org.

A signature over the raw bytes of `update.json` will be served as `update.json.sig` from a
separate hard-coded URL.

The extension should check for ruleset updates when the browser is started, and then again
every 10800000 milliseconds (3 hours).
If an attempt to fetch or verify an update fails, the extension should request `update.json`
again every 300000 + R milliseconds, where R is a random number between 0 and 300000.
The extension should attempt this a maximum of 6 times until it is
able to fetch `update.json` and verify the contents before defaulting back to waiting 3 hours.

Every time the extension finds that the data provided by `update.json` to be inauthentic,
either as a result of the hash of the database file not matching or the signature not verifying,
the extension must send a POST request to a hardcoded failure-reporting url containing the data
in the `update.json` file that it tried and failed to verify. The format for failure reports
has yet to be determined.

Verification and Version Checking
=================================

In order to compute the hash of the database file, the nsICryptoHash class will be used.
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsICryptoHash
SHA1 is currently being used as the hashing algorithm.

In order to verify the signature over `update.json` file contents, which is the content of `update.json.sig`,
the nsIDataSignatureVerifier class will be used.
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDataSignatureVerifier

The `version` will be compared to the currently installed ruleset library version using nsIVersionComparator.
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIVersionComparator
Any HTTPS Everywhere extension with version X.Y.Z can ONLY accept ruleset versions of the form X.Y.Z.N, which
is to say that the extension will only accept ruleset versions that are subversions of itself.

The branch field can be checked and referenced against a value stored in user preferences.
A stable release of the extension will have a `branch` preference set to "stable",
and a development release will set the option to "development" or another specified constant.

Updating
========

For an early implementation of the ruleset update mechanism, the extension will update its
ruleset library (stored as a SQLite database) by fetching a SQLite database file from eff.org
containing the new ruleset library, and replace its local database file.
Replacing the local rulesets library will only occur after validating `update.json`
(pseudocode below).

Manifest
========

The following is the format for a simple `update.json` containing information about a single
ruleset library to be used by all target applications.

{"branch": <ruleset branch>
,"changes": <a short description of recent changes>
,"date": <the date the new db was released>
,"hash": <the hash of the db file>
,"hashfn": <The name of the hash function to use>
,"source": <the URL serving the updated ruleset db>
,"version": <ruleset release version>}

The meanings of each field are explained as follows:

* `branch` is a machine-readable target extension branch, e.g "stable", "developer", "willeatyourpc", etc. The extension SHOULD check that this field matches the extension's branch preference and MAY refuse to accept updates it doesn't like, e.g. stable extension release MAY refuse to update to developer rulesets.
* `date` is a formatted date string detailing the date that the release to the ruleset was released, and will be set
automatically by the `ruleset_update_manifest.py` utility. The format for the date is "dd-mm-yyyy". For example, "08-06-2014".
* `changes` is a short human-readable description of what has been changed, perhaps a list of the biggest or most requested fixes
* `hash` is a hash of the database file's content, encoded in hex. The hash function to use is specified by `hashfn`.
* `hashfn` is the name of the hash function used to compute the hash of the database file and MUST be one of md5, sha1, sha256, sha384, or sha512.
* `source` is the URL from which the most recently released database file is to be fetched. The URL must address a valid eff.org location and must not be overwritten by the extension.
* `version` is the ruleset release version, which is a subversion of the extension release version and MUST be checked by the updater to determine whether the advertised release is newer than the currently installed ruleset library. A ruleset release with a version number such as "3.5.1.2" must ONLY be accepted by HTTPS-Everywhere version 3.5.1, and so on.

Pseudocode of update procedure
==============================

The following is a high-level description of how the update mechanism is expected to function. Specifically, it details the order in which important authenticity tests are carried out

// Called at startup of HTTPS-E and every three hours afterwards.
function checkAndApplyUpdate() do
updateURL := preferences.get("updateURL")
updateSigURL := preferences.get("updateSigURL")
branchName := preferences.get("branchName")
currentVersion := preferences.get("rulesetVersion")
# tryFetch tries to request data up to 6 times in randomly padded intervals
# See the "Fetching" section
updateJSON := tryFetch(updateURL)
updateData := JSON.parse(upateJSON)
shouldUpdate := updateJSON != null and\ # Were able to receive data
updateData.version > currentVersion and\
isSubversion(updateData.version, EXTENSION_VERSION) and\
branchName == updateData.branch
inauthentic := true
if shouldUpdate then
signature := tryFetch(updateSigURL)
if isValidSignature(signature, updateJSON, PUBLIC_SIGNING_KEY) then
databaseSource := tryFetch(updateData.source)
if databaseSource == null then
return
endif
dbHash := hashFunctions[updateData.hashfn](databaseSource)
if dbHash == updateData.hash then
dbFile := openFile(RULESET_DB_FILE)
write(databaseSource, dbFile)
HTTPSRules.init()
inauthentic := false
endif
endif
endif
if inauthentic then
# tryPost works like tryFetch, but also sends data with a POST request
tryPost(REPORT_INAUTHENTIC_UPDATE_URL, updateData)
endif
endfunction

101 changes: 101 additions & 0 deletions https-everywhere-tests/test/test-rsupdate-verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Test the signature verification of the sha256 hash of update.json

const { Cc, Ci, Cu } = require('chrome');
const { atob, btoa} = Cu.import('resource://gre/modules/Services.jsm', {});

const PUBKEY = ""+
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvrJKpqX5"+
"kbiSX6DEKNcFO8U/Kw3jn1z+im+hSwCHNCXUzJ1IkwtRe2QkK66g"+
"1kCGnQ9rxnaOnLRSi8DK6Yypobm0paG71/WtHyRQzKDASPbVhy0U"+
"Men/3sGBOIOlT1JbZskHxVdEBJfb7YOr+a1BSgaIsrbaI7n9tmrT"+
"ysC5ECN5i5ETFQz0Hni7iqKWUB/a2dfDu0U4VDsJHIt1PKsduIJG"+
"aACT7+CZuaw3Jvc/utCOh0tgMHXxtxrezRu56ouVcttsQSuVQ56g"+
"xSwnASElECsmUgs6ci+ts4LMDrF8l/J1t778lIPQb2jf3QrNxsgV"+
"LKFSePJ2bwONkTSaj48I2wIDAQAB";

const UPDATE_JSON = '' +
'{"branch": "development"\n'+
',"changes": "Still trying to get signature verification working"\n'+
',"date": "04-08-2014"\n'+
',"hash": "8476a3638e2e95b6381aba4367e8c1c0f361bdaed501cd2f6f91b74e4545"\n'+
',"hashfn": "sha256"\n'+
',"source": "http://0.0.0.0:8000/data/rulesets.sqlite"\n'+
',"version": "5.0.0.1"}\n';

const UPDATE_JSON_SIG = ""+
"MIIBFDANBgkqhkiG9w0BAQUFAAOCAQEAWi6AThn723ovBCri3iuxu"+
"9g2mQGvKrWzeOBPW/2kc8U0DwVMn/v17ZtjWJuFnFyCpWFT88/gnC"+
"a+QV3+fupw4D9RwkFvdyKAp8ok7jGdrDl78jEmpqbqlc9Oz7WXDFr"+
"5OpxSjkd4jn4Pks0ImhZejuoWE1dLg7qLQhJ3gYzAT4IRKVVzBTkA"+
"zHHxKvuHzWpD3Q7pI/GkqUcygyJdVwYv6LQesnmdMzwIpyfgf/6ac"+
"znoQj3LsNn0W1Q6so64ng7aWx+2gFZp/f9Y8I5llWHaO55wEgKOBZ"+
"4n7OOvTLn0jyfbwkySzjaXmFgE1be6TmZ/dXggaI0w0uG5L2QIxfOhhg==";

function hashSHA256(data) {
let converter = Cc['@mozilla.org/intl/scriptableunicodeconverter']
.createInstance(Ci.nsIScriptableUnicodeConverter);
let hashing = Cc['@mozilla.org/security/hash;1']
.createInstance(Ci.nsICryptoHash);
function toHexString(charCode) {
return ('0' + charCode.toString(16)).slice(-2);
}
hashing.init(hashing.SHA256);
converter.charset = 'UTF-8';
let result = {};
let converted = converter.convertToByteArray(data, result);
hashing.update(converted, converted.length);
let hashed = hashing.finish(false);
return [toHexString(hashed.charCodeAt(i)) for (i in hashed)].join('');
}

function validUpdateData(updateHash, signature) {
return Cc['@mozilla.org/security/datasignatureverifier;1']
.createInstance(Ci.nsIDataSignatureVerifier)
.verifyData(updateHash, signature, PUBKEY);
}

exports['test binary-base64 encoding'] = function(assert) {
assert.strictEqual('hello', atob(btoa('hello')),
'Test that binary/base64 encoding works.');
};

/* This test is just meant to make sure that the object was parsed into JSON
* properly and that the attributes of the object created can be read.
*/
exports['test update JSON parsing'] = function(assert) {
let updateObj = JSON.parse(UPDATE_JSON);
assert.equal(updateObj.hash,
'8476a3638e2e95b6381aba4367e8c1c0f361bdaed501cd2f6f91b74e4545',
'Test that the data was parsed into JSON properly');
};

exports['test update JSON signature validity'] = function(assert) {
let hashed = hashSHA256(UPDATE_JSON);
console.log("###############################################################");
console.log(hashed);
console.log(hashed.charCodeAt(hashed.length - 1));
console.log("###############################################################");
let verifier = Cc['@mozilla.org/security/datasignatureverifier;1']
.createInstance(Ci.nsIDataSignatureVerifier);
assert.equal(hashed,
'e05c92fcb9ed93344d8f5e9b358e64f7e0ab13eb8cd3a6fce2581f1d8cc73832',
'Test that the update.json data hashed to the right value');
assert.equal(typeof verifier, 'object', 'Test verifier creation success');
assert.ok(verifier.verifyData(
UPDATE_JSON, UPDATE_JSON_SIG, PUBKEY),
//hashed, UPDATE_JSON_SIG, PUBKEY),
'Test that the update.json raw data is authentic');
};

exports['test ruleset version comparison'] = function(assert) {
let vcmp = Cc['@mozilla.org/xpcom/version-comparator;1']
.createInstance(Ci.nsIVersionComparator);
assert.ok(vcmp.compare('3.5.2', '3.5.2') === 0,
'Test that equal version numbers are confirmed equal by version comparator');
assert.ok(vcmp.compare('4.0development.17', '3.5.3') > 0,
'Test that 4.0development.17 > 3.5.3');
assert.ok(vcmp.compare('3.5.3.1', '3.5.3.2') < 0,
'Test that ruleset version 3.5.3.2 > 3.5.3.1');
};

require('sdk/test').run(exports);
11 changes: 10 additions & 1 deletion src/chrome/content/code/HTTPSRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,16 @@ const HTTPSRules = {
this.scanRulefiles(rulefiles);

// Initialize database connection.
var dbFile = new FileUtils.File(RuleWriter.chromeToPath("chrome://https-everywhere/content/rulesets.sqlite"));
// Use the rulesets database file downloaded in an update if one exists.
var updatedPath = HTTPSEverywhere.instance.UPDATED_RULESET_DBFILE_PATH();
var updatedDBFile = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
updatedDBFile.initWithPath(updatedPath);
if (updatedDBFile.exists()) {
var dbFile = new FileUtils.File(updatedPath);
} else {
var dbFile = new FileUtils.File(RuleWriter.chromeToPath(
"chrome://https-everywhere/content/rulesets.sqlite"));
}
var rulesetDBConn = Services.storage.openDatabase(dbFile);
this.queryForRuleset = rulesetDBConn.createStatement(
"select contents from rulesets where id = :id");
Expand Down
Loading