unsafe-browser 7.1 KB
Newer Older
1
#!/bin/sh
2

3
4
set -e

Tails developers's avatar
Tails developers committed
5
CMD=$(basename ${0})
6
LOCK=/var/lock/${CMD}
Tails developers's avatar
Tails developers committed
7
8

. gettext.sh
9
TEXTDOMAIN="tails"
Tails developers's avatar
Tails developers committed
10
11
export TEXTDOMAIN

12
13
14
CONF_DIR=/var/lib/unsafe-browser
COW=${CONF_DIR}/cow
CHROOT=${CONF_DIR}/chroot
15
BROWSER_USER=clearnet
16
17
18

# Import tor_is_working()
. /usr/local/lib/tails-shell-library/tor.sh
19

20
21
22
# Import the TBB_INSTALL, TBB_EXT and TBB_PROFILE variables, and
# exec_firefox(), configure_xulrunner_app_locale() and
# guess_best_tor_browser_locale()
23
24
. /usr/local/lib/tails-shell-library/tor-browser.sh

25
26
. /usr/local/lib/tails-shell-library/chroot-browser.sh

27
28
29
30
31
32
33
34
WARNING_PAGE='/usr/share/doc/tails/website/misc/unsafe_browser_warning'
LANG_CODE="$(echo ${LANG} | head -c 2)"
if [ -r "${WARNING_PAGE}.${LANG_CODE}.html" ]; then
   START_PAGE="${WARNING_PAGE}.${LANG_CODE}.html"
else
   START_PAGE="${WARNING_PAGE}.en.html"
fi

35
36
37
38
if [ -e /var/lib/gdm3/tails.camouflage ]; then
    CAMOUFLAGE=yes
fi

39
cleanup () {
40
    try_cleanup_browser_chroot ${CHROOT} ${COW} ${BROWSER_USER}
41
42
43
}

error () {
44
45
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>
46

47
${@}"
48
    echo "${cli_text}" >&2
49
    sudo -u ${SUDO_USER} zenity --error --title "" --text "${dialog_text}"
50
51
52
    exit 1
}

53
54
verify_start () {
    # Make sure the user really wants to start the browser
55
    local dialog_msg="<b><big>`gettext \"Do you really want to launch the Unsafe Browser?\"`</big></b>
56

Tails developers's avatar
Tails developers committed
57
`gettext \"Network activity within the Unsafe Browser is <b>not anonymous</b>. Only use the Unsafe Browser if necessary, for example if you have to login or register to activate your Internet connection.\"`"
58
59
60
61
62
63
    local launch="`gettext \"_Launch\"`"
    local exit="`gettext \"_Exit\"`"
    # Since zenity can't set the default button to cancel, we switch the
    # labels and interpret the return value as its negation.
    if sudo -u ${SUDO_USER} zenity --question --title "" --ok-label "${exit}" \
       --cancel-label "${launch}" --text "${dialog_msg}"; then
64
65
66
        exit 0
    fi
}
67

68
69
70
show_start_notification () {
    local title="`gettext \"Starting the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, so please be patient.\"`"
71
    tails-notify-user "${title}" "${body}" 10000
72
73
}

