9001-FSDG-sync-remote-settings-with-local-dump.patch 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. From c572b11d9d112f534b2855e8825f81d6304fd3fd Mon Sep 17 00:00:00 2001
  2. From: grizzlyuser <grizzlyuser@protonmail.com>
  3. Date: Wed, 30 Dec 2020 17:20:39 +0200
  4. Subject: [PATCH 01/13] Point to local omni.ja files, not remote server
  5. This patch series tries to remove any network communication with Remote
  6. Settings [1], which can be used by Mozilla to silently push data to client
  7. browsers. This data can include references to nonfree software, for example,
  8. to search engines or other websites that contain nonfree JavaScript code.
  9. Without this patching, it would be hard to make sure the browser does not
  10. violate paragraph 4 of [2]: "Programs in the system should not suggest
  11. installing nonfree plugins, documentation, and so on."
  12. Changes in the current patch:
  13. First of all, replace every occurrence of Remote Settings server domain name
  14. with URIs that point to built-in local files within omni.ja.
  15. Some links to json files may point to non-existing files, but that's OK
  16. because it's better than leave them point to Remote Settings server.
  17. If necessary, missing files can be added later.
  18. [1] https://remote-settings.readthedocs.io/en/latest/introduction.html
  19. [2] https://www.gnu.org/distros/free-system-distribution-guidelines.en.html#license-rules
  20. ---
  21. browser/components/asrouter/bin/import-rollouts.js | 4 ++--
  22. .../components/ASRouterAdmin/ASRouterAdmin.jsx | 2 +-
  23. .../components/asrouter/content/asrouter-admin.bundle.js | 2 +-
  24. .../feature/search/telemetry/SerpTelemetryRepository.kt | 2 +-
  25. .../support/remotesettings/RemoteSettingsClient.kt | 2 +-
  26. .../support/remotesettings/RemoteSettingsClientTest.kt | 2 +-
  27. .../docs/_posts/2018-08-10-fretboard.md | 2 +-
  28. .../src/main/java/org/mozilla/fenix/components/Core.kt | 4 ++--
  29. .../org/mozilla/focus/telemetry/GleanMetricsService.kt | 4 ++--
  30. services/settings/Utils.sys.mjs | 2 +-
  31. services/settings/docs/index.rst | 4 ++--
  32. .../periodic-updates/scripts/periodic_file_updates.sh | 2 +-
  33. third_party/rust/remote_settings/.cargo-checksum.json | 2 +-
  34. third_party/rust/remote_settings/src/client.rs | 2 +-
  35. third_party/rust/remote_settings/src/config.rs | 6 +++---
  36. .../components/antitracking/docs/query-stripping/index.md | 2 +-
  37. .../backgroundtasks/BackgroundTask_message.sys.mjs | 6 +++---
  38. toolkit/components/search/SearchUtils.sys.mjs | 8 ++++----
  39. toolkit/components/search/docs/DefaultSearchEngines.rst | 2 +-
  40. .../components/search/docs/SearchEngineConfiguration.rst | 8 ++++----
  41. .../search/docs/SearchEngineConfigurationArchive.rst | 2 +-
  42. toolkit/modules/AppConstants.sys.mjs | 4 ++--
  43. 22 files changed, 37 insertions(+), 37 deletions(-)
  44. diff --git a/browser/components/asrouter/bin/import-rollouts.js b/browser/components/asrouter/bin/import-rollouts.js
  45. index b8e4b3fff7..9cf2e7ebef 100644
  46. --- a/browser/components/asrouter/bin/import-rollouts.js
  47. +++ b/browser/components/asrouter/bin/import-rollouts.js
  48. @@ -36,7 +36,7 @@ const jsonschema = require("../../../../third_party/js/cfworker/json-schema.js")
  49. const DEFAULT_COLLECTION_ID = "nimbus-desktop-experiments";
  50. const BASE_URL =
  51. - "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/";
  52. + "resource://app/defaults/settings/main/";
  53. const EXPERIMENTER_URL = "https://experimenter.services.mozilla.com/nimbus/";
  54. const OUTPUT_PATH = "./tests/NimbusRolloutMessageProvider.sys.mjs";
  55. const LICENSE_STRING = `/* This Source Code Form is subject to the terms of the Mozilla Public
  56. @@ -237,7 +237,7 @@ async function main() {
  57. }
  58. );
  59. - const RECORDS_URL = `${BASE_URL}${cli.flags.collection}/records`;
  60. + const RECORDS_URL = `${BASE_URL}${cli.flags.collection}.json`;
  61. console.log(`Fetching records from ${chalk.underline.yellow(RECORDS_URL)}`);
  62. diff --git a/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx b/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
  63. index a5edd0c481..cb6e735cfc 100644
  64. --- a/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
  65. +++ b/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
  66. @@ -816,7 +816,7 @@ export class ASRouterAdminInner extends React.PureComponent {
  67. <a
  68. className="small-text"
  69. target="_blank"
  70. - href="https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/nimbus-desktop-experiments/records"
  71. + href="resource://app/defaults/settings/main/nimbus-desktop-experiments.json"
  72. rel="noopener noreferrer"
  73. >
  74. nimbus-desktop-experiments
  75. diff --git a/browser/components/asrouter/content/asrouter-admin.bundle.js b/browser/components/asrouter/content/asrouter-admin.bundle.js
  76. index 206610282a..bac1763595 100644
  77. --- a/browser/components/asrouter/content/asrouter-admin.bundle.js
  78. +++ b/browser/components/asrouter/content/asrouter-admin.bundle.js
  79. @@ -1152,7 +1152,7 @@ class ASRouterAdminInner extends (react__WEBPACK_IMPORTED_MODULE_1___default().P
  80. label = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement("span", null, "remote settings (", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement("a", {
  81. className: "small-text",
  82. target: "_blank",
  83. - href: "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/nimbus-desktop-experiments/records",
  84. + href: "resource://app/defaults/settings/main/nimbus-desktop-experiments.json",
  85. rel: "noopener noreferrer"
  86. }, "nimbus-desktop-experiments"), ")");
  87. }
  88. diff --git a/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt b/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
  89. index 436b0e22db..129e728872 100644
  90. --- a/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
  91. +++ b/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
  92. @@ -16,7 +16,7 @@ import org.json.JSONException
  93. import org.json.JSONObject
  94. import java.io.File
  95. -internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
  96. +internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
  97. internal const val REMOTE_ENDPOINT_BUCKET_NAME = "main"
  98. /**
  99. diff --git a/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt b/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
  100. index c9e448e8a2..ba2638ff10 100644
  101. --- a/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
  102. +++ b/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
  103. @@ -43,7 +43,7 @@ import java.net.URL
  104. class RemoteSettingsClient(
  105. private val storageRootDirectory: File,
  106. - private val serverUrl: String = "https://firefox.settings.services.mozilla.com",
  107. + private val serverUrl: String = "resource://app/defaults/settings",
  108. private val bucketName: String = "main",
  109. private val collectionName: String,
  110. ) {
  111. diff --git a/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt b/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
  112. index e6b153a9a4..afca8776f5 100644
  113. --- a/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
  114. +++ b/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
  115. @@ -37,7 +37,7 @@ class RemoteSettingsClientTest {
  116. mockFileReader = mock()
  117. mockJsonObject = mock()
  118. mockRemoteSettings = mock()
  119. - remoteSettingsClient = RemoteSettingsClient(File(""), "https://firefox.settings.services.mozilla.com", "", "")
  120. + remoteSettingsClient = RemoteSettingsClient(File(""), "resource://app/defaults/settings", "", "")
  121. }
  122. @Test
  123. diff --git a/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md b/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
  124. index f4f852eeb1..b877808e79 100644
  125. --- a/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
  126. +++ b/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
  127. @@ -8,7 +8,7 @@ author: fernando
  128. ## Overview
  129. Firefox for Android (codenamed Fennec) started using [KeepSafe's Switchboard library](https://github.com/KeepSafe/Switchboard) and server component in order to run A/B testing or staged rollout of features, but since then the code changed significantly. It used a special [switchboard server](https://github.com/mozilla-services/switchboard-server) that decided which experiments a client is part of and returned a simplified list for the client to consume. However, this required the client to send data (including a unique id) to the server.
  130. -To avoid this Firefox moved to using [Kinto](https://github.com/Kinto/kinto) as storage and server of the experiment configuration. Clients now download the whole list of experiments and decide locally what experiments they are enrolled in (the configuration for Fennec [looks like this](https://firefox.settings.services.mozilla.com/v1/buckets/fennec/collections/experiments/records)).
  131. +To avoid this Firefox moved to using [Kinto](https://github.com/Kinto/kinto) as storage and server of the experiment configuration. Clients now download the whole list of experiments and decide locally what experiments they are enrolled in (the configuration for Fennec [looks like this](resource://app/defaults/settings/fennec/experiments.json)).
  132. The purpose of this Google Summer of Code project, which is called Fretboard, was to develop an A/B testing framework written in Kotlin based on the existing code from Fennec, but making it independent of both the server used and the local storage mechanism, allowing it to be used on other apps, such as Firefox Focus, which started to need to do some A/B tests.
  133. diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
  134. index fcdc1ad20f..8403d64c0c 100644
  135. --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
  136. +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
  137. @@ -676,7 +676,7 @@ class Core(
  138. // collection name to fetch from server for SERP telemetry
  139. const val COLLECTION_NAME = "search-telemetry-v2"
  140. - internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
  141. - internal const val REMOTE_STAGE_ENDPOINT_URL = "https://firefox.settings.services.allizom.org"
  142. + internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
  143. + internal const val REMOTE_STAGE_ENDPOINT_URL = "resource://app/defaults/settings"
  144. }
  145. }
  146. diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
  147. index b419f85faf..9a3fc984e2 100644
  148. --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
  149. +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
  150. @@ -62,8 +62,8 @@ class GleanMetricsService(context: Context) : MetricsService {
  151. const val COLLECTION_NAME = "search-telemetry-v2"
  152. // urls for prod and stage remote settings server
  153. - internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
  154. - internal const val REMOTE_STAGE_ENDPOINT_URL = "https://firefox.settings.services.allizom.org"
  155. + internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
  156. + internal const val REMOTE_STAGE_ENDPOINT_URL = "resource://app/defaults/settings"
  157. private val isEnabledByDefault: Boolean
  158. get() = !AppConstants.isKlarBuild
  159. diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
  160. index 12fef6cde8..13d940455e 100644
  161. --- a/services/settings/Utils.sys.mjs
  162. +++ b/services/settings/Utils.sys.mjs
  163. @@ -102,7 +102,7 @@ export var Utils = {
  164. : AppConstants.REMOTE_SETTINGS_SERVER_URL;
  165. },
  166. - CHANGES_PATH: "/buckets/monitor/collections/changes/changeset",
  167. + CHANGES_PATH: "/monitor/changes",
  168. /**
  169. * Logger instance.
  170. diff --git a/services/settings/docs/index.rst b/services/settings/docs/index.rst
  171. index a834bb74a0..17c7f7b9cc 100644
  172. --- a/services/settings/docs/index.rst
  173. +++ b/services/settings/docs/index.rst
  174. @@ -190,11 +190,11 @@ It is possible to package a dump of the server records that will be loaded into
  175. The JSON dump will serve as the default dataset for ``.get()``, instead of doing a round-trip to pull the latest data. It will also reduce the amount of data to be downloaded on the first synchronization.
  176. -#. Place the JSON dump of the server records in the ``services/settings/dumps/main/`` folder. Using this command:
  177. +#. Place the JSON dump of the server records in the ``services/settings/dumps/main/`` folder. Using this command (replace 'https://settings.invalid' with your Remote Settings address):
  178. ::
  179. CID="your-collection"
  180. - curl "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/${CID}/changeset?_expected=0" | jq '{"data": .changes, "timestamp": .timestamp}' > services/settings/dumps/main/${CID}.json``
  181. + curl "https://settings.invalid/v1/buckets/main/collections/${CID}/changeset?_expected=0" | jq '{"data": .changes, "timestamp": .timestamp}' > services/settings/dumps/main/${CID}.json``
  182. #. Add the filename to the relevant ``FINAL_TARGET_FILES`` list in ``services/settings/dumps/main/moz.build``
  183. diff --git a/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh b/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
  184. index dd90445a30..7f3e878ca3 100755
  185. --- a/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
  186. +++ b/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
  187. @@ -295,7 +295,7 @@ function compare_suffix_lists {
  188. }
  189. function compare_remote_settings_files {
  190. - REMOTE_SETTINGS_SERVER="https://firefox.settings.services.mozilla.com/v1"
  191. + REMOTE_SETTINGS_SERVER="resource://app/defaults/settings"
  192. # 1. List remote settings collections from server.
  193. echo "INFO: fetch remote settings list from server"
  194. diff --git a/third_party/rust/remote_settings/.cargo-checksum.json b/third_party/rust/remote_settings/.cargo-checksum.json
  195. index edae407f85..a5396ba2c1 100644
  196. --- a/third_party/rust/remote_settings/.cargo-checksum.json
  197. +++ b/third_party/rust/remote_settings/.cargo-checksum.json
  198. @@ -1 +1 @@
  199. -{"files":{"Cargo.toml":"e607c012c7d59d412f2795ad83281d67fe373c9c10859ea2a35a48e3def02a1d","src/cache.rs":"9c16f17353730103d57132a0f055863b085d2d3eb3a78f6a6f8d095f897d0c0d","src/client.rs":"e70cbbdf8a739d6a60f588ad8cc4f127aedc3db08091ff76a43dd813424148f0","src/config.rs":"496299f100673fb862aaeffdec61173f5265779e8990ab326ac91a7270fab8cc","src/error.rs":"832b80cf4d2b4464f5824ed36a37726bc99535b28d4c5c384df22ef3b906b187","src/lib.rs":"baf2e1e47f2c059531f00320ff7715a7d84ddf7df5ad1c4ec7ec4f01bee92edf","uniffi.toml":"88cfb5e8e6ea16b0a3998f34791232a22478b2027ea4f1932dcc417b51fe2e7a"},"package":null}
  200. \ No newline at end of file
  201. +{"files":{"Cargo.toml":"e607c012c7d59d412f2795ad83281d67fe373c9c10859ea2a35a48e3def02a1d","src/cache.rs":"9c16f17353730103d57132a0f055863b085d2d3eb3a78f6a6f8d095f897d0c0d","src/client.rs":"b29ba1a84ec833e0a863587feedb181d594d1b0edacc4f07db5974c728790814","src/config.rs":"6893db5c9a2499aed911a276077928204f3f02ab4812bb1b78c2cdf396f53ccd","src/error.rs":"832b80cf4d2b4464f5824ed36a37726bc99535b28d4c5c384df22ef3b906b187","src/lib.rs":"baf2e1e47f2c059531f00320ff7715a7d84ddf7df5ad1c4ec7ec4f01bee92edf","uniffi.toml":"88cfb5e8e6ea16b0a3998f34791232a22478b2027ea4f1932dcc417b51fe2e7a"},"package":null}
  202. diff --git a/third_party/rust/remote_settings/src/client.rs b/third_party/rust/remote_settings/src/client.rs
  203. index 8475b6689b..6839ae4cb2 100644
  204. --- a/third_party/rust/remote_settings/src/client.rs
  205. +++ b/third_party/rust/remote_settings/src/client.rs
  206. @@ -536,7 +536,7 @@ mod test {
  207. };
  208. let client = Client::new(config).unwrap();
  209. assert_eq!(
  210. - Url::parse("https://firefox.settings.services.mozilla.com").unwrap(),
  211. + Url::parse("resource://app/defaults/settings").unwrap(),
  212. client.base_url
  213. );
  214. assert_eq!(String::from("main"), client.bucket_name);
  215. diff --git a/third_party/rust/remote_settings/src/config.rs b/third_party/rust/remote_settings/src/config.rs
  216. index f4029e5bc6..6405328481 100644
  217. --- a/third_party/rust/remote_settings/src/config.rs
  218. +++ b/third_party/rust/remote_settings/src/config.rs
  219. @@ -51,9 +51,9 @@ impl RemoteSettingsServer {
  220. /// inside the crate.
  221. pub(crate) fn get_url(&self) -> Result<Url> {
  222. Ok(match self {
  223. - Self::Prod => Url::parse("https://firefox.settings.services.mozilla.com").unwrap(),
  224. - Self::Stage => Url::parse("https://firefox.settings.services.allizom.org").unwrap(),
  225. - Self::Dev => Url::parse("https://remote-settings-dev.allizom.org").unwrap(),
  226. + Self::Prod => Url::parse("resource://app/defaults/settings").unwrap(),
  227. + Self::Stage => Url::parse("resource://app/defaults/settings").unwrap(),
  228. + Self::Dev => Url::parse("resource://app/defaults/settings").unwrap(),
  229. Self::Custom { url } => Url::parse(url)?,
  230. })
  231. }
  232. diff --git a/toolkit/components/antitracking/docs/query-stripping/index.md b/toolkit/components/antitracking/docs/query-stripping/index.md
  233. index e49d8513ba..c1c6ae5deb 100644
  234. --- a/toolkit/components/antitracking/docs/query-stripping/index.md
  235. +++ b/toolkit/components/antitracking/docs/query-stripping/index.md
  236. @@ -63,7 +63,7 @@ of query params:
  237. It is enabled in Nightly by default in all modes with an extended
  238. strip-list. You can find the current list of parameters that are
  239. stripped
  240. -[here](https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/query-stripping/records).
  241. +[here](resource://app/defaults/settings/main/collections/query-stripping/records).
  242. Note that some records have a *filter\_expression* that limits where
  243. they apply.
  244. diff --git a/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs b/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
  245. index aafe4a6dcf..cfdefe2ef8 100644
  246. --- a/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
  247. +++ b/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
  248. @@ -19,8 +19,8 @@
  249. // environment variables still apply.
  250. //
  251. // --stage: use stage Remote Settings
  252. -// (`https://firefox.settings.services.allizom.org/v1`) rather than production
  253. -// (`https://firefox.settings.services.mozilla.com/v1`)
  254. +// (`resource://app/defaults/settings/`) rather than production
  255. +// (`resource://app/defaults/settings/`)
  256. //
  257. // --preview: enable Remote Settings and Experiment previews.
  258. //
  259. @@ -71,7 +71,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  260. Utils: "resource://services-settings/Utils.sys.mjs",
  261. });
  262. -const SERVER_STAGE = "https://firefox.settings.services.allizom.org/v1";
  263. +const SERVER_STAGE = "resource://app/defaults/settings";
  264. // Default profile targeting snapshot.
  265. let defaultProfileTargetingSnapshot = {};
  266. diff --git a/toolkit/components/search/SearchUtils.sys.mjs b/toolkit/components/search/SearchUtils.sys.mjs
  267. index d7c5c05cb5..b2e4dd3f6c 100644
  268. --- a/toolkit/components/search/SearchUtils.sys.mjs
  269. +++ b/toolkit/components/search/SearchUtils.sys.mjs
  270. @@ -162,13 +162,13 @@ export var SearchUtils = {
  271. ENGINES_URLS: {
  272. "prod-main":
  273. - "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config/records",
  274. + "resource://app/defaults/settings/main/search-config.json",
  275. "prod-preview":
  276. - "https://firefox.settings.services.mozilla.com/v1/buckets/main-preview/collections/search-config/records",
  277. + "resource://app/defaults/settings/main/search-config.json",
  278. "stage-main":
  279. - "https://firefox.settings.services.allizom.org/v1/buckets/main/collections/search-config/records",
  280. + "resource://app/defaults/settings/main/search-config.json",
  281. "stage-preview":
  282. - "https://firefox.settings.services.allizom.org/v1/buckets/main-preview/collections/search-config/records",
  283. + "resource://app/defaults/settings/main/search-config.json",
  284. },
  285. // The following constants are left undocumented in nsISearchService.idl
  286. diff --git a/toolkit/components/search/docs/DefaultSearchEngines.rst b/toolkit/components/search/docs/DefaultSearchEngines.rst
  287. index 3dfe68abb1..26d5f18a7b 100644
  288. --- a/toolkit/components/search/docs/DefaultSearchEngines.rst
  289. +++ b/toolkit/components/search/docs/DefaultSearchEngines.rst
  290. @@ -99,4 +99,4 @@ is updated.
  291. .. _configuration schema: SearchConfigurationSchema.html
  292. .. _remote settings: /services/settings/index.html
  293. -.. _search-default-override-allowlist bucket: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-default-override-allowlist/records
  294. +.. _search-default-override-allowlist bucket: resource://app/defaults/settings/main/search-default-override-allowlist.json
  295. diff --git a/toolkit/components/search/docs/SearchEngineConfiguration.rst b/toolkit/components/search/docs/SearchEngineConfiguration.rst
  296. index ca6009a0ef..66ef611e73 100644
  297. --- a/toolkit/components/search/docs/SearchEngineConfiguration.rst
  298. +++ b/toolkit/components/search/docs/SearchEngineConfiguration.rst
  299. @@ -40,7 +40,7 @@ An outline of the schemas may be found on the `Search Configuration Schema`_ pag
  300. .. _JSON schema: https://json-schema.org/
  301. .. _stored in mozilla-central: https://searchfox.org/mozilla-central/source/toolkit/components/search/schema/
  302. .. _Search Configuration Schema: SearchConfigurationSchema.html
  303. -.. _viewed live: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-v2/records
  304. -.. _search-config-icons: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-icons/records
  305. -.. _search-config-overrides-v2: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-overrides-v2/records
  306. -.. _search-default-override-allowlist: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-default-override-allowlist/records
  307. +.. _viewed live: resource://app/defaults/settings/main/search-config-v2.json
  308. +.. _search-config-icons: resource://app/defaults/settings/main/search-config-icons.json
  309. +.. _search-config-overrides-v2: resource://app/defaults/settings/main/search-config-overrides-v2.json
  310. +.. _search-default-override-allowlist: resource://app/defaults/settings/main/search-default-override-allowlist.json
  311. diff --git a/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst b/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
  312. index a6aba91a42..0700ab0b69 100644
  313. --- a/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
  314. +++ b/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
  315. @@ -68,5 +68,5 @@ related. As a result several situations may occur:
  316. .. _JSON schema: https://json-schema.org/
  317. .. _stored in mozilla-central: https://searchfox.org/mozilla-central/source/toolkit/components/search/schema/
  318. .. _Search Configuration Schema: SearchConfigurationSchema.html
  319. -.. _viewed live: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config/records
  320. +.. _viewed live: resource://app/defaults/settings/main/search-config.json
  321. .. _Normandy: /toolkit/components/normandy/normandy/services.html
  322. diff --git a/toolkit/modules/AppConstants.sys.mjs b/toolkit/modules/AppConstants.sys.mjs
  323. index a20e45c613..6c200784fe 100644
  324. --- a/toolkit/modules/AppConstants.sys.mjs
  325. +++ b/toolkit/modules/AppConstants.sys.mjs
  326. @@ -390,9 +390,9 @@ export var AppConstants = Object.freeze({
  327. REMOTE_SETTINGS_SERVER_URL:
  328. #ifdef MOZ_THUNDERBIRD
  329. - "https://thunderbird-settings.thunderbird.net/v1",
  330. + "resource://app/defaults/settings",
  331. #else
  332. - "https://firefox.settings.services.mozilla.com/v1",
  333. + "resource://app/defaults/settings",
  334. #endif
  335. REMOTE_SETTINGS_VERIFY_SIGNATURE:
  336. --
  337. 2.47.0
  338. From 23be7658779a5d1cab0e1f0c146420395b99f6f8 Mon Sep 17 00:00:00 2001
  339. From: grizzlyuser <grizzlyuser@protonmail.com>
  340. Date: Wed, 30 Dec 2020 17:34:08 +0200
  341. Subject: [PATCH 02/13] Remove polling triggered by push broadcasts
  342. When initialized, remote-settings.sys.mjs adds a listener to push broadcasts,
  343. that let Remote Settings server send push messages to trigger polling
  344. for changes from the client side. This is not needed for local-only
  345. setup. Remove the record from broadcast-listeners.json file stored in
  346. the user profile, so that it doesn't get picked up by push broadcast
  347. service.
  348. ---
  349. dom/push/PushBroadcastService.sys.mjs | 13 +++++++++++++
  350. services/settings/remote-settings.sys.mjs | 11 ++---------
  351. 2 files changed, 15 insertions(+), 9 deletions(-)
  352. diff --git a/dom/push/PushBroadcastService.sys.mjs b/dom/push/PushBroadcastService.sys.mjs
  353. index eea31ef192..529ecd6917 100644
  354. --- a/dom/push/PushBroadcastService.sys.mjs
  355. +++ b/dom/push/PushBroadcastService.sys.mjs
  356. @@ -168,6 +168,19 @@ export var BroadcastService = class {
  357. }
  358. }
  359. + async deleteListener(broadcastId) {
  360. + await this.initializePromise;
  361. +
  362. + if (this.jsonFile.data.listeners.hasOwnProperty(broadcastId)) {
  363. + console.info(
  364. + "deleteListener: deleting listener",
  365. + broadcastId
  366. + );
  367. + delete this.jsonFile.data.listeners[broadcastId];
  368. + this.jsonFile.saveSoon();
  369. + }
  370. + }
  371. +
  372. /**
  373. * Call the listeners of the specified broadcasts.
  374. *
  375. diff --git a/services/settings/remote-settings.sys.mjs b/services/settings/remote-settings.sys.mjs
  376. index 7a5530abd2..e17f1b5b5b 100644
  377. --- a/services/settings/remote-settings.sys.mjs
  378. +++ b/services/settings/remote-settings.sys.mjs
  379. @@ -586,11 +586,7 @@ function remoteSettingsFunction() {
  380. moduleURI: import.meta.url,
  381. symbolName: "remoteSettingsBroadcastHandler",
  382. };
  383. - lazy.pushBroadcastService.addListener(
  384. - BROADCAST_ID,
  385. - currentVersion,
  386. - moduleInfo
  387. - );
  388. + lazy.pushBroadcastService.deleteListener(BROADCAST_ID);
  389. };
  390. return remoteSettings;
  391. @@ -610,9 +606,6 @@ export var remoteSettingsBroadcastHandler = {
  392. `Push notification received (version=${version} phase=${phase})`
  393. );
  394. - return RemoteSettings.pollChanges({
  395. - expectedTimestamp: version,
  396. - trigger: isStartup ? "startup" : "broadcast",
  397. - });
  398. + return;
  399. },
  400. };
  401. --
  402. 2.47.0
  403. From eeae799a1b5ab7d9b167ee8010cedadebc6b56bc Mon Sep 17 00:00:00 2001
  404. From: grizzlyuser <grizzlyuser@protonmail.com>
  405. Date: Wed, 30 Dec 2020 17:41:54 +0200
  406. Subject: [PATCH 03/13] Remove timer that triggers polling for changes
  407. That is not needed for local-only setup.
  408. ---
  409. services/settings/components.conf | 9 +--------
  410. services/settings/servicesSettings.manifest | 4 ----
  411. 2 files changed, 1 insertion(+), 12 deletions(-)
  412. diff --git a/services/settings/components.conf b/services/settings/components.conf
  413. index fbc4df9bfc..25109415a7 100644
  414. --- a/services/settings/components.conf
  415. +++ b/services/settings/components.conf
  416. @@ -4,11 +4,4 @@
  417. # License, v. 2.0. If a copy of the MPL was not distributed with this
  418. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  419. -Classes = [
  420. - {
  421. - 'cid': '{5e756573-234a-49ea-bbe4-59ec7a70657d}',
  422. - 'contract_ids': ['@mozilla.org/services/settings;1'],
  423. - 'esModule': 'resource://services-settings/RemoteSettingsComponents.sys.mjs',
  424. - 'constructor': 'RemoteSettingsTimer',
  425. - },
  426. -]
  427. +Classes = []
  428. diff --git a/services/settings/servicesSettings.manifest b/services/settings/servicesSettings.manifest
  429. index 3bfed26ea4..807eb220ec 100644
  430. --- a/services/settings/servicesSettings.manifest
  431. +++ b/services/settings/servicesSettings.manifest
  432. @@ -1,7 +1,3 @@
  433. # Register resource aliases
  434. resource services-settings resource://gre/modules/services-settings/
  435. -# Schedule polling of remote settings changes
  436. -# (default 24H, max 72H)
  437. -# see syntax https://searchfox.org/mozilla-central/rev/cc280c4be94ff8cf64a27cc9b3d6831ffa49fa45/toolkit/components/timermanager/UpdateTimerManager.jsm#155
  438. -category update-timer RemoteSettingsComponents @mozilla.org/services/settings;1,getService,services-settings-poll-changes,services.settings.poll_interval,86400,259200
  439. --
  440. 2.47.0
  441. From 1352df7a424eeceec577ae53660ef06337608693 Mon Sep 17 00:00:00 2001
  442. From: grizzlyuser <grizzlyuser@protonmail.com>
  443. Date: Wed, 30 Dec 2020 17:47:41 +0200
  444. Subject: [PATCH 04/13] Utils: fetch timestamps of each collection locally
  445. Utils.CHANGES_PATH points to
  446. services/settings/dumps/monitor/changes
  447. which will be generated later by JSON processing script. Fetch the
  448. timestamps from that file and mock response headers to not confuse any
  449. code that expects them.
  450. ---
  451. services/settings/Utils.sys.mjs | 28 ++++++++++++++++++++---
  452. services/settings/dumps/monitor/moz.build | 8 +++++++
  453. services/settings/dumps/moz.build | 1 +
  454. 3 files changed, 34 insertions(+), 3 deletions(-)
  455. create mode 100644 services/settings/dumps/monitor/moz.build
  456. diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
  457. index 13d940455e..d5dfe84823 100644
  458. --- a/services/settings/Utils.sys.mjs
  459. +++ b/services/settings/Utils.sys.mjs
  460. @@ -411,7 +411,7 @@ export var Utils = {
  461. async fetchLatestChanges(serverUrl, options = {}) {
  462. const { expectedTimestamp, lastEtag = "", filters = {} } = options;
  463. - let url = serverUrl + Utils.CHANGES_PATH;
  464. + let url = Utils.SERVER_URL + Utils.CHANGES_PATH;
  465. const params = {
  466. ...filters,
  467. _expected: expectedTimestamp ?? 0,
  468. @@ -426,7 +426,21 @@ export var Utils = {
  469. .map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
  470. .join("&");
  471. }
  472. - const response = await Utils.fetch(url);
  473. + const rawResponse = await fetch(url);
  474. + const responseDate = new Date().toUTCString();
  475. +
  476. + const headers = new Headers();
  477. + headers.set("Date", responseDate);
  478. + headers.set("Last-Modified", responseDate);
  479. + headers.set("Content-Type", "application/json");
  480. +
  481. + const responseAttributes = {
  482. + status: rawResponse.status,
  483. + statusText: rawResponse.statusText,
  484. + headers,
  485. + };
  486. +
  487. + const response = new Response(rawResponse.body, responseAttributes);
  488. if (response.status >= 500) {
  489. throw new Error(`Server error ${response.status} ${response.statusText}`);
  490. @@ -461,7 +475,15 @@ export var Utils = {
  491. }
  492. }
  493. - const { changes = [], timestamp } = payload;
  494. + const { timestamp } = payload;
  495. + const { bucket, collection } = filters;
  496. + if (!bucket || !collection) {
  497. + throw new Error('Unable to fetch latest change without bucket or collection');
  498. + }
  499. + const change = payload.changes.find(
  500. + change => change.bucket === bucket && change.collection === collection
  501. + ) ?? { last_modified: 0, bucket, collection };
  502. + const changes = [change];
  503. let serverTimeMillis = Date.parse(response.headers.get("Date"));
  504. // Since the response is served via a CDN, the Date header value could have been cached.
  505. diff --git a/services/settings/dumps/monitor/moz.build b/services/settings/dumps/monitor/moz.build
  506. new file mode 100644
  507. index 0000000000..25c53a2eeb
  508. --- /dev/null
  509. +++ b/services/settings/dumps/monitor/moz.build
  510. @@ -0,0 +1,8 @@
  511. +# This Source Code Form is subject to the terms of the Mozilla Public
  512. +# License, v. 2.0. If a copy of the MPL was not distributed with this
  513. +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
  514. +
  515. +FINAL_TARGET_FILES.defaults.settings.monitor += ["changes"]
  516. +
  517. +if CONFIG["MOZ_BUILD_APP"] == "browser":
  518. + DIST_SUBDIR = "browser"
  519. diff --git a/services/settings/dumps/moz.build b/services/settings/dumps/moz.build
  520. index a3e9e9b3f2..b32a8d8691 100644
  521. --- a/services/settings/dumps/moz.build
  522. +++ b/services/settings/dumps/moz.build
  523. @@ -5,6 +5,7 @@
  524. DIRS += [
  525. "blocklists",
  526. "main",
  527. + "monitor",
  528. "security-state",
  529. ]
  530. --
  531. 2.47.0
  532. From fe166bca96785e408782eeea77d9083e9b7e599a Mon Sep 17 00:00:00 2001
  533. From: grizzlyuser <grizzlyuser@protonmail.com>
  534. Date: Wed, 30 Dec 2020 17:52:10 +0200
  535. Subject: [PATCH 05/13] Utils: disable offline checking
  536. Since only local data is read now, it should always return false for the
  537. current and any future code that relies on it.
  538. ---
  539. services/settings/Utils.sys.mjs | 10 ----------
  540. 1 file changed, 10 deletions(-)
  541. diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
  542. index d5dfe84823..7fcb28863d 100644
  543. --- a/services/settings/Utils.sys.mjs
  544. +++ b/services/settings/Utils.sys.mjs
  545. @@ -192,16 +192,6 @@ export var Utils = {
  546. * @return {bool} Whether network is down or not.
  547. */
  548. get isOffline() {
  549. - try {
  550. - return (
  551. - Services.io.offline ||
  552. - lazy.CaptivePortalService.state ==
  553. - lazy.CaptivePortalService.LOCKED_PORTAL ||
  554. - !lazy.gNetworkLinkService.isLinkUp
  555. - );
  556. - } catch (ex) {
  557. - log.warn("Could not determine network status.", ex);
  558. - }
  559. return false;
  560. },
  561. --
  562. 2.47.0
  563. From b209bdae1c54577442378773790770dd7c1f4150 Mon Sep 17 00:00:00 2001
  564. From: grizzlyuser <grizzlyuser@protonmail.com>
  565. Date: Wed, 30 Dec 2020 17:56:02 +0200
  566. Subject: [PATCH 06/13] Refactor hashing logic to a separate function
  567. It is used instead of internal signature validation mechanism, for
  568. integrity checking of the locally cached data.
  569. ---
  570. services/settings/RemoteSettingsWorker.sys.mjs | 4 ++++
  571. services/settings/SharedUtils.sys.mjs | 9 +++++++--
  572. 2 files changed, 11 insertions(+), 2 deletions(-)
  573. diff --git a/services/settings/RemoteSettingsWorker.sys.mjs b/services/settings/RemoteSettingsWorker.sys.mjs
  574. index 57bfb3f3d5..52a0b7961a 100644
  575. --- a/services/settings/RemoteSettingsWorker.sys.mjs
  576. +++ b/services/settings/RemoteSettingsWorker.sys.mjs
  577. @@ -177,6 +177,10 @@ class Worker {
  578. // task on the current thread instead of the worker thread.
  579. return lazy.SharedUtils.checkContentHash(buffer, size, hash);
  580. }
  581. +
  582. + async getContentHash(bytes) {
  583. + return lazy.SharedUtils.getContentHash(bytes);
  584. + }
  585. }
  586. // Now, first add a shutdown blocker. If that fails, we must have
  587. diff --git a/services/settings/SharedUtils.sys.mjs b/services/settings/SharedUtils.sys.mjs
  588. index 1eeaf0bed9..d998a2d3b1 100644
  589. --- a/services/settings/SharedUtils.sys.mjs
  590. +++ b/services/settings/SharedUtils.sys.mjs
  591. @@ -21,11 +21,16 @@ export var SharedUtils = {
  592. return false;
  593. }
  594. // Has expected content?
  595. + const hashStr = await this.getContentHash(bytes);
  596. + return hashStr == hash;
  597. + },
  598. +
  599. + async getContentHash(bytes) {
  600. const hashBuffer = await crypto.subtle.digest("SHA-256", bytes);
  601. const hashBytes = new Uint8Array(hashBuffer);
  602. const toHex = b => b.toString(16).padStart(2, "0");
  603. - const hashStr = Array.from(hashBytes, toHex).join("");
  604. - return hashStr == hash;
  605. +
  606. + return Array.from(hashBytes, toHex).join("");
  607. },
  608. /**
  609. --
  610. 2.47.0
  611. From 0f02e4174404f1b43f3359ab9d630b3d7c78823e Mon Sep 17 00:00:00 2001
  612. From: grizzlyuser <grizzlyuser@protonmail.com>
  613. Date: Wed, 30 Dec 2020 18:05:02 +0200
  614. Subject: [PATCH 07/13] Client: Fetch and hash records from local dump
  615. Read the records from local dumps. See [1] for details on how to prepare
  616. custom dumps). Records are cached in the local IndexedDB, and the client
  617. updates cached records each time there's a change. Also it verifies
  618. integrity of the data. Then the list of current / created / updated /
  619. deleted records is generated and emitted to every registered listener.
  620. Change upstream signature validation mechanism to a simpler one.
  621. Otherwise, it'd be necessary to sign local records, which is redundant,
  622. because the application package should be signed already by the distro.
  623. Instead of signature property from metadata records, json_dump_metadata
  624. has been introduced. It contains the checksum of the records and size in
  625. bytes. Also added app_build_id property for version checking and updates
  626. of cached data.
  627. Although it's possible to disable integrity checking via preference, it
  628. seems to be not a good idea, because the logic that detects invalid
  629. local data relies on it. In the context of local-only setup, data that
  630. has been received from real Remote Settings server will not contain the
  631. custom metadata, and thus will be considered invalid and then discarded,
  632. while the client gets a chance to gracefully inform registered listeners
  633. about these changes so that they can discard the data received before
  634. the upgrade to local-only setup.
  635. [1] https://firefox-source-docs.mozilla.org/services/common/services/RemoteSettings.html#initial-data
  636. ---
  637. .../settings/RemoteSettingsClient.sys.mjs | 66 ++++++++-----------
  638. 1 file changed, 28 insertions(+), 38 deletions(-)
  639. diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
  640. index 7e98e6d5b3..64a592e055 100644
  641. --- a/services/settings/RemoteSettingsClient.sys.mjs
  642. +++ b/services/settings/RemoteSettingsClient.sys.mjs
  643. @@ -714,11 +714,9 @@ export class RemoteSettingsClient extends EventEmitter {
  644. // If the data is up-to-date but don't have metadata (records loaded from dump),
  645. // we fetch them and validate the signature immediately.
  646. - if (this.verifySignature && lazy.ObjectUtils.isEmpty(localMetadata)) {
  647. + if (this.verifySignature && lazy.ObjectUtils.isEmpty(localMetadata?.json_dump_metadata)) {
  648. lazy.console.debug(`${this.identifier} pull collection metadata`);
  649. - const metadata = await this.httpClient().getData({
  650. - query: { _expected: expectedTimestamp },
  651. - });
  652. + const { metadata } = await this._fetchChangeset(expectedTimestamp);
  653. await this.db.importChanges(metadata);
  654. // We don't bother validating the signature if the dump was just loaded. We do
  655. // if the dump was loaded at some other point (eg. from .get()).
  656. @@ -995,38 +993,28 @@ export class RemoteSettingsClient extends EventEmitter {
  657. * @returns {Promise}
  658. */
  659. async _validateCollectionSignature(records, timestamp, metadata) {
  660. - if (!metadata?.signature) {
  661. + if (!metadata?.json_dump_metadata) {
  662. throw new MissingSignatureError(this.identifier);
  663. }
  664. - if (!this._verifier) {
  665. - this._verifier = Cc[
  666. - "@mozilla.org/security/contentsignatureverifier;1"
  667. - ].createInstance(Ci.nsIContentSignatureVerifier);
  668. - }
  669. -
  670. - // This is a content-signature field from an autograph response.
  671. const {
  672. - signature: { x5u, signature },
  673. + json_dump_metadata: { hash, size },
  674. } = metadata;
  675. - const certChain = await (await lazy.Utils.fetch(x5u)).text();
  676. // Merge remote records with local ones and serialize as canonical JSON.
  677. const serialized = await lazy.RemoteSettingsWorker.canonicalStringify(
  678. records,
  679. timestamp
  680. );
  681. - lazy.console.debug(`${this.identifier} verify signature using ${x5u}`);
  682. + lazy.console.debug(`${this.identifier} verify signature using size ${size} and hash ${hash}`);
  683. if (
  684. - !(await this._verifier.asyncVerifyContentSignature(
  685. - serialized,
  686. - "p384ecdsa=" + signature,
  687. - certChain,
  688. - this.signerName,
  689. - lazy.Utils.CERT_CHAIN_ROOT_IDENTIFIER
  690. + !(await lazy.RemoteSettingsWorker.checkContentHash(
  691. + new TextEncoder().encode(serialized),
  692. + size,
  693. + hash
  694. ))
  695. ) {
  696. - throw new InvalidSignatureError(this.identifier, x5u);
  697. + throw new InvalidSignatureError(this.identifier);
  698. }
  699. }
  700. @@ -1193,24 +1181,26 @@ export class RemoteSettingsClient extends EventEmitter {
  701. * @param since timestamp of last sync (optional)
  702. */
  703. async _fetchChangeset(expectedTimestamp, since) {
  704. - const client = this.httpClient();
  705. - const {
  706. - metadata,
  707. - timestamp: remoteTimestamp,
  708. - changes: remoteRecords,
  709. - } = await client.execute(
  710. - {
  711. - path: `/buckets/${this.bucketName}/collections/${this.collectionName}/changeset`,
  712. - },
  713. - {
  714. - query: {
  715. - _expected: expectedTimestamp,
  716. - _since: since,
  717. - },
  718. - }
  719. + const { data } = await lazy.SharedUtils.loadJSONDump(
  720. + this.bucketName,
  721. + this.collectionName
  722. );
  723. + const remoteRecords = data ?? [];
  724. +
  725. + const serialized = await lazy.RemoteSettingsWorker.canonicalStringify(
  726. + remoteRecords,
  727. + expectedTimestamp
  728. + );
  729. + const bytes = new TextEncoder().encode(serialized);
  730. + const metadata = {
  731. + app_build_id: Services.appinfo.appBuildID,
  732. + json_dump_metadata: {
  733. + hash: await lazy.RemoteSettingsWorker.getContentHash(bytes),
  734. + size: bytes.length,
  735. + },
  736. + }
  737. return {
  738. - remoteTimestamp,
  739. + remoteTimestamp: expectedTimestamp,
  740. metadata,
  741. remoteRecords,
  742. };
  743. --
  744. 2.47.0
  745. From 8b6f8dfd7bf32488e1f17312c483b7f1de55d4c3 Mon Sep 17 00:00:00 2001
  746. From: grizzlyuser <grizzlyuser@protonmail.com>
  747. Date: Wed, 30 Dec 2020 18:42:56 +0200
  748. Subject: [PATCH 08/13] Client: start deferred sync on get() or on()
  749. The users of the RemoteSettingsClient.sys.mjs can receive records from it in
  750. two ways: by calling get(), and by subscribing to events by calling
  751. on().
  752. So hook a deferred sync whenever something calls these methods. Because
  753. multiple of those calls can be made quite early and in very short time,
  754. set up a deferred task that will be armed only when needed and only once
  755. in a second. When the task is running it first checks if the local data
  756. came from the dump of the current app build, and no-ops if true. If
  757. false, it triggers a sync. Then adds a flag if the client has been
  758. correctly synchronized with the dump, so that no metadata checking
  759. occurs during the session.
  760. ---
  761. .../settings/RemoteSettingsClient.sys.mjs | 27 ++++++++++++++++++-
  762. 1 file changed, 26 insertions(+), 1 deletion(-)
  763. diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
  764. index 64a592e055..371f58bfd4 100644
  765. --- a/services/settings/RemoteSettingsClient.sys.mjs
  766. +++ b/services/settings/RemoteSettingsClient.sys.mjs
  767. @@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  768. ClientEnvironmentBase:
  769. "resource://gre/modules/components-utils/ClientEnvironment.sys.mjs",
  770. Database: "resource://services-settings/Database.sys.mjs",
  771. + DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
  772. IDBHelpers: "resource://services-settings/IDBHelpers.sys.mjs",
  773. KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs",
  774. ObjectUtils: "resource://gre/modules/ObjectUtils.sys.mjs",
  775. @@ -23,6 +24,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  776. });
  777. const TELEMETRY_COMPONENT = "Remotesettings";
  778. +const DEFERRED_SYNC_DELAY_MILLISECONDS = 1000;
  779. ChromeUtils.defineLazyGetter(lazy, "console", () => lazy.Utils.log);
  780. @@ -341,6 +343,11 @@ export class RemoteSettingsClient extends EventEmitter {
  781. this._lastCheckTimePref = lastCheckTimePref;
  782. this._verifier = null;
  783. this._syncRunning = false;
  784. + this._deferredSync = new lazy.DeferredTask(async () => {
  785. + if (!this._syncRunning && !(await this._isSynced())) {
  786. + await this.sync();
  787. + }
  788. + }, DEFERRED_SYNC_DELAY_MILLISECONDS);
  789. // This attribute allows signature verification to be disabled, when running tests
  790. // or when pulling data from a dev server.
  791. @@ -370,6 +377,11 @@ export class RemoteSettingsClient extends EventEmitter {
  792. this.db.identifier = this.identifier;
  793. }
  794. + on(event, callback) {
  795. + super.on(event, callback);
  796. + this._deferredSync.arm();
  797. + }
  798. +
  799. get identifier() {
  800. return `${this.bucketName}/${this.collectionName}`;
  801. }
  802. @@ -443,6 +455,10 @@ export class RemoteSettingsClient extends EventEmitter {
  803. let lastModified = forceSync ? null : await this.db.getLastModified();
  804. let hasLocalData = lastModified !== null;
  805. + if (!(await this._isSynced())) {
  806. + throw new MissingSignatureError(this.identifier);
  807. + }
  808. +
  809. if (forceSync) {
  810. if (!this._importingPromise) {
  811. this._importingPromise = (async () => {
  812. @@ -559,7 +575,10 @@ export class RemoteSettingsClient extends EventEmitter {
  813. // No need to verify signature on JSON dumps.
  814. // If local DB cannot be read, then we don't even try to do anything,
  815. // we return results early.
  816. - return this._filterEntries(data);
  817. + const filtered = this._filterEntries(data);
  818. + this._deferredSync.arm();
  819. +
  820. + return filtered;
  821. }
  822. lazy.console.debug(
  823. @@ -599,6 +618,12 @@ export class RemoteSettingsClient extends EventEmitter {
  824. return final;
  825. }
  826. + async _isSynced() {
  827. + this._synced ||=
  828. + Services.appinfo.appBuildID === (await this.db?.getMetadata())?.app_build_id;
  829. + return this._synced;
  830. + }
  831. +
  832. /**
  833. * Synchronize the local database with the remote server.
  834. *
  835. --
  836. 2.47.0
  837. From 4346c63a3cd1312424fb79dcbce912b64c97357a Mon Sep 17 00:00:00 2001
  838. From: grizzlyuser <grizzlyuser@protonmail.com>
  839. Date: Wed, 30 Dec 2020 18:53:51 +0200
  840. Subject: [PATCH 09/13] Client: deep compare records if timestamps match
  841. When the list of current / updated / deleted records is generated, their
  842. modification timestamps are compared to detect the updates.
  843. Although in practice this is unlikely to happen, in theory the
  844. timestamp of some older record received from Remote Settings can match
  845. with the modified record in the dump. Although JSON processing script
  846. makes sure to add unique timestamps to each of the modified records,
  847. it's still possible to update dumps manually and simply forget to update
  848. timestamps. So serialize the records and compare them as strings to be
  849. on the safe side. This should happen only once after upgrading to each
  850. new version of the application, so is not likely to introduce any
  851. noticeable performance issues.
  852. ---
  853. services/settings/RemoteSettingsClient.sys.mjs | 6 +++++-
  854. 1 file changed, 5 insertions(+), 1 deletion(-)
  855. diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
  856. index 371f58bfd4..3119d5b33d 100644
  857. --- a/services/settings/RemoteSettingsClient.sys.mjs
  858. +++ b/services/settings/RemoteSettingsClient.sys.mjs
  859. @@ -9,6 +9,7 @@ import { Downloader } from "resource://services-settings/Attachments.sys.mjs";
  860. const lazy = {};
  861. ChromeUtils.defineESModuleGetters(lazy, {
  862. + CanonicalJSON: "resource://gre/modules/CanonicalJSON.sys.mjs",
  863. ClientEnvironmentBase:
  864. "resource://gre/modules/components-utils/ClientEnvironment.sys.mjs",
  865. Database: "resource://services-settings/Database.sys.mjs",
  866. @@ -1181,7 +1182,10 @@ export class RemoteSettingsClient extends EventEmitter {
  867. const old = oldById.get(r.id);
  868. if (old) {
  869. oldById.delete(r.id);
  870. - if (r.last_modified != old.last_modified) {
  871. + if (
  872. + r.last_modified != old.last_modified ||
  873. + lazy.CanonicalJSON.stringify(r) != lazy.CanonicalJSON.stringify(old)
  874. + ) {
  875. syncResult.updated.push({ old, new: r });
  876. }
  877. } else {
  878. --
  879. 2.47.0
  880. From 2c094c83de139f3f0d1ab8e43fc8e5b376286c3f Mon Sep 17 00:00:00 2001
  881. From: grizzlyuser <grizzlyuser@protonmail.com>
  882. Date: Wed, 30 Dec 2020 19:01:39 +0200
  883. Subject: [PATCH 10/13] Client: delete more data on cleanup
  884. When the client detects the local data is invalid (i.e. it came from
  885. real Remote Settings and can have unwanted records), delete not only
  886. the records, but also the attachments that came with them, because they
  887. too can be problematic. And last check time preference, because it's not
  888. useful anyway when remote-settings.sys.mjs doesn't do any polling for changes.
  889. Note that attachments should be deleted before the records, because the
  890. logic gets the data about the attachments from those records.
  891. ---
  892. services/settings/RemoteSettingsClient.sys.mjs | 12 +++++++++---
  893. 1 file changed, 9 insertions(+), 3 deletions(-)
  894. diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
  895. index 3119d5b33d..c26e81ce0a 100644
  896. --- a/services/settings/RemoteSettingsClient.sys.mjs
  897. +++ b/services/settings/RemoteSettingsClient.sys.mjs
  898. @@ -262,7 +262,7 @@ class AttachmentDownloader extends Downloader {
  899. allRecords
  900. .filter(r => !!r.attachment)
  901. .map(r =>
  902. - Promise.all([this.deleteDownloaded(r), this.deleteFromDisk(r)])
  903. + Promise.all([this.deleteDownloaded(r), this.deleteFromDisk(r), this.deleteCached(r.id)])
  904. )
  905. );
  906. }
  907. @@ -1141,7 +1141,7 @@ export class RemoteSettingsClient extends EventEmitter {
  908. // Signature failed, clear local DB because it contains
  909. // bad data (local + remote changes).
  910. lazy.console.debug(`${this.identifier} clear local data`);
  911. - await this.db.clear();
  912. + await this._clearAll();
  913. // Local data was tampered, throw and it will retry from empty DB.
  914. lazy.console.error(`${this.identifier} local data was corrupted`);
  915. throw new CorruptedDataError(this.identifier);
  916. @@ -1163,7 +1163,7 @@ export class RemoteSettingsClient extends EventEmitter {
  917. // _importJSONDump() only clears DB if dump is available,
  918. // therefore do it here!
  919. if (imported < 0) {
  920. - await this.db.clear();
  921. + await this._clearAll();
  922. }
  923. }
  924. }
  925. @@ -1203,6 +1203,12 @@ export class RemoteSettingsClient extends EventEmitter {
  926. return syncResult;
  927. }
  928. + async _clearAll() {
  929. + await this.attachments.deleteAll();
  930. + await this.db.clear();
  931. + Services.prefs.clearUserPref(this.lastCheckTimePref);
  932. + }
  933. +
  934. /**
  935. * Fetch information from changeset endpoint.
  936. *
  937. --
  938. 2.47.0
  939. From 8330c0202a34df1b2c33ca5cbaacf449e2a29480 Mon Sep 17 00:00:00 2001
  940. From: grizzlyuser <grizzlyuser@protonmail.com>
  941. Date: Wed, 30 Dec 2020 19:07:56 +0200
  942. Subject: [PATCH 11/13] Client: remove comparison of collection timestamps
  943. In case if the cached data that came from real Remote Settings server
  944. (before the upgrade to local-only setup) has collection timestamp, that
  945. is newer than the packaged local dump, then this comparison logic can
  946. lead to early return of old data, skipping the integrity checking and
  947. necessary cleanup. So remove the checks.
  948. ---
  949. services/settings/RemoteSettingsClient.sys.mjs | 5 -----
  950. 1 file changed, 5 deletions(-)
  951. diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
  952. index c26e81ce0a..65b3393946 100644
  953. --- a/services/settings/RemoteSettingsClient.sys.mjs
  954. +++ b/services/settings/RemoteSettingsClient.sys.mjs
  955. @@ -1083,14 +1083,9 @@ export class RemoteSettingsClient extends EventEmitter {
  956. updated: [],
  957. deleted: [],
  958. };
  959. - // If data wasn't changed, return empty sync result.
  960. - // This can happen when we update the signature but not the data.
  961. lazy.console.debug(
  962. `${this.identifier} local timestamp: ${localTimestamp}, remote: ${remoteTimestamp}`
  963. );
  964. - if (localTimestamp && remoteTimestamp < localTimestamp) {
  965. - return syncResult;
  966. - }
  967. await this.db.importChanges(metadata, remoteTimestamp, remoteRecords, {
  968. clear: retry,
  969. --
  970. 2.47.0
  971. From 56ea078c21cd355e9a01c8f901a105c9985b1ebf Mon Sep 17 00:00:00 2001
  972. From: grizzlyuser <grizzlyuser@protonmail.com>
  973. Date: Wed, 30 Dec 2020 19:15:44 +0200
  974. Subject: [PATCH 12/13] Attachments: load only from dump and drop cached
  975. ---
  976. services/settings/Attachments.sys.mjs | 44 +++++----------------------
  977. 1 file changed, 8 insertions(+), 36 deletions(-)
  978. diff --git a/services/settings/Attachments.sys.mjs b/services/settings/Attachments.sys.mjs
  979. index 9982c27661..00c1491ea5 100644
  980. --- a/services/settings/Attachments.sys.mjs
  981. +++ b/services/settings/Attachments.sys.mjs
  982. @@ -334,10 +334,11 @@ export class Downloader {
  983. retries,
  984. checkHash,
  985. attachmentId = record?.id,
  986. - fallbackToCache = false,
  987. fallbackToDump = false,
  988. avoidDownload = false,
  989. } = options || {};
  990. + const fallbackToCache = false;
  991. +
  992. if (!attachmentId) {
  993. // Check for pre-condition. This should not happen, but it is explicitly
  994. // checked to avoid mixing up attachments, which could be dangerous.
  995. @@ -397,6 +398,7 @@ export class Downloader {
  996. const newBuffer = await this.downloadAsBytes(record, {
  997. retries,
  998. checkHash,
  999. + dumpInfo,
  1000. });
  1001. const blob = new Blob([newBuffer]);
  1002. // Store in cache but don't wait for it before returning.
  1003. @@ -430,7 +432,7 @@ export class Downloader {
  1004. }
  1005. try {
  1006. - return { ...(await cacheInfo.getResult()), _source: "cache_fallback" };
  1007. + await this.cacheImpl.delete(attachmentId);
  1008. } catch (e) {
  1009. // Failed to read from cache, e.g. IndexedDB unusable.
  1010. console.error(e);
  1011. @@ -518,7 +520,7 @@ export class Downloader {
  1012. * @returns {String} the absolute file path to the downloaded attachment.
  1013. */
  1014. async downloadToDisk(record, options = {}) {
  1015. - const { retries = 3 } = options;
  1016. + const retries = 0;
  1017. const {
  1018. attachment: { filename, size, hash },
  1019. } = record;
  1020. @@ -573,40 +575,10 @@ export class Downloader {
  1021. */
  1022. async downloadAsBytes(record, options = {}) {
  1023. const {
  1024. - attachment: { location, hash, size },
  1025. - } = record;
  1026. -
  1027. - let baseURL;
  1028. - try {
  1029. - baseURL = await lazy.Utils.baseAttachmentsURL();
  1030. - } catch (error) {
  1031. - throw new Downloader.ServerInfoError(error);
  1032. - }
  1033. -
  1034. - const remoteFileUrl = baseURL + location;
  1035. + dumpInfo = new LazyRecordAndBuffer(() => this._readAttachmentDump(attachmentId))
  1036. + } = options;
  1037. - const { retries = 3, checkHash = true } = options;
  1038. - let retried = 0;
  1039. - while (true) {
  1040. - try {
  1041. - const buffer = await this._fetchAttachment(remoteFileUrl);
  1042. - if (!checkHash) {
  1043. - return buffer;
  1044. - }
  1045. - if (
  1046. - await lazy.RemoteSettingsWorker.checkContentHash(buffer, size, hash)
  1047. - ) {
  1048. - return buffer;
  1049. - }
  1050. - // Content is corrupted.
  1051. - throw new Downloader.BadContentError(location);
  1052. - } catch (e) {
  1053. - if (retried >= retries) {
  1054. - throw e;
  1055. - }
  1056. - }
  1057. - retried++;
  1058. - }
  1059. + return (await dumpInfo.getResult()).buffer;
  1060. }
  1061. /**
  1062. --
  1063. 2.47.0
  1064. From f93a08be54f24a2cf9a1cf8693e3682288a34564 Mon Sep 17 00:00:00 2001
  1065. From: grizzlyuser <grizzlyuser@protonmail.com>
  1066. Date: Wed, 30 Dec 2020 19:22:20 +0200
  1067. Subject: [PATCH 13/13] Disable CRLite entirely for now
  1068. It's designed to fetch the data from Remote Settings. One of the main
  1069. selling points is that new revocations can be pushed to the clients
  1070. within minutes. That won't work with local-only setup. Although (some?)
  1071. of the JSON dumps for it are in place, obviously the updates won't
  1072. happen that fast.
  1073. Disable the preference right in the source code, so that the patch fails
  1074. to apply when the upstream decides to set it to fully enforcing mode
  1075. by default.
  1076. The solution with CRLite is up for discussion. If necessary, it's
  1077. possible to make clients for blessed collections to communicate to real
  1078. Remote Settings server. For example, for collections related to
  1079. certificate revocations.
  1080. ---
  1081. modules/libpref/init/StaticPrefList.yaml | 2 +-
  1082. security/manager/ssl/nsNSSComponent.cpp | 1 +
  1083. 2 files changed, 2 insertions(+), 1 deletion(-)
  1084. diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
  1085. index 72202ac640..1d9c6f97f7 100644
  1086. --- a/modules/libpref/init/StaticPrefList.yaml
  1087. +++ b/modules/libpref/init/StaticPrefList.yaml
  1088. @@ -15778,7 +15778,7 @@
  1089. # 3: Consult CRLite and enforce "Not Revoked" results, but defer to OCSP for "Revoked".
  1090. - name: security.pki.crlite_mode
  1091. type: RelaxedAtomicUint32
  1092. - value: 3
  1093. + value: 0
  1094. mirror: always
  1095. # The CRLite filter channel to which the user is subscribed.
  1096. diff --git a/security/manager/ssl/nsNSSComponent.cpp b/security/manager/ssl/nsNSSComponent.cpp
  1097. index ed15648dae..0ac4762d11 100644
  1098. --- a/security/manager/ssl/nsNSSComponent.cpp
  1099. +++ b/security/manager/ssl/nsNSSComponent.cpp
  1100. @@ -1142,6 +1142,7 @@ void nsNSSComponent::setValidationOptions(
  1101. CRLiteMode defaultCRLiteMode = CRLiteMode::Disabled;
  1102. CRLiteMode crliteMode =
  1103. static_cast<CRLiteMode>(StaticPrefs::security_pki_crlite_mode());
  1104. + // Adding a comment just in case so that the patch breaks as soon as any surrounding lines get changed
  1105. switch (crliteMode) {
  1106. case CRLiteMode::Disabled:
  1107. case CRLiteMode::TelemetryOnly:
  1108. --
  1109. 2.47.0