Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exiting data over tunnels is only allowed after opt-in via settings #1325

Merged
merged 14 commits into from
Apr 20, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Tribler/Core/SessionConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ def get_tunnel_community_socks5_listen_ports(self):
path = u'tunnel_community~socks5_listen_ports~'
return [self._get_random_port(path + unicode(index)) if port < 0 else port for index, port in enumerate(ports)]

def set_tunnel_community_exitnode_enabled(self, value):
self.sessconfig.set(u'tunnel_community', u'exitnode_enabled', value)

def get_tunnel_community_exitnode_enabled(self):
""" Returns whether being an exitnode is allowed
@return Boolean. """
return self.sessconfig.get(u'tunnel_community', u'exitnode_enabled')

def get_listen_port(self):
""" Returns the current UDP/TCP listen port.
@return Port number. """
Expand Down
5 changes: 3 additions & 2 deletions Tribler/Core/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
# Version 2: as released in Tribler 4.5.0
# Version 3: cleanup unused params
# Version 4: remove swift
#
# Version 7: exitnode optin switch added

SESSDEFAULTS_VERSION = 6
SESSDEFAULTS_VERSION = 7
sessdefaults = OrderedDict()

# General Tribler settings
Expand Down Expand Up @@ -65,6 +65,7 @@
sessdefaults['tunnel_community']['optin_dialog_shown'] = False
sessdefaults['tunnel_community']['enabled'] = False
sessdefaults['tunnel_community']['socks5_listen_ports'] = [-1] * 5
sessdefaults['tunnel_community']['exitnode_enabled'] = False

# Mainline DHT settings
sessdefaults['mainline_dht'] = OrderedDict()
Expand Down
2 changes: 1 addition & 1 deletion Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def define_communities(*args):
if self.sconfig.get_tunnel_community_enabled():
keypair = dispersy.crypto.generate_key(u"curve25519")
dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair),)
settings = TunnelSettings(session.get_install_dir())
settings = TunnelSettings(session.get_install_dir(), tribler_session=session)
tunnel_kwargs = {'tribler_session': session, 'settings': settings}

self.tunnel_community = dispersy.define_auto_load(HiddenTunnelCommunity, dispersy_member, load=True,
Expand Down
38 changes: 38 additions & 0 deletions Tribler/Main/vwxGUI/settingsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ def __init__(self):
self._bandwidth_panel, self._bandwidth_id = self.__create_s3(tree_root, hsizer)
self._seeding_panel, self._seeding_id = self.__create_s4(tree_root, hsizer)
self._experimental_panel, self._experimental_id = self.__create_s5(tree_root, hsizer)
self._tunnel_panel, self._tunnel_id = self.__create_s6(tree_root, hsizer)

self._general_panel.Show(True)
self._conn_panel.Show(False)
self._bandwidth_panel.Show(False)
self._seeding_panel.Show(False)
self._experimental_panel.Show(False)
self._tunnel_panel.Show(False)

self._save_btn = wx.Button(self, wx.ID_OK, label="Save")
self._cancel_btn = wx.Button(self, wx.ID_CANCEL, label="Cancel")
Expand Down Expand Up @@ -207,6 +209,13 @@ def saveAll(self, event):
self.utility.write_config('use_webui', useWebUI)
restart = True


becomeExitNode = self._become_exitnode.IsChecked()
if becomeExitNode != scfg.get_tunnel_community_exitnode_enabled():
scfg.set_tunnel_community_exitnode_enabled(becomeExitNode)
self.saveDefaultSessionConfig(scfg)
restart = True

valwebuiport = self._webui_port.GetValue()
if valwebuiport != str(self.utility.read_config('webui_port')):
self.utility.write_config('webui_port', valwebuiport)
Expand Down Expand Up @@ -353,6 +362,11 @@ def saveDefaultDownloadConfig(self, scfg):

scfg.save(cfgfilename)


def saveDefaultSessionConfig(self, scfg):
cfgfilename = Session.get_default_config_filename(scfg.get_state_dir())
scfg.save(cfgfilename)

def moveCollectedTorrents(self, old_dir, new_dir):
def rename_or_merge(old, new, ignore=True):
if os.path.exists(old):
Expand Down Expand Up @@ -729,3 +743,27 @@ def __create_s5(self, tree_root, sizer):
self._webui_port.SetValue(str(self.utility.read_config('webui_port')))

return exp_panel, item_id


def __create_s6(self, tree_root, sizer):
exp_panel, exp_vsizer = create_section(self, sizer, "Anonimity")

item_id = self._tree_ctrl.AppendItem(tree_root, "Anonimity", data=wx.TreeItemData(exp_panel))

# Web UI
exp_s1_sizer = create_subsection(exp_panel, exp_vsizer, "Relaying", 2, 3)
self._become_exitnode = wx.CheckBox(exp_panel, label="Become an exit node")
exp_s1_sizer.Add(self._become_exitnode, 0, wx.EXPAND)

exp_s1_faq_text = wx.StaticText(
exp_panel, label="By allowing Tribler to be an exit node, it's possible to become a proxy for someone elses traffic. \nThis may cause problems in some countries.")
exp_vsizer.Add(exp_s1_faq_text, 0, wx.EXPAND | wx.TOP, 10)

# load values
state_dir = self.utility.session.get_state_dir()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't load the sessionconfig use session:

self.utility.session.get_tunnel....

cfgfilename = self.utility.session.get_default_config_filename(state_dir)
scfg = SessionStartupConfig.load(cfgfilename)
self._become_exitnode.SetValue(scfg.get_tunnel_community_exitnode_enabled())


return exp_panel, item_id
7 changes: 4 additions & 3 deletions Tribler/Test/test_tunnel_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def startTest(self, callback, min_timeout=5):
def setup_proxies():
tunnel_communities = []
for i in range(3, 7):
tunnel_communities.append(create_proxy(i))
tunnel_communities.append(create_proxy(i, i > 5))

# Connect the proxies to the Tribler instance
for community in self.lm.dispersy.get_communities():
Expand All @@ -245,7 +245,7 @@ def setup_proxies():

callback(tunnel_communities)

def create_proxy(index):
def create_proxy(index, become_exit_node):
from Tribler.Core.Session import Session

self.setUpPreSession()
Expand All @@ -269,8 +269,9 @@ def create_proxy(index):
def load_community(session):
keypair = dispersy.crypto.generate_key(u"curve25519")
dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair))
settings = TunnelSettings()
settings = TunnelSettings(tribler_session=session)
settings.do_test = False
settings.become_exitnode = True #become_exit_node

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixme

return dispersy.define_auto_load(HiddenTunnelCommunity, dispersy_member, (session, settings), load=True)[0]

return blockingCallFromThread(reactor, load_community, session)
Expand Down
20 changes: 10 additions & 10 deletions Tribler/community/tunnel/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ def _decode_cell(self, placeholder, offset, data):

def _encode_create(self, message):
payload = message.payload
packet = pack("!IHH20s", payload.circuit_id, len(payload.node_public_key),
len(payload.key), payload.node_id) + payload.node_public_key + payload.key
packet = pack("!IHH20s?", payload.circuit_id, len(payload.node_public_key),
len(payload.key), payload.node_id, payload.become_exit) + payload.node_public_key + payload.key
return packet,

def _decode_create(self, placeholder, offset, data):
circuit_id, len_pubic_key, len_key, nodeid = unpack_from('!IHH20s', data, offset)
offset += 28
circuit_id, len_pubic_key, len_key, nodeid, become_exit = unpack_from('!IHH20s?', data, offset)
offset += 29

node_public_key = data[offset: offset + len_pubic_key]
offset += len_pubic_key

key = data[offset:offset + len_key]
offset += len_key

return offset, placeholder.meta.payload.implement(circuit_id, nodeid, node_public_key, key)
return offset, placeholder.meta.payload.implement(circuit_id, nodeid, node_public_key, key, become_exit)

def _encode_created(self, message):
payload = message.payload
Expand All @@ -94,17 +94,17 @@ def _decode_created(self, placeholder, offset, data):

def _encode_extend(self, message):
payload = message.payload
packet = pack("!IHH20s", payload.circuit_id, len(payload.node_public_key), len(payload.key), payload.node_id) + \
payload.node_public_key + payload.key
packet = pack("!IHH20s?", payload.circuit_id, len(payload.node_public_key), len(payload.key),
payload.node_id, payload.become_exit) + payload.node_public_key + payload.key

if message.payload.node_addr:
host, port = message.payload.node_addr
packet += pack("!4sH", inet_aton(host), port)
return packet,

def _decode_extend(self, placeholder, offset, data):
circuit_id, len_public_key, len_key, nodeid = unpack_from('!IHH20s', data, offset)
offset += 28
circuit_id, len_public_key, len_key, nodeid, become_exit = unpack_from('!IHH20s?', data, offset)
offset += 29

node_public_key = data[offset:offset + len_public_key]
offset += len_public_key
Expand All @@ -118,7 +118,7 @@ def _decode_extend(self, placeholder, offset, data):
offset += 6
node_addr = (inet_ntoa(host), port)

return offset, placeholder.meta.payload.implement(circuit_id, nodeid, node_public_key, node_addr, key)
return offset, placeholder.meta.payload.implement(circuit_id, nodeid, node_public_key, node_addr, key, become_exit)

def _encode_extended(self, message):
payload = message.payload
Expand Down
8 changes: 8 additions & 0 deletions Tribler/community/tunnel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def main(argv):

try:
parser.add_argument('-p', '--socks5', help='Socks5 port')
parser.add_argument('-x', '--exit', help='Allow being an exit-node')
parser.add_argument('-d', '--dispersy', help='Dispersy port')
parser.add_argument('-c', '--crawl', help='Enable crawler and use the keypair specified in the given filename')
parser.add_argument('-j', '--json', help='Enable JSON api, which will run on the provided port number ' +
Expand Down Expand Up @@ -350,6 +351,13 @@ def main(argv):
settings.socks_listen_ports = range(socks5_port, socks5_port + 5)
else:
settings.socks_listen_ports = [random.randint(1000, 65535) for _ in range(5)]

settings.become_exitnode = True if args.exit in ['true'] else False
if settings.become_exitnode:
print "Exit-node enabled"
else:
print "Exit-node disabled"

settings.do_test = False
tunnel = Tunnel(settings, crawl_keypair_filename, dispersy_port)
StandardIO(LineHandler(tunnel, profile))
Expand Down
16 changes: 14 additions & 2 deletions Tribler/community/tunnel/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ class CreatePayload(Payload):

class Implementation(Payload.Implementation):

def __init__(self, meta, circuit_id, node_id, node_public_key, key):
def __init__(self, meta, circuit_id, node_id, node_public_key, key, become_exit):
assert isinstance(circuit_id, (int, long)), type(circuit_id)
assert isinstance(node_id, basestring), type(node_id)
assert isinstance(node_public_key, basestring), type(node_public_key)
assert isinstance(key, basestring), type(key)
assert isinstance(become_exit, bool), type(become_exit)

super(CreatePayload.Implementation, self).__init__(meta)
self._circuit_id = circuit_id
self._node_id = node_id
self._node_public_key = node_public_key
self._key = key
self._become_exit = become_exit

@property
def circuit_id(self):
Expand All @@ -60,6 +62,10 @@ def node_public_key(self):
def key(self):
return self._key

@property
def become_exit(self):
return self._become_exit


class CreatedPayload(Payload):

Expand Down Expand Up @@ -98,19 +104,21 @@ class ExtendPayload(Payload):

class Implementation(Payload.Implementation):

def __init__(self, meta, circuit_id, node_id, node_public_key, node_addr, key):
def __init__(self, meta, circuit_id, node_id, node_public_key, node_addr, key, become_exit):
assert isinstance(circuit_id, (int, long)), type(circuit_id)
assert isinstance(node_id, basestring), type(node_id)
assert isinstance(node_public_key, basestring), type(node_public_key)
assert node_addr == None or isinstance(node_addr, tuple), type(node_addr)
assert isinstance(key, basestring), type(key)
assert isinstance(become_exit, bool), type(become_exit)

super(ExtendPayload.Implementation, self).__init__(meta)
self._circuit_id = circuit_id
self._node_id = node_id
self._node_public_key = node_public_key
self._node_addr = node_addr
self._key = key
self._become_exit = become_exit

@property
def circuit_id(self):
Expand All @@ -132,6 +140,10 @@ def node_addr(self):
def key(self):
return self._key

@property
def become_exit(self):
return self._become_exit


class ExtendedPayload(Payload):

Expand Down
Loading