Commit bbee5530 authored by anonym's avatar anonym
Browse files

Tor Browser: kill the branding@amnesia.boum.org add-on.

This old school Firefox add-on is not compatible with e10s, so we move
its functionality into our Tor Browser wrapper instead of porting to a
WebExtension -- that would be more work, and we'd still have to do
ugly stuff to work around mandatory signing.

Refs: #12569

                                     _ " _
   _ " _                            (_\|/_)
  (_\|/_)   _ " _           _ " _    (/|\)
   (/|\)   (_\|/_) " _     (_\|/_)
            (/|\)_\|/_)     (/|\)
                 (/|\)

And yay, I found a use case for this kind of Enterprise feature that's
not about enslaving corporate computers, but for freedom, love and all
that good stuff! Namaste!

       ,,,                      ,,,
      {{{}}    ,,,             {{{}}    ,,,
   ,,, ~Y~    {{{}},,,      ,,, ~Y~    {{{}},,,
  {{}}} |/,,,  ~Y~{{}}}    {{}}} |/,,,  ~Y~{{}}}
   ~Y~ \|{{}}}/\|/ ~Y~  ,,, ~Y~ \|{{}}}/\|/ ~Y~  ,,,
   \|/ \|/~Y~  \|,,,|/ {{}}}\|/ \|/~Y~  \|,,,|/ {{}}}
   \|/ \|/\|/  \{{{}}/  ~Y~ \|/ \|/\|/  \{{{}}/  ~Y~
   \|/\\|/\|/ \\|~Y~//  \|/ \|/\\|/\|/ \\|~Y~//  \|/
   \|//\|/\|/,\\|/|/|// \|/ \|//\|/\|/,\\|/|/|// \|/
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
parent f11ebadf
......@@ -135,13 +135,12 @@ apply_extension_code_signing_hacks () {
diff -Naur a/chrome/toolkit/content/mozapps/extensions/extensions.js b/chrome/toolkit/content/mozapps/extensions/extensions.js
--- a/chrome/toolkit/content/mozapps/extensions/extensions.js 2000-01-01 00:00:00.000000000 +0000
+++ b/chrome/toolkit/content/mozapps/extensions/extensions.js 2000-01-01 00:00:00.000000000 +0000
@@ -282,7 +282,9 @@
@@ -282,7 +282,8 @@
// they aren't the correct type for signing.
if (aAddon.id == "torbutton@torproject.org" ||
aAddon.id == "tor-launcher@torproject.org" ||
- aAddon.id == "https-everywhere-eff@eff.org") {
+ aAddon.id == "https-everywhere-eff@eff.org" ||
+ aAddon.id == "branding@amnesia.boum.org" ||
+ aAddon.id == "uBlock0@raymondhill.net") {
return true;
}
......@@ -149,13 +148,12 @@ diff -Naur a/chrome/toolkit/content/mozapps/extensions/extensions.js b/chrome/to
diff -Naur a/modules/addons/XPIProvider.jsm b/modules/addons/XPIProvider.jsm
--- a/modules/addons/XPIProvider.jsm 2000-01-01 00:00:00.000000000 +0000
+++ b/modules/addons/XPIProvider.jsm 2000-01-01 00:00:00.000000000 +0000
@@ -749,7 +749,9 @@
@@ -749,7 +749,8 @@
if (aAddon.id == "torbutton@torproject.org" ||
aAddon.id == "tor-launcher@torproject.org" ||
aAddon.id == "https-everywhere-eff@eff.org" ||
- aAddon.id == "meek-http-helper@bamsoftware.com") {
+ aAddon.id == "meek-http-helper@bamsoftware.com" ||
+ aAddon.id == "branding@amnesia.boum.org" ||
+ aAddon.id == "uBlock0@raymondhill.net") {
return true;
}
......@@ -172,13 +170,12 @@ EOF
diff -Naur x/components/nsBrowserGlue.js y/components/nsBrowserGlue.js
--- a/components/nsBrowserGlue.js 2000-01-01 00:00:00.000000000 +0000
+++ b/components/nsBrowserGlue.js 2000-01-01 00:00:00.000000000 +0000
@@ -1122,7 +1122,9 @@
@@ -1122,7 +1122,8 @@
if ((addon.signedState <= AddonManager.SIGNEDSTATE_MISSING) &&
!(addon.id == "torbutton@torproject.org" ||
addon.id == "tor-launcher@torproject.org" ||
- addon.id == "https-everywhere-eff@eff.org")) {
+ addon.id == "https-everywhere-eff@eff.org" ||
+ addon.id == "branding@amnesia.boum.org" ||
+ addon.id == "uBlock0@raymondhill.net")) {
this._notifyUnsignedAddonsDisabled();
break;
......@@ -202,6 +199,32 @@ EOF
)
}
# Modern Firefox doesn't apply browser.search.defaultenginename on
# start, and the other ways to get it to work (e.g. pre-generating
# search.json.mozlz4) seems rather complex. Instead, let's just make
# browser.search.defaultenginename work again by employing some
# Enterprise features to run arbitrary JavaScript with acces to the
# Firefox internals. For the details of this feature, see:
# https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment
apply_default_searchengine_hacks () {
local destination
destination="${1}"
cat > "${destination}/defaults/pref/autoconfig.js" <<EOF
// This file must start with a comment
pref("general.config.filename", "mozilla.cfg");
pref("general.config.obscure_value", 0);
EOF
cat > "${destination}/mozilla.cfg" <<EOF
// This file must start with a comment
var searchService = Components.classes["@mozilla.org/browser/search-service;1"].getService(Components.interfaces.nsIBrowserSearchService);
var engineName = getPref("browser.search.defaultenginename");
var engine = searchService.getEngineByName(engineName);
searchService.currentEngine = engine;
EOF
}
install_langpacks_from_bundles() {
local bundles_dir destination
bundles_dir="${1}"
......@@ -280,6 +303,7 @@ download_and_verify_files "${TBB_TARBALLS_BASE_URL}" "${TBB_TARBALLS}" "${TMP}"
install_tor_browser "${TMP}/${MAIN_TARBALL}" "${TBB_INSTALL}"
apply_extension_code_signing_hacks "${TBB_INSTALL}"
apply_default_searchengine_hacks "${TBB_INSTALL}"
mkdir -p "${TBB_EXT}"
if [ "${NIGHTLY_BUILD}" != yes ]; then
......
......@@ -8,9 +8,6 @@ echo "Localize each supported browser locale"
# supported_tor_browser_locales()
. /usr/local/lib/tails-shell-library/tor-browser.sh
# Import set_simple_config_key()
. /usr/local/lib/tails-shell-library/common.sh
# Import language_code_from_locale()
. /usr/local/lib/tails-shell-library/localization.sh
......@@ -23,8 +20,7 @@ echo "Localize each supported browser locale"
TBB_LOCALIZED_SEARCHPLUGINS_DIR="${TBB_INSTALL}/distribution/searchplugins/locale/"
BROWSER_LOCALIZATION_DIR="/usr/share/tails/browser-localization"
DESCRIPTIONS_FILE="${BROWSER_LOCALIZATION_DIR}/descriptions"
BRANDING_TEMPLATE_FILE="${BROWSER_LOCALIZATION_DIR}/amnesia.properties-template"
BRANDING_DIR="/usr/local/share/tor-browser-extensions/branding@amnesia.boum.org/"
LOCALE_PROFILES_DIR="/etc/tor-browser/locale-profiles/"
NO_SPELLCHECKER_LOCALES="ja ko nl pl tr zh"
# Sanity check that each supported Tor Browser locale has a
......@@ -114,13 +110,10 @@ while IFS=: read MOZILLA_LOCALE LOCATION LOCALIZED_LANG STARTPAGE_LANG STARTPAGE
rm "${LOCALIZED_WIKIPEDIA_ICON_PATH}" \
"${WIKIPEDIA_SEARCH_ICON_BASE64_PATH}"
# We use the branding@amnesia.org extension to set some per-locale
# default prefs that set the appropriate localization options.
TARGET_BRANDING_DIR="${BRANDING_DIR}/chrome/locale/${MOZILLA_LOCALE}"
echo "locale amnesiabranding ${MOZILLA_LOCALE} chrome/locale/${MOZILLA_LOCALE}/" >> "${BRANDING_DIR}/chrome.manifest"
mkdir -p "${TARGET_BRANDING_DIR}"
TARGET_BRANDING_FILE="${TARGET_BRANDING_DIR}/amnesia.properties"
cp "${BRANDING_TEMPLATE_FILE}" "${TARGET_BRANDING_FILE}"
# Our Tor Browser wrapper script will make use of the following
# per-locale profiles to set localized defaults for various prefs.
mkdir -p "${LOCALE_PROFILES_DIR}"
LOCALE_PROFILE_FILE="${LOCALE_PROFILES_DIR}/${MOZILLA_LOCALE}.js"
for KEY in browser.search.defaultenginename \
browser.search.selectedEngine; do
PLUGIN="DuckDuckGo - ${LOCALIZED_LANG}"
......@@ -128,7 +121,7 @@ while IFS=: read MOZILLA_LOCALE LOCATION LOCALIZED_LANG STARTPAGE_LANG STARTPAGE
echo "Trying to make search plugin '${PLUGIN}' the default for ${MOZILLA_LOCALE} but it unexpectedly wasn't the one we generated earlier" >&2
exit 1
fi
set_simple_config_key "${TARGET_BRANDING_FILE}" "${KEY}" "${PLUGIN}"
set_mozilla_pref "${LOCALE_PROFILE_FILE}" "${KEY}" "\"${PLUGIN}\""
done
TBB_DICTIONARIES_DIR="${TBB_INSTALL}/dictionaries"
unset SPELLCHECKER_LOCALE
......@@ -145,15 +138,15 @@ while IFS=: read MOZILLA_LOCALE LOCATION LOCALIZED_LANG STARTPAGE_LANG STARTPAGE
exit 1
fi
fi
set_simple_config_key "${TARGET_BRANDING_FILE}" \
set_mozilla_pref "${LOCALE_PROFILE_FILE}" \
"spellchecker.dictionary" \
"${SPELLCHECKER_LOCALE}"
"\"${SPELLCHECKER_LOCALE}\""
HOMEPAGE="https://tails.boum.org/home/"
if echo "${TAILS_WIKI_SUPPORTED_LANGUAGES}" | grep -qw "${LANG_CODE}"; then
HOMEPAGE="${HOMEPAGE}index.${LANG_CODE}.html"
fi
set_simple_config_key "${TARGET_BRANDING_FILE}" \
"browser.startup.homepage" "${HOMEPAGE}"
set_mozilla_pref "${LOCALE_PROFILE_FILE}" \
"browser.startup.homepage" "\"${HOMEPAGE}\"" "user_pref"
done < "${DESCRIPTIONS_FILE}"
# This directory is not needed after build time.
......@@ -201,5 +194,5 @@ done
# All generated and modified files must remain world-readable.
chmod -R a+rX "${TBB_LOCALIZED_SEARCHPLUGINS_DIR}" \
"${BRANDING_DIR}" \
"${LOCALE_PROFILES_DIR}" \
"${TBB_EXT}"
#!/bin/sh
set -e
echo "Overriding TBB branding with our own"
# Import the TBB_PROFILE variable.
. /usr/local/lib/tails-shell-library/tor-browser.sh
install --owner root --group root --mode 0755 --directory /etc/xul-ext
install --owner root --group root --mode 0644 \
"${TBB_PROFILE}"/extensions/branding@amnesia.boum.org/defaults/preferences/prefs.js \
/etc/xul-ext/torbutton.js
......@@ -77,8 +77,8 @@ pref("browser.newtabpage.directory.ping", "");
pref("browser.newtabpage.introShown", true);
// Don't use geographically specific search prefs, like
// browser.search.*.US for US locales. Our generated amnesia branding
// add-on localizes search-engines in an incompatible but equivalent
// browser.search.*.US for US locales. Our generated localization
// profiles localizes search-engines in an incompatible but equivalent
// way.
pref("browser.search.geoSpecificDefaults", false);
......
......@@ -15,7 +15,7 @@ set_mozilla_pref() {
value="${3}"
# Sometimes we might want to do e.g. user_pref
prefix="${4:-pref}"
sed -i "/^${prefix}(\"${name}\",/d" "${file}"
[ -e "${file}" ] && sed -i "/^${prefix}(\"${name}\",/d" "${file}"
echo "${prefix}(\"${name}\", ${value});" >> "${file}"
}
......@@ -93,7 +93,12 @@ configure_xulrunner_app_locale() {
}
configure_best_tor_browser_locale() {
configure_xulrunner_app_locale "${1}" "$(guess_best_tor_browser_locale)"
local profile best_locale
profile="${1}"
best_locale="$(guess_best_tor_browser_locale)"
configure_xulrunner_app_locale "${profile}" "${best_locale}"
cat "/etc/tor-browser/locale-profiles/${best_locale}.js" \
>> "${profile}/preferences/0000locale.js"
}
configure_best_tor_launcher_locale() {
......
pref("browser.search.defaultenginename", "chrome://amnesiabranding/locale/amnesia.properties");
pref("browser.search.selectedEngine", "chrome://amnesiabranding/locale/amnesia.properties");
pref("browser.startup.homepage", "chrome://amnesiabranding/locale/amnesia.properties");
pref("spellchecker.dictionary", "chrome://amnesiabranding/locale/amnesia.properties");
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>branding@amnesia.boum.org</em:id>
<em:name>amnesia branding</em:name>
<em:version>0.2</em:version>
<em:creator>amnesia</em:creator>
<!-- Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0</em:minVersion>
<em:maxVersion>10.0.999</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment