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