1 **********************************************************
2 BridgeDB |Latest Version| |Build Status| |Coverage 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 .. |Latest Version| image:: https://pypip.in/version/bridgedb/badge.svg?style=flat
11 :target: https://pypi.python.org/pypi/bridgedb/
12 .. |Build Status| image:: https://travis-ci.org/sysrqbci/bridgedb.svg
13 :target: https://travis-ci.org/sysrqbci/bridgedb
14 .. |Coverage Status| image:: https://coveralls.io/repos/github/sysrqbci/bridgedb/badge.svg?branch=develop
15 :target: https://coveralls.io/github/sysrqbci/bridgedb?branch=develop
19 .. image:: doc/sphinx/source/_static/bay-bridge.jpg
32 `Tor Bridges <https://www.torproject.org/docs/bridges>`__ are special
33 Tor relays which are not listed in the public relay directory. They are
34 used to help circumvent `censorship <https://ooni.torproject.org>`__ by
35 providing users with connections to the public relays in the Tor
38 Tor Bridges are different from normal relays in another important way:
39 they can run what are called *Pluggable* *Transports*.
41 -----------------------------
42 What's a Pluggable Transport?
43 -----------------------------
46 Transport <https://www.torproject.org/docs/pluggable-transports.html.en>`__
47 is a program which is *pluggable* — meaning that it is meant to work
48 with lots of other anonymity and censorship circumvention software, not
49 just Tor — and is a *transport* — meaning that it transports your
50 internet traffic, usually in a way which makes it look different. For
52 `Obfsproxy <https://www.torproject.org/projects/obfsproxy.html.en>`__ is
53 a Pluggable Transport which disguises your traffic by adding an
54 obfuscating layer of encryption.
60 Well, probably, you don't. But if you're looking for bridges, you can
61 use `the web interface <https://bridges.torproject.org>`__ of the
62 BridgeDB instance deployed by the Tor Project, which has instructions on
63 getting the Pluggable Transports-capable Tor Browser Bundle, as well as
64 instructions for getting extra Bridges.
71 If you'd like to hack on BridgeDB, you might wish to read BridgeDB's
72 `developer documentation <https://pythonhosted.org/bridgedb/>`__. The rest of
73 this document mainly concerns mainenance and installation instructions.
75 -----------------------------
76 Dependencies and installation
77 -----------------------------
79 BridgeDB requires the following OS-level dependencies:
83 - `python3-dkim <https://pypi.org/project/dkimpy/>`__ (it contains the ``dkimverify`` binary)
86 - `SQLite3 <http://www.maxmind.com/app/python>`__
87 - `MaxMind GeoIP <https://www.maxmind.com/en/geolocation_landing>`__
90 - `python-setuptools <https://pypi.python.org/pypi/setuptools>`__
92 - `flog <https://packages.debian.org/jessie/flog>`__ (only required if bridgedb
93 is invocated with the ``run-bridgedb`` `script
94 <https://gitweb.torproject.org/project/bridges/bridgedb-admin.git/tree/bin/run-bridgedb>`__)
96 As well as any Python dependencies in the ``requirements.txt`` file.
98 .. note: There are additional dependencies for things like running the test
99 suites, building BridgeDB's developer documentation, etc. Read on for more
100 info if you wish to enable addition features.
107 BridgeDB should work with or without a Python virtualenv.
109 - Install Python 2.7, and other OS-level dependencies. On Debian, you
112 sudo apt-get install build-essential openssl python python-dev \
113 python-setuptools sqlite3 libgeoip-dev geoip-database
116 - Install Pip 1.3.1 or later. Debian has this version, but if for some
117 reason that or a newer version isn't available, the easiest way to
118 install a newer Pip is to use the Pip development teams's `getpip
119 script <https://raw.github.com/pypa/pip/master/contrib/get-pip.py>`__::
121 wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
122 sudo python get-pip.py
125 - **(virtualenv installs only)** Use Pip to install virtualenv and
126 `virtualenvwrapper <https://virtualenvwrapper.readthedocs.org>`__::
128 sudo pip install --upgrade virtualenv virtualenvwrapper
131 - **(virtualenv installs only)** Configure virtualenvwrapper and create a
132 virtualenv for BridgeDB::
134 WORKON_HOME=${HOME}/.virtualenvs
136 mkdir -p $WORKON_HOME
137 source $(which virtualenvwrapper.sh)
138 git clone https://git.torproject.org/bridgedb.git && cd bridgedb
139 mkvirtualenv -a $PWD -r requirements.txt --unzip-setuptools --setuptools bridgedb
141 From now on, to use BridgeDB's virtualenv, just do ``$ workon bridgedb``
142 (after sourcing virtualenvwrapper.sh, as before). To exit the virtualenv
143 without exiting the shell, do ``$ deactivate``.
146 - **(virtualenv installs only)** To install, set PYTHONPATH to include the
147 root directory of the virtualenv::
149 export PYTHONPATH=$PYTHONPATH:${VIRTUAL_ENV}/lib/python2.7/site-packages
152 - Then, proceed as usual::
154 python setup.py install --record installed-files.txt
157 ============================
158 Enabling additional features
159 ============================
165 For general information on the translation process, take a look at
166 `our translation guidelines for developers
167 <https://trac.torproject.org/projects/tor/wiki/doc/translation/developers>`__.
169 **Using New Translations**:
171 This should be done when newly completed translations are available in
174 Piece of cake. Running ``maint/get-completed-translations`` will take
175 care of cloning *only* the ``bridgedb_completed`` branch of Tor's
176 `translations repo <https://gitweb.torproject.org/translation.git>`__
177 and placing all the updated files in their correct locations.
181 **Requesting Translations for Altered/Added Source Code**:
183 This should be done whenever any of the strings requiring translation --
184 ``_("the ones inside the weird underscore function, like this")`` -- are
185 changed, or new ones are added. See ``lib/bridgedb/strings.py``.
187 Translations for Tor Project repos are kept `in a separate repo
188 <https://gitweb.torproject.org/translation.git>`__. To request new or updated
189 translations, you'll need to extract the strings from BridgeDB's source code
190 into our ./i18n/templates/bridgedb.pot template, and then commit it to our
191 ``develop`` branch. From there, the translation system takes over and
192 eventually, new translations will be available. To extract all strings from
193 BridgeDB's source, run::
195 python setup.py extract_messages
197 Transifex uses the resulting file ./i18n/templates/bridgedb.pot (and this file
198 only) as input and fetches it from BridgeDB's ``develop`` branch, so we don't
199 need to release a new BridgeDB version (which we only do in the ``master``
200 branch) to request translations.
208 Create a self-signed certificate with::
210 scripts/make-ssl-cert
212 Or, place an existing certificate in the path specified in bridgedb.conf
213 by the ``HTTPS_CERT_FILE`` option, and a private key where
214 ``HTTPS_KEY_FILE`` points to. The defaults are 'cert' and 'privkey.pem',
218 ------------------------
219 Enabling CAPTCHA Support
220 ------------------------
222 BridgeDB has two ways to use CAPTCHAs on webpages. The first uses reCaptcha_,
223 an external Google service (this requires an account with them), which
224 BridgeDB fetches the CAPTCHAs images from for each incoming request from a
225 client. The second method uses a local cache of pre-made CAPTCHAs, created by
226 scripting Gimp using gimp-captcha_. The latter cannot easily be run on
227 headless server, unfortunately, because Gimp requires an X server to be
230 .. _reCaptcha: https://www.google.com/recaptcha
231 .. _gimp-captcha: https://github.com/isislovecruft/gimp-captcha
236 To enable fetching CAPTCHAs from the reCaptcha API server, set these
237 options in bridgedb.conf::
247 To enable using a local cache of CAPTCHAs, set the following options::
251 GIMP_CAPTCHA_HMAC_KEYFILE
252 GIMP_CAPTCHA_RSA_KEYFILE
257 ----------------------------------------------------------
258 Preventing already-blocked bridges from being distributed:
259 ----------------------------------------------------------
261 Uncomment or add ``COUNTRY_BLOCK_FILE`` to your bridgedb.conf. This file
262 should contain one bridge entry per line, in the format::
264 fingerprint <bridge fingerprint> country-code <country code>
266 If the ``COUNTRY_BLOCK_FILE`` file is present, bridgedb will filter
267 blocked bridges from the responses it gives to clients requesting
275 Before running to any of BridgeDB's test suites, make sure you have the
276 additional dependencies in the Pip requirements file,
277 ``.test.requirements.txt`` installed::
279 pip install -r .test.requirements.txt
281 To create a bunch of fake bridge descriptors to test BridgeDB, do::
283 bridgedb mock [-n NUMBER_OF_DESCRIPTORS]
285 To run the test suites, do::
289 If you just want to run the tests, and don't care about code coverage
290 statistics, see the ``bridgedb trial`` and ``bridgedb test`` commands.
297 To run BridgeDB, simply make any necessary changes to bridgedb.conf, and do::
301 And remember that all files/directories in ``bridgedb.conf`` are assumed
302 relative to the runtime directory. By default, BridgeDB uses the current
303 working directory; you can, however specify an a different runtime
306 bridgedb -r /srv/bridges.torproject.org/run
308 Make sure that the files and directories referred to in bridgedb.conf
309 exist. However, many of them, if not found, will be touched on disk so
310 that attempts to read/write from/to them will not raise excessive
314 ----------------------------------------------
315 Reloading Bridges From Their Descriptor Files:
316 ----------------------------------------------
318 When you have new lists of bridges from the Bridge Authority, replace
319 the old files and do::
323 Or just give it a SIGHUP::
325 kill -s SIGHUP `cat .../run/bridgedb.pid`
328 =========================
329 Using a BridgeDB Instance
330 =========================
332 Obviously, you'll have to feed it bridge descriptor files from a
333 BridgeAuthority. There's currently only one BridgeAuthority in the entire
334 world, but Tor Project is, of course, very interested in adding support for
335 multiple BridgeAuthorities so that we can scale our own network, and make it
336 easier for individual and organisations who wish to run a lot of Tor bridge
337 relays have an easier time distributing those bridges themselves (if they wish
338 to do so). If you'd like to fund our work on this, please contact
339 tor-dev@lists.torproject.org!
341 ----------------------------------
342 Accessing the HTTPS User Interface
343 ----------------------------------
345 Just connect to the appropriate port. (See the ``HTTPS_PORT`` and
346 ``HTTP_UNENCRYPTED_PORT`` options in the ``bridgedb.conf`` file.)
348 The HTTPS interface for our BridgeDB instance can be found `here
349 <https://bridges.torproject.org>`__.
352 ----------------------------------
353 Accessing the Email User Interface
354 ----------------------------------
356 Any mail sent to the ``EMAIL_PORT`` with a destination username as defined by
357 the ``EMAIL_USERNAME`` configuration option (the default is ``'bridge'``, e.g.
358 bridges@...) and sent from an ``@riseup.net`` or ``@gmail.com`` address (by
359 default, but configurable with the ``EMAIL_DOMAINS`` option).
361 You can email our BridgeDB instance `here <mailto:bridges@torproject.org>`__.
364 ----------------------------
365 Accessing the Moat Interface
366 ----------------------------
368 Moat is a bridge distributor for requesting bridges through `Tor Launcher's
369 <https://gitweb.torproject.org/tor-launcher.git/>`__ user interface.
371 The following describes the Moat API, version 0.1.0.
373 The client and server both MUST conform to `JSON-API <http://jsonapi.org/>`__.
375 The client SHOULD direct all requests via the Meek reflector at ``MEEK_REFECTOR``.
377 XXX meek reflector URL
382 The client MUST send a ``POST /moat/fetch`` containing the following JSON::
387 "type": "client-transports",
388 "supported": [ "TRANSPORT", "TRANSPORT", ... ],
394 * ``TRANSPORT`` is a string identifying a transport, e.g. ``"obfs3"`` or
395 ``"obfs4"``. Currently supported transport identifiers are:
403 Receiving a CAPTCHA challenge
404 """""""""""""""""""""""""""""
406 The moat server will respond with ``200 OK``.
408 If there is an overlap with what BridgeDB supports, the moat server will select
409 the "best" transport from the list of supported transports, and respond with the
410 following JSON containing a CAPTCHA challenge::
415 "type": "moat-challenge",
417 "transport": "TRANSPORT",
419 "challenge": "CHALLENGE",
425 * ``TRANSPORT`` is the agreed upon transport which will be distributed,
426 * ``CAPTCHA`` is a base64-encoded, jpeg image that is 400 pixels in
427 length and 125 pixels in height,
428 * ``CHALLENGE`` is a base64-encoded CAPTCHA challenge which MUST be
429 later passed back to the server along with the proposed solution.
431 The challenge contains an encrypted-then-HMACed timestamp, and
432 solutions submitted more than 30 minutes after requesting the CAPTCHA
433 are considered invalid.
435 If there is no overlap with the transports which BridgeDB supports, the moat
436 server will respond with the list of transports which is *does* support::
441 "type": "moat-challenge",
443 "transport": [ "TRANSPORT", "TRANSPORT", ... ],
445 "challenge": "CHALLENGE",
450 Responding to a CAPTCHA challenge
451 """""""""""""""""""""""""""""""""
453 To propose a solution to a CAPTCHA, the client MUST send a request for ``POST
454 /moat/check``, where the body of the request contains the following JSON::
459 "type": "moat-solution",
461 "transport": "TRANSPORT",
462 "challenge": "CHALLENGE",
463 "solution": "SOLUTION",
471 * ``TRANSPORT`` is the agreed upon transport which will be distributed,
472 * ``CHALLENGE`` is a base64-encoded CAPTCHA challenge which MUST be
473 later passed back to the server along with the proposed solution.
474 * ``SOLUTION`` is a valid unicode string, up to 20 bytes in length,
475 containing the client's answer (i.e. what characters the CAPTCHA
476 image displayed). The solution is *not* case-sensitive.
477 * ``BOOLEAN`` is ``"true"`` if the client wants a qrcode containing the bridge
478 lines to be generated and returned; ``"false"`` otherwise.
484 If the ``CHALLENGE`` has already timed out, or if the ``SOLUTION`` was
485 incorrect, the server SHOULD respond with ``419 No You're A Teapot``.
487 If the ``SOLUTION`` was successful for the supplied ``CHALLENGE``, the
488 server responds ``200 OK`` with the following JSON::
493 "type": "moat-bridges",
495 "bridges": [ "BRIDGE_LINE", ... ],
502 * ``BRIDGE_LINE`` is a bridge line suitable for configuration in a torrc,
503 * ``QRCODE`` is a base64-encoded jpeg image of a QRCode containing all the
504 ``BRIDGE_LINE``, if one was requested, otherwise this field will be ``NaN``.
507 XXX do we care to differentiate the errors for "unable to distribute
508 bridges"? are any of these useful to Tor Launcher?
510 If the ``SOLUTION`` was successful for the supplied ``CHALLENGE``, but the
511 server is unable to distribute the requested Bridges, the server responds ``200
512 OK`` with the following JSON::
517 "type": "moat-bridges",
520 "status": "Not Found",
527 * ``DETAILS`` is some string describing the detailed nature of the issue.
533 If the client requested some page other than ``/moat/fetch``, or
534 ``/moat/check``, the server MUST respond with ``501 Not Implemented``.
536 If the client attempts any other HTTP method, other than ``POST``, the server
537 MUST respond ``403 FORBIDDEN``.
544 Send your questions, patches, and suggestions to
545 `the tor-dev mailing list <mailto:tor-dev@lists.torproject.org>`__, or to
546 `Philipp Winter <mailto:phw@torproject.org>`__.