74
configure_chroot () {
75
76
    echo "* Configuring chroot"

77
78
    # Set the chroot's DNS servers to those obtained through DHCP
    rm -f ${CHROOT}/etc/resolv.conf
79
    for NS in ${IP4_NAMESERVERS}; do
80
81
82
83
        echo "nameserver ${NS}" >> ${CHROOT}/etc/resolv.conf
    done
    chmod a+r ${CHROOT}/etc/resolv.conf

84
    # Create a fresh browser profile for the clearnet user
85
    BROWSER_PROFILE="${CHROOT}"/home/${BROWSER_USER}/.tor-browser/profile.default
86

87
88
89
    BROWSER_EXT="${BROWSER_PROFILE}"/extensions
    mkdir -p "${BROWSER_EXT}"
    cp -Pr "${TBB_PROFILE}"/extensions/langpack-*.xpi "${BROWSER_EXT}"
90

91
92
    BROWSER_PREFS="${BROWSER_PROFILE}"/preferences/prefs.js
    mkdir -p "$(dirname "${BROWSER_PREFS}")"
93
94

    # Localization
95
    BEST_LOCALE="$(guess_best_tor_browser_locale)"
96
    configure_xulrunner_app_locale "${BROWSER_PROFILE}" "${BEST_LOCALE}"
97

98
    # Disable proxying in the chroot
99
100
    echo 'pref("network.proxy.type", 0);' >> "${BROWSER_PREFS}"
    echo 'pref("network.proxy.socks_remote_dns", false);' >>  "${BROWSER_PREFS}"
101

102
103
104
    # Prevent File -> Print or CTRL+P from causing the browser to hang
    # for several minutes while trying to communicate with CUPS, since
    # access to port 631 isn't allowed through.
105
    echo 'pref("print.postscript.cups.enabled", false);' >> "${BROWSER_PREFS}"
106
    # Hide "Get Addons" in Add-ons manager
107
    echo 'user_pref("extensions.getAddons.showPane", false);' >> "${BROWSER_PREFS}"
108

109
    # Set the name (e.g. window title) of the browser
110
    set_chroot_browser_name ${CHROOT} "`gettext \"Unsafe Browser\"`" "${BEST_LOCALE}"
111

112
113
    # Set start page to something that explains what's going on
    echo 'user_pref("browser.startup.homepage", "'${START_PAGE}'");' >> \
114
115
        "${BROWSER_PREFS}"
    BROWSER_CHROME="${BROWSER_PROFILE}/chrome/userChrome.css"
116
117
118
119
120
121
122
123
124
125
126
127
    mkdir -p "$(dirname "${BROWSER_CHROME}")"
    cat > ${BROWSER_CHROME} << EOF
/* Required, do not remove */
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

/* Hide TorBrowser Health Report and its configuration option */
#appmenu_healthReport,
#dataChoicesTab,
#healthReport

{display: none !important}
EOF
128
129

    # Remove all bookmarks
130
    rm -f ${CHROOT}/"${TBB_PROFILE}"/bookmarks.html
131
132
    rm -f ${BROWSER_PROFILE}/bookmarks.html
    rm -f ${BROWSER_PROFILE}/places.sqlite
133

134
    chown -R ${BROWSER_USER}:${BROWSER_USER} ${CHROOT}/home/clearnet/.tor-browser
135
136
137
138
139
140

    # Set a scary theme (except if we're using Windows
    # camouflage). Note that the tails-activate-win8-theme script that
    # we may run below requires that the browser profile is writable
    # by the user running the script (i.e. clearnet).
    if [ -z "${CAMOUFLAGE}" ]; then
141
        cat >> "${BROWSER_PREFS}" <<EOF
142
143
144
145
146
147
pref("lightweightThemes.isThemeSelected", true);
pref("lightweightThemes.usedThemes", "[{\"id\":\"1\",\"name\":\"Unsafe Browser\",\"headerURL\":\"file:///usr/share/pixmaps/red_dot.png\",\"footerURL\":\"file:///usr/share/pixmaps/red_dot.png\",\"textcolor\":\"#FFFFFF\",\"accentcolor\":\"#CC0000\",\"updateDate\":0,\"installDate\":0}]");
EOF
    else
        # The camouflage activation script requires a dbus server for
        # properly configuring GNOME, so we start one in the chroot
148
        chroot ${CHROOT} sudo -H -u ${BROWSER_USER} sh -c 'eval `dbus-launch --auto-syntax`; tails-activate-win8-theme' || :
149
150
    fi

151
152
}

153
154
155
show_shutdown_notification () {
    local title="`gettext \"Shutting down the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, and you may not restart the Unsafe Browser until it is properly shut down.\"`"
156
    tails-notify-user "${title}" "${body}" 10000
157
158
}

159
160
161
162
163
maybe_restart_tor () {
    # Restart Tor if it's not working (a captive portal may have prevented
    # Tor from bootstrapping, and a restart is the fastest way to get
    # wheels turning)
    if ! tor_is_working; then
164
        echo "* Restarting Tor"
165
166
        restart-tor
        if ! service tor status >/dev/null; then
167
168
            error "`gettext \"Failed to restart Tor.\"`"
        fi
169
170
    fi
}
171

172
173
174
175
176
177
# Prevent multiple instances of the script.
exec 9>${LOCK}
if ! flock -x -n 9; then
    error "`gettext \"Another Unsafe Browser is currently running, or being cleaned up. Please retry in a while.\"`"
fi

178
# Get the DNS servers that was obtained from NetworkManager, if any...
179
180
181
182
183
184
185
186
NM_ENV=/var/lib/NetworkManager/env
if [ -r "${NM_ENV}" ]; then
    . ${NM_ENV}
fi
# ... otherwise fail.
# FIXME: Or would it make sense to fallback to Google's DNS or OpenDNS?
# Some stupid captive portals may allow DNS to any host, but chances are
# that only the portal's DNS would forward to the login page.
187
if [ -z "${IP4_NAMESERVERS}" ]; then
Tails developers's avatar
Tails developers committed
188
    error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
189
190
fi

191
verify_start
192
show_start_notification
193
194
195
echo "* Setting up chroot"
setup_browser_chroot ${CHROOT} ${COW} || \
    error "`gettext \"Failed to setup chroot.\"`"
196
configure_chroot
197
echo "* Starting Unsafe Browser"
198
run_chroot_browser ${CHROOT} ${BROWSER_USER} ${SUDO_USER}
199
show_shutdown_notification
200
maybe_restart_tor
201
202

exit 0