mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1331604
- Minor style and idiom changes (r=mgoodwin)
MozReview-Commit-ID: IdO8EP3hg0P --HG-- extra : rebase_source : 86f6da5d655bd84fa849b4a5374a41aebb8e814f
This commit is contained in:
parent
8f6110a8e5
commit
ef51c56995
@ -52,6 +52,7 @@ this.FILENAME_ADDONS_JSON = "blocklist-addons.json";
|
||||
this.FILENAME_GFX_JSON = "blocklist-gfx.json";
|
||||
this.FILENAME_PLUGINS_JSON = "blocklist-plugins.json";
|
||||
|
||||
|
||||
function mergeChanges(collection, localRecords, changes) {
|
||||
const records = {};
|
||||
// Local records by id.
|
||||
@ -88,10 +89,10 @@ function fetchRemoteCollection(collection) {
|
||||
* persist the local DB.
|
||||
*/
|
||||
function kintoClient(connection, bucket) {
|
||||
let base = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
|
||||
const remote = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
|
||||
|
||||
let config = {
|
||||
remote: base,
|
||||
const config = {
|
||||
remote,
|
||||
bucket,
|
||||
adapter: FirefoxAdapter,
|
||||
adapterOptions: {sqliteHandle: connection},
|
||||
@ -127,7 +128,7 @@ class BlocklistClient {
|
||||
data: payload.data
|
||||
};
|
||||
} else {
|
||||
const localRecords = (yield collection.list()).data;
|
||||
const {data: localRecords} = yield collection.list();
|
||||
const records = mergeChanges(collection, localRecords, payload.changes);
|
||||
toSerialize = {
|
||||
last_modified: `${payload.lastModified}`,
|
||||
@ -156,8 +157,8 @@ class BlocklistClient {
|
||||
* @return {Promise} which rejects on sync or process failure.
|
||||
*/
|
||||
maybeSync(lastModified, serverTime) {
|
||||
let opts = {};
|
||||
let enforceCollectionSigning =
|
||||
const opts = {};
|
||||
const enforceCollectionSigning =
|
||||
Services.prefs.getBoolPref(PREF_BLOCKLIST_ENFORCE_SIGNING);
|
||||
|
||||
// if there is a signerName and collection signing is enforced, add a
|
||||
@ -173,10 +174,10 @@ class BlocklistClient {
|
||||
let connection;
|
||||
try {
|
||||
connection = yield FirefoxAdapter.openConnection({path: KINTO_STORAGE_PATH});
|
||||
let db = kintoClient(connection, this.bucketName);
|
||||
let collection = db.collection(this.collectionName, opts);
|
||||
const db = kintoClient(connection, this.bucketName);
|
||||
const collection = db.collection(this.collectionName, opts);
|
||||
|
||||
let collectionLastModified = yield collection.db.getLastModified();
|
||||
const collectionLastModified = yield collection.db.getLastModified();
|
||||
// If the data is up to date, there's no need to sync. We still need
|
||||
// to record the fact that a check happened.
|
||||
if (lastModified <= collectionLastModified) {
|
||||
@ -185,8 +186,8 @@ class BlocklistClient {
|
||||
}
|
||||
// Fetch changes from server.
|
||||
try {
|
||||
let syncResult = yield collection.sync();
|
||||
if (!syncResult.ok) {
|
||||
const {ok} = yield collection.sync();
|
||||
if (!ok) {
|
||||
throw new Error("Sync failed");
|
||||
}
|
||||
} catch (e) {
|
||||
@ -195,7 +196,7 @@ class BlocklistClient {
|
||||
// local data has been modified in some way.
|
||||
// We will attempt to fix this by retrieving the whole
|
||||
// remote collection.
|
||||
let payload = yield fetchRemoteCollection(collection);
|
||||
const payload = yield fetchRemoteCollection(collection);
|
||||
yield this.validateCollectionSignature(payload, collection, true);
|
||||
// if the signature is good (we haven't thrown), and the remote
|
||||
// last_modified is newer than the local last_modified, replace the
|
||||
@ -210,9 +211,9 @@ class BlocklistClient {
|
||||
}
|
||||
}
|
||||
// Read local collection of records.
|
||||
let list = yield collection.list();
|
||||
const {data} = yield collection.list();
|
||||
|
||||
yield this.processCallback(list.data);
|
||||
yield this.processCallback(data);
|
||||
|
||||
// Track last update.
|
||||
this.updateLastCheck(serverTime);
|
||||
@ -228,7 +229,7 @@ class BlocklistClient {
|
||||
* @param {Date} serverTime the current date return by server.
|
||||
*/
|
||||
updateLastCheck(serverTime) {
|
||||
let checkedServerTimeInSeconds = Math.round(serverTime / 1000);
|
||||
const checkedServerTimeInSeconds = Math.round(serverTime / 1000);
|
||||
Services.prefs.setIntPref(this.lastCheckTimePref, checkedServerTimeInSeconds);
|
||||
}
|
||||
}
|
||||
@ -239,8 +240,8 @@ class BlocklistClient {
|
||||
* @param {Object} records current records in the local db.
|
||||
*/
|
||||
function* updateCertBlocklist(records) {
|
||||
let certList = Cc["@mozilla.org/security/certblocklist;1"]
|
||||
.getService(Ci.nsICertBlocklist);
|
||||
const certList = Cc["@mozilla.org/security/certblocklist;1"]
|
||||
.getService(Ci.nsICertBlocklist);
|
||||
for (let item of records) {
|
||||
try {
|
||||
if (item.issuerName && item.serialNumber) {
|
||||
@ -267,39 +268,40 @@ function* updateCertBlocklist(records) {
|
||||
* @param {Object} records current records in the local db.
|
||||
*/
|
||||
function* updatePinningList(records) {
|
||||
if (Services.prefs.getBoolPref(PREF_BLOCKLIST_PINNING_ENABLED)) {
|
||||
const appInfo = Cc["@mozilla.org/xre/app-info;1"]
|
||||
.getService(Ci.nsIXULAppInfo);
|
||||
if (!Services.prefs.getBoolPref(PREF_BLOCKLIST_PINNING_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
const appInfo = Cc["@mozilla.org/xre/app-info;1"]
|
||||
.getService(Ci.nsIXULAppInfo);
|
||||
|
||||
const siteSecurityService = Cc["@mozilla.org/ssservice;1"]
|
||||
.getService(Ci.nsISiteSecurityService);
|
||||
const siteSecurityService = Cc["@mozilla.org/ssservice;1"]
|
||||
.getService(Ci.nsISiteSecurityService);
|
||||
|
||||
// clear the current preload list
|
||||
siteSecurityService.clearPreloads();
|
||||
// clear the current preload list
|
||||
siteSecurityService.clearPreloads();
|
||||
|
||||
// write each KeyPin entry to the preload list
|
||||
for (let item of records) {
|
||||
try {
|
||||
const {pinType, pins = [], versions} = item;
|
||||
if (versions.indexOf(appInfo.version) != -1) {
|
||||
if (pinType == "KeyPin" && pins.length) {
|
||||
siteSecurityService.setKeyPins(item.hostName,
|
||||
item.includeSubdomains,
|
||||
item.expires,
|
||||
pins.length,
|
||||
pins, true);
|
||||
}
|
||||
if (pinType == "STSPin") {
|
||||
siteSecurityService.setHSTSPreload(item.hostName,
|
||||
item.includeSubdomains,
|
||||
item.expires);
|
||||
}
|
||||
// write each KeyPin entry to the preload list
|
||||
for (let item of records) {
|
||||
try {
|
||||
const {pinType, pins = [], versions} = item;
|
||||
if (versions.indexOf(appInfo.version) != -1) {
|
||||
if (pinType == "KeyPin" && pins.length) {
|
||||
siteSecurityService.setKeyPins(item.hostName,
|
||||
item.includeSubdomains,
|
||||
item.expires,
|
||||
pins.length,
|
||||
pins, true);
|
||||
}
|
||||
if (pinType == "STSPin") {
|
||||
siteSecurityService.setHSTSPreload(item.hostName,
|
||||
item.includeSubdomains,
|
||||
item.expires);
|
||||
}
|
||||
} catch (e) {
|
||||
// prevent errors relating to individual preload entries from causing
|
||||
// sync to fail. We will accumulate telemetry for such failures in bug
|
||||
// 1254099.
|
||||
}
|
||||
} catch (e) {
|
||||
// prevent errors relating to individual preload entries from causing
|
||||
// sync to fail. We will accumulate telemetry for such failures in bug
|
||||
// 1254099.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ this.checkVersions = function() {
|
||||
// "collection":"certificates"
|
||||
// }]}
|
||||
// Right now, we only use the collection name and the last modified info
|
||||
let kintoBase = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
|
||||
let changesEndpoint = kintoBase + Services.prefs.getCharPref(PREF_BLOCKLIST_CHANGES_PATH);
|
||||
const kintoBase = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
|
||||
const changesEndpoint = kintoBase + Services.prefs.getCharPref(PREF_BLOCKLIST_CHANGES_PATH);
|
||||
|
||||
// Use ETag to obtain a `304 Not modified` when no change occurred.
|
||||
const headers = {};
|
||||
@ -54,7 +54,7 @@ this.checkVersions = function() {
|
||||
}
|
||||
}
|
||||
|
||||
let response = yield fetch(changesEndpoint, {headers});
|
||||
const response = yield fetch(changesEndpoint, {headers});
|
||||
|
||||
let versionInfo;
|
||||
// No changes since last time. Go on with empty list of changes.
|
||||
@ -71,25 +71,19 @@ this.checkVersions = function() {
|
||||
}
|
||||
|
||||
// Record new update time and the difference between local and server time
|
||||
let serverTimeMillis = Date.parse(response.headers.get("Date"));
|
||||
const serverTimeMillis = Date.parse(response.headers.get("Date"));
|
||||
|
||||
// negative clockDifference means local time is behind server time
|
||||
// by the absolute of that value in seconds (positive means it's ahead)
|
||||
let clockDifference = Math.floor((Date.now() - serverTimeMillis) / 1000);
|
||||
const clockDifference = Math.floor((Date.now() - serverTimeMillis) / 1000);
|
||||
Services.prefs.setIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS, clockDifference);
|
||||
Services.prefs.setIntPref(PREF_BLOCKLIST_LAST_UPDATE, serverTimeMillis / 1000);
|
||||
|
||||
let firstError;
|
||||
for (let collectionInfo of versionInfo.data) {
|
||||
let collection = collectionInfo.collection;
|
||||
let client = gBlocklistClients[collection];
|
||||
if (client &&
|
||||
client.bucketName == collectionInfo.bucket &&
|
||||
client.maybeSync) {
|
||||
let lastModified = 0;
|
||||
if (collectionInfo.last_modified) {
|
||||
lastModified = collectionInfo.last_modified;
|
||||
}
|
||||
const {bucket, collection, last_modified: lastModified} = collectionInfo;
|
||||
const client = gBlocklistClients[collection];
|
||||
if (client && client.bucketName == bucket) {
|
||||
try {
|
||||
yield client.maybeSync(lastModified, serverTimeMillis);
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user