Merge branch 'release-0.11.0'
[tor-bridgedb.git] / README.rst
bloba06c2cdd7772cfe7b2aafa4781eedb1a4913d7cf
1 ***********************
2 BridgeDB |Build Status|
3 ***********************
5 BridgeDB is a collection of backend servers used to distribute `Tor Bridges
6 <https://www.torproject.org/docs/bridges>`__. Currently, it mainly consists of
7 a webserver with `an HTTPS interface <https://bridges.torproject.org>`__,
8 `an email responder <mailto:bridges@torproject.org>`__, and an SQLite database.
10 .. |Build Status| image:: https://travis-ci.org/NullHypothesis/bridgedb.svg?branch=master
11    :target: https://travis-ci.org/github/NullHypothesis/bridgedb
13 .. image:: doc/sphinx/source/_static/bay-bridge.jpg
14    :scale: 80%
15    :align: center
18 .. contents::
19    :backlinks: entry
22 =====================
23 What are Tor Bridges?
24 =====================
26 `Tor Bridges <https://www.torproject.org/docs/bridges>`__ are special
27 Tor relays which are not listed in the public relay directory. They are
28 used to help circumvent `censorship <https://ooni.torproject.org>`__ by
29 providing users with connections to the public relays in the Tor
30 network.
32 Tor Bridges are different from normal relays in another important way:
33 they can run what are called *Pluggable* *Transports*.
35 -----------------------------
36 What's a Pluggable Transport?
37 -----------------------------
39 A `Pluggable
40 Transport <https://www.torproject.org/docs/pluggable-transports.html.en>`__
41 is a program which is *pluggable* — meaning that it is meant to work
42 with lots of other anonymity and censorship circumvention software, not
43 just Tor — and is a *transport* — meaning that it transports your
44 internet traffic, usually in a way which makes it look different. For
45 example,
46 `Obfsproxy <https://www.torproject.org/projects/obfsproxy.html.en>`__ is
47 a Pluggable Transport which disguises your traffic by adding an
48 obfuscating layer of encryption.
50 ---------------------
51 So how do I use this?
52 ---------------------
54 Well, probably, you don't. But if you're looking for bridges, you can
55 use `the web interface <https://bridges.torproject.org>`__ of the
56 BridgeDB instance deployed by the Tor Project, which has instructions on
57 getting the Pluggable Transports-capable Tor Browser Bundle, as well as
58 instructions for getting extra Bridges.
61 ================
62 Maintainer Setup
63 ================
65 If you'd like to hack on BridgeDB, you might wish to read BridgeDB's
66 `developer documentation <https://pythonhosted.org/bridgedb/>`__.  The rest of
67 this document mainly concerns mainenance and installation instructions.
69 -----------------------------
70 Dependencies and installation
71 -----------------------------
73 BridgeDB requires the following OS-level dependencies:
75 -  python>=3
76 -  python3-dev
77 -  `python3-dkim <https://pypi.org/project/dkimpy/>`__ (it contains the ``dkimverify`` binary)
78 -  build-essential
79 -  OpenSSL>=1.0.1g
80 -  `SQLite3 <http://www.maxmind.com/app/python>`__
81 -  `MaxMind GeoIP <https://www.maxmind.com/en/geolocation_landing>`__
82 -  libgeoip-dev
83 -  geoip-database
84 -  `python-setuptools <https://pypi.python.org/pypi/setuptools>`__
85 -  libjpeg-dev
86 -  `flog <https://packages.debian.org/jessie/flog>`__ (only required if bridgedb
87    is invocated with the ``run-bridgedb`` `script
88    <https://gitweb.torproject.org/project/bridges/bridgedb-admin.git/tree/bin/run-bridgedb>`__)
90 As well as any Python dependencies in the ``requirements.txt`` file.
92 .. note: There are additional dependencies for things like running the test
93     suites, building BridgeDB's developer documentation, etc. Read on for more
94     info if you wish to enable addition features.
97 ------------------
98 Deploying BridgeDB
99 ------------------
101 BridgeDB should work with or without a Python virtualenv.
103 -  Install Python 3, and other OS-level dependencies. On Debian, you
104    can do::
106          sudo apt-get install build-essential openssl python3 python3-dev \
107            python3-setuptools sqlite3 gnupg2 libgeoip-dev geoip-database
110 -  Install Pip 1.3.1 or later. Debian has this version, but if for some
111    reason that or a newer version isn't available, the easiest way to
112    install a newer Pip is to use the Pip development teams's `getpip
113    script <https://raw.github.com/pypa/pip/master/contrib/get-pip.py>`__::
115          wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
116          sudo python get-pip.py
119 -  **(virtualenv installs only)** Use Pip to install virtualenv and
120    `virtualenvwrapper <https://virtualenvwrapper.readthedocs.org>`__::
122          sudo pip install --upgrade virtualenv virtualenvwrapper
125 -  **(virtualenv installs only)** Configure virtualenvwrapper and create a
126    virtualenv for BridgeDB::
128          WORKON_HOME=${HOME}/.virtualenvs
129          export WORKON_HOME
130          mkdir -p $WORKON_HOME
131          source $(which virtualenvwrapper.sh)
132          git clone https://git.torproject.org/bridgedb.git && cd bridgedb
133          mkvirtualenv -a $PWD -r requirements.txt --unzip-setuptools --setuptools bridgedb
135    From now on, to use BridgeDB's virtualenv, just do ``$ workon bridgedb``
136    (after sourcing virtualenvwrapper.sh, as before). To exit the virtualenv
137    without exiting the shell, do ``$ deactivate``.
140 -  **(virtualenv installs only)** To install, set PYTHONPATH to include the
141    root directory of the virtualenv::
143          export PYTHONPATH=$PYTHONPATH:${VIRTUAL_ENV}/lib/python3.7/site-packages
146 -  Then, proceed as usual::
148          python setup.py install --record installed-files.txt
151 ============================
152 Enabling additional features
153 ============================
155 ------------
156 Translations
157 ------------
159 For general information on the translation process, take a look at
160 `our translation guidelines for developers
161 <https://trac.torproject.org/projects/tor/wiki/doc/translation/developers>`__.
163 **Using New Translations**:
165 This should be done when newly completed translations are available in
166 Transifex.
168 Piece of cake. Running ``maint/get-completed-translations`` will take
169 care of cloning *only* the ``bridgedb_completed`` branch of Tor's
170 `translations repo <https://gitweb.torproject.org/translation.git>`__
171 and placing all the updated files in their correct locations.
173 -------
175 **Requesting Translations for Altered/Added Source Code**:
177 This should be done whenever any of the strings requiring translation --
178 ``_("the ones inside the weird underscore function, like this")`` -- are
179 changed, or new ones are added. See ``lib/bridgedb/strings.py``.
181 Translations for Tor Project repos are kept `in a separate repo
182 <https://gitweb.torproject.org/translation.git>`__. To request new or updated
183 translations, you'll need to extract the strings from BridgeDB's source code
184 into our ./i18n/templates/bridgedb.pot template, and then commit it to our
185 ``develop`` branch.  From there, the translation system takes over and
186 eventually, new translations will be available.  To extract all strings from
187 BridgeDB's source, run::
189          python setup.py extract_messages
191 Transifex uses the resulting file ./i18n/templates/bridgedb.pot (and this file
192 only) as input and fetches it from BridgeDB's ``develop`` branch, so we don't
193 need to release a new BridgeDB version (which we only do in the ``master``
194 branch) to request translations.
196 -------
198 --------------
199 Enabling HTTPS
200 --------------
202 Create a self-signed certificate with::
204          scripts/make-ssl-cert
206 Or, place an existing certificate in the path specified in bridgedb.conf
207 by the ``HTTPS_CERT_FILE`` option, and a private key where
208 ``HTTPS_KEY_FILE`` points to. The defaults are 'cert' and 'privkey.pem',
209 respectively.
212 ------------------------
213 Enabling CAPTCHA Support
214 ------------------------
216 BridgeDB has two ways to use CAPTCHAs on webpages. The first uses reCaptcha_,
217 an external Google service (this requires an account with them), which
218 BridgeDB fetches the CAPTCHAs images from for each incoming request from a
219 client. The second method uses a local cache of pre-made CAPTCHAs, created by
220 scripting Gimp using gimp-captcha_. The latter cannot easily be run on
221 headless server, unfortunately, because Gimp requires an X server to be
222 installed.
224 .. _reCaptcha: https://www.google.com/recaptcha
225 .. _gimp-captcha: https://github.com/isislovecruft/gimp-captcha
228 **reCaptcha**
230 To enable fetching CAPTCHAs from the reCaptcha API server, set these
231 options in bridgedb.conf::
233       RECAPTCHA_ENABLED
234       RECAPTCHA_PUB_KEY
235       RECAPTCHA_SEC_KEY
237 -------
239 **gimp-captcha**
241 To enable using a local cache of CAPTCHAs, set the following options::
243       GIMP_CAPTCHA_ENABLED
244       GIMP_CAPTCHA_DIR
245       GIMP_CAPTCHA_HMAC_KEYFILE
246       GIMP_CAPTCHA_RSA_KEYFILE
248 -------
251 ----------------------------------------------------------
252 Preventing already-blocked bridges from being distributed:
253 ----------------------------------------------------------
255 Uncomment or add ``COUNTRY_BLOCK_FILE`` to your bridgedb.conf. This file
256 should contain one bridge entry per line, in the format::
258       fingerprint <bridge fingerprint> country-code <country code>
260 If the ``COUNTRY_BLOCK_FILE`` file is present, bridgedb will filter
261 blocked bridges from the responses it gives to clients requesting
262 bridges.
265 ================
266 Testing BridgeDB
267 ================
269 Before running to any of BridgeDB's test suites, make sure you have the
270 additional dependencies in the Pip requirements file,
271 ``.test.requirements.txt`` installed::
273       pip install -r .test.requirements.txt
275 To create a bunch of fake bridge descriptors to test BridgeDB, do::
277       bridgedb mock [-n NUMBER_OF_DESCRIPTORS]
279 To run the test suites, do::
281       make coverage
283 If you just want to run the tests, and don't care about code coverage
284 statistics, see the ``bridgedb trial`` and ``bridgedb test`` commands.
287 ================
288 Running BridgeDB
289 ================
291 To run BridgeDB, simply make any necessary changes to bridgedb.conf, and do::
293       bridgedb
295 And remember that all files/directories in ``bridgedb.conf`` are assumed
296 relative to the runtime directory. By default, BridgeDB uses the current
297 working directory; you can, however specify an a different runtime
298 directory::
300       bridgedb -r /srv/bridges.torproject.org/run
302 Make sure that the files and directories referred to in bridgedb.conf
303 exist. However, many of them, if not found, will be touched on disk so
304 that attempts to read/write from/to them will not raise excessive
305 errors.
308 ----------------------------------------------
309 Reloading Bridges From Their Descriptor Files:
310 ----------------------------------------------
312 When you have new lists of bridges from the Bridge Authority, replace
313 the old files and do::
315       kill -s SIGHUP `cat .../run/bridgedb.pid`
318 =========================
319 Using a BridgeDB Instance
320 =========================
322 Obviously, you'll have to feed it bridge descriptor files from a
323 BridgeAuthority. There's currently only one BridgeAuthority in the entire
324 world, but Tor Project is, of course, very interested in adding support for
325 multiple BridgeAuthorities so that we can scale our own network, and make it
326 easier for individual and organisations who wish to run a lot of Tor bridge
327 relays have an easier time distributing those bridges themselves (if they wish
328 to do so). If you'd like to fund our work on this, please contact
329 tor-dev@lists.torproject.org!
331 ----------------------------------
332 Accessing the HTTPS User Interface
333 ----------------------------------
335 Just connect to the appropriate port. (See the ``HTTPS_PORT`` and
336 ``HTTP_UNENCRYPTED_PORT`` options in the ``bridgedb.conf`` file.)
338 The HTTPS interface for our BridgeDB instance can be found `here
339 <https://bridges.torproject.org>`__.
342 ----------------------------------
343 Accessing the Email User Interface
344 ----------------------------------
346 Any mail sent to the ``EMAIL_PORT`` with a destination username as defined by
347 the ``EMAIL_USERNAME`` configuration option (the default is ``'bridge'``, e.g.
348 bridges@...) and sent from an ``@riseup.net`` or ``@gmail.com`` address (by
349 default, but configurable with the ``EMAIL_DOMAINS`` option).
351 You can email our BridgeDB instance `here <mailto:bridges@torproject.org>`__.
354 ----------------------------
355 Accessing the Moat Interface
356 ----------------------------
358 Moat is a bridge distributor for requesting bridges through `Tor Launcher's
359 <https://gitweb.torproject.org/tor-launcher.git/>`__ user interface.
361 The following describes the Moat API, version 0.1.0.
363 The client and server both MUST conform to `JSON-API <http://jsonapi.org/>`__.
365 The client SHOULD direct all requests via the Meek reflector at ``MEEK_REFECTOR``.
367    XXX meek reflector URL
369 Requesting Bridges
370 """"""""""""""""""
372 The client MUST send a ``POST /moat/fetch`` containing the following JSON::
374     {
375       "data": [{
376         "version": "0.1.0",
377         "type": "client-transports",
378         "supported": [ "TRANSPORT", "TRANSPORT", ... ],
379       }]
380     }
382 where:
384 * ``TRANSPORT`` is a string identifying a transport, e.g. ``"obfs3"`` or
385   ``"obfs4"``.  Currently supported transport identifiers are:
386   - ``"vanilla"``
387   - ``"fte"``
388   - ``"obfs3"``
389   - ``"obfs4"``
390   - ``"scramblesuit"``
393 Receiving a CAPTCHA challenge
394 """""""""""""""""""""""""""""
396 The moat server will respond with ``200 OK``.
398 If there is an overlap with what BridgeDB supports, the moat server will select
399 the "best" transport from the list of supported transports, and respond with the
400 following JSON containing a CAPTCHA challenge::
402     {
403       "data": [{
404         "id": "1",
405         "type": "moat-challenge",
406         "version": "0.1.0",
407         "transport": "TRANSPORT",
408         "image": "CAPTCHA",
409         "challenge": "CHALLENGE",
410       }]
411     }
413 where:
415 * ``TRANSPORT`` is the agreed upon transport which will be distributed,
416 * ``CAPTCHA`` is a base64-encoded, jpeg image that is 400 pixels in
417   length and 125 pixels in height,
418 * ``CHALLENGE`` is a base64-encoded CAPTCHA challenge which MUST be
419   later passed back to the server along with the proposed solution.
421 The challenge contains an encrypted-then-HMACed timestamp, and
422 solutions submitted more than 30 minutes after requesting the CAPTCHA
423 are considered invalid.
425 If there is no overlap with the transports which BridgeDB supports, the moat
426 server will respond with the list of transports which is *does* support::
428     {
429       "data": [{
430         "id": "1",
431         "type": "moat-challenge",
432         "version": "0.1.0",
433         "transport": [ "TRANSPORT", "TRANSPORT", ... ],
434         "image": "CAPTCHA",
435         "challenge": "CHALLENGE",
436       }]
437     }
440 Responding to a CAPTCHA challenge
441 """""""""""""""""""""""""""""""""
443 To propose a solution to a CAPTCHA, the client MUST send a request for ``POST
444 /moat/check``, where the body of the request contains the following JSON::
446     {
447       "data": [{
448         "id": "2",
449         "type": "moat-solution",
450         "version": "0.1.0",
451         "transport": "TRANSPORT",
452         "challenge": "CHALLENGE",
453         "solution": "SOLUTION",
454         "qrcode": "BOOLEAN",
455       }]
456     }
459 where:
461 * ``TRANSPORT`` is the agreed upon transport which will be distributed,
462 * ``CHALLENGE`` is a base64-encoded CAPTCHA challenge which MUST be
463   later passed back to the server along with the proposed solution.
464 * ``SOLUTION`` is a valid unicode string, up to 20 bytes in length,
465   containing the client's answer (i.e. what characters the CAPTCHA
466   image displayed).  The solution is *not* case-sensitive.
467 * ``BOOLEAN`` is ``"true"`` if the client wants a qrcode containing the bridge
468   lines to be generated and returned; ``"false"`` otherwise.
471 Receiving Bridges
472 """""""""""""""""
474 If the ``CHALLENGE`` has already timed out, or if the ``SOLUTION`` was
475 incorrect, the server SHOULD respond with ``419 No You're A Teapot``.
477 If the ``SOLUTION`` was successful for the supplied ``CHALLENGE``, the
478 server responds ``200 OK`` with the following JSON::
480     {
481       "data": [{
482         "id": "3",
483         "type": "moat-bridges",
484         "version": "0.1.0",
485         "bridges": [ "BRIDGE_LINE", ... ],
486         "qrcode": "QRCODE",
487       }]
488     }
490 where:
492 * ``BRIDGE_LINE`` is a bridge line suitable for configuration in a torrc,
493 * ``QRCODE`` is a base64-encoded jpeg image of a QRCode containing all the
494   ``BRIDGE_LINE``, if one was requested, otherwise this field will be ``NaN``.
497     XXX do we care to differentiate the errors for "unable to distribute
498         bridges"? are any of these useful to Tor Launcher?
500 If the ``SOLUTION`` was successful for the supplied ``CHALLENGE``, but the
501 server is unable to distribute the requested Bridges, the server responds ``200
502 OK`` with the following JSON::
504     {
505       "errors": [{
506         "id": "6",
507         "type": "moat-bridges",
508         "version": "0.1.0",
509         "code": "404",
510         "status": "Not Found",
511         "detail": "DETAILS",
512       }]
513     }
515 where:
517 * ``DETAILS`` is some string describing the detailed nature of the issue.
520 Other Responses
521 """""""""""""""
523 If the client requested some page other than ``/moat/fetch``, or
524 ``/moat/check``, the server MUST respond with ``501 Not Implemented``.
526 If the client attempts any other HTTP method, other than ``POST``, the server
527 MUST respond ``403 FORBIDDEN``.
530 =================
531 Contact & Support
532 =================
534 Send your questions, patches, and suggestions to
535 `the tor-dev mailing list <mailto:tor-dev@lists.torproject.org>`__, or to
536 `Philipp Winter <mailto:phw@torproject.org>`__.