Commit 2bcdef17 authored by juga  's avatar juga
Browse files

stem: disable pad connections

and create function to set options that can fail because they are
not supported by some Tor versions at runtime.

Fixes bug 28692. Bugfix v0.4.0
parent 6c8639d2
......@@ -8,6 +8,9 @@ from stem import __version__ as stem_version
from sbws import __version__
from collections import OrderedDict
log = logging.getLogger(__name__)
RESULT_VERSION = 4
......@@ -32,11 +35,22 @@ TORRC_STARTING_POINT = {
'LogTimeGranularity': '1',
'ProtocolWarnings': '1',
}
# Options that need to be set at runtime.
TORRC_RUNTIME_OPTIONS = {
# The scanner builds the circuits to download the data itself,
# so do not let Tor to build them.
'__DisablePredictedCircuits': '1',
# The scanner attach the streams to the circuit itself,
# so do not let Tor to attache them.
'__LeaveStreamsUnattached': '1',
}
# Options that can be set at runtime and can fail with some Tor versions
# The ones that fail will be ignored..
TORRC_OPTIONS_CAN_FAIL = OrderedDict({
# Since currently scanner anonymity is not the goal, ConnectionPadding
# is disable to do not send extra traffic
'ConnectionPadding': '0'
})
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
DEFAULT_CONFIG_PATH = os.path.join(PKG_DIR, 'config.default.ini')
......
......@@ -12,7 +12,8 @@ import copy
import logging
import os
from sbws.globals import fail_hard
from sbws.globals import TORRC_STARTING_POINT, TORRC_RUNTIME_OPTIONS
from sbws.globals import (TORRC_STARTING_POINT, TORRC_RUNTIME_OPTIONS,
TORRC_OPTIONS_CAN_FAIL)
log = logging.getLogger(__name__)
stream_building_lock = RLock()
......@@ -179,6 +180,22 @@ def set_torrc_runtime_options(controller):
log.exception(e)
exit(1)
def set_torrc_options_can_fail(controller):
"""Set options that can fail, at runtime.
They can be set at launch, but since the may fail because they are not
supported in some Tor versions, it's easier to try one by one at runtime
and ignore the ones that fail.
"""
for k, v in TORRC_OPTIONS_CAN_FAIL.items():
try:
controller.set_conf(k, v)
except InvalidArguments as error:
log.debug('Ignoring option not supported by this Tor version. %s',
error)
def launch_tor(conf):
assert isinstance(conf, ConfigParser)
os.makedirs(conf.getpath('tor', 'datadir'), mode=0o700, exist_ok=True)
......@@ -211,7 +228,9 @@ def launch_tor(conf):
fail_hard('Error trying to launch tor: %s', e)
# And return a controller to it
cont = _init_controller_socket(conf.getpath('tor', 'control_socket'))
# Set options that can fail at runtime
set_torrc_options_can_fail(cont)
# Set runtime options
set_torrc_runtime_options(cont)
log.info('Started and connected to Tor %s via %s', cont.get_version(),
......
......@@ -18,3 +18,11 @@ def test_set_torrc_runtime_invalidrequest_option_fail(persistent_launch_tor):
controller.set_conf('ControlSocket', '/tmp/dummy')
except stem_utils.InvalidRequest as e:
assert "Unable to set option" in e.message
def test_set_torrc_options_can_fail_option_fail(persistent_launch_tor):
controller = persistent_launch_tor
try:
controller.set_conf('BadOption', '0')
except stem_utils.InvalidArguments as e:
assert "Unknown option" in e.message
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