[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] stem: disable pad connections
commit 2bcdef17a8629216f43353618837059251b60b8b
Author: juga0 <juga@xxxxxxxxxx>
Date: Fri Dec 14 22:42:59 2018 +0000
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
---
sbws/globals.py | 16 +++++++++++++++-
sbws/util/stem.py | 23 +++++++++++++++++++++--
tests/integration/util/test_stem.py | 8 ++++++++
3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/sbws/globals.py b/sbws/globals.py
index c6adc44..8c66b79 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -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')
diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 359e020..6eb37e2 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -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(),
diff --git a/tests/integration/util/test_stem.py b/tests/integration/util/test_stem.py
index 51a425a..e5492d6 100644
--- a/tests/integration/util/test_stem.py
+++ b/tests/integration/util/test_stem.py
@@ -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
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits