[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Drop workaround for relative cookie paths
commit 32a37dcd211a8292c757c9da7c628939bf37555a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Jul 3 10:57:03 2017 -0700
Drop workaround for relative cookie paths
Five years ago we worked around a tor bug where PROTOCOLINFO responses could
have relative cookie paths...
https://trac.torproject.org/projects/tor/ticket/4881
https://trac.torproject.org/projects/tor/ticket/1101
This has easily been fixed long enough that we can drop this workaround. Yay,
less code!
---
stem/connection.py | 60 --------------------------------------
test/unit/response/protocolinfo.py | 35 ----------------------
2 files changed, 95 deletions(-)
diff --git a/stem/connection.py b/stem/connection.py
index db3f218..cce00bf 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -985,11 +985,6 @@ def get_protocolinfo(controller):
the tor process running on it. If the socket is already closed then it is
first reconnected.
- According to the control spec the cookie_file is an absolute path. However,
- this often is not the case (especially for the Tor Browser Bundle). If the
- path is relative then we'll make an attempt (which may not work) to correct
- this (:trac:`1101`).
-
This can authenticate to either a :class:`~stem.control.BaseController` or
:class:`~stem.socket.ControlSocket`.
@@ -1021,27 +1016,6 @@ def get_protocolinfo(controller):
raise stem.SocketError(exc)
stem.response.convert('PROTOCOLINFO', protocolinfo_response)
-
- # attempt to expand relative cookie paths
-
- if protocolinfo_response.cookie_path:
- _expand_cookie_path(protocolinfo_response, stem.util.system.pid_by_name, 'tor')
-
- # attempt to expand relative cookie paths via the control port or socket file
-
- if isinstance(controller, stem.socket.ControlSocket):
- control_socket = controller
- else:
- control_socket = controller.get_socket()
-
- if isinstance(control_socket, stem.socket.ControlPort):
- if control_socket.get_address() == '127.0.0.1':
- pid_method = stem.util.system.pid_by_port
- _expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_port())
- elif isinstance(control_socket, stem.socket.ControlSocketFile):
- pid_method = stem.util.system.pid_by_open_file
- _expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_socket_path())
-
return protocolinfo_response
@@ -1122,40 +1096,6 @@ def _read_cookie(cookie_path, is_safecookie):
raise UnreadableCookieFile(exc_msg, cookie_path, is_safecookie)
-def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg):
- """
- Attempts to expand a relative cookie path with the given pid resolver. This
- leaves the cookie_path alone if it's already absolute, **None**, or the
- system calls fail.
- """
-
- cookie_path = protocolinfo_response.cookie_path
- if cookie_path and not os.path.isabs(cookie_path):
- try:
- tor_pid = pid_resolver(pid_resolution_arg)
-
- if not tor_pid:
- raise IOError('pid lookup failed')
-
- tor_cwd = stem.util.system.cwd(tor_pid)
-
- if not tor_cwd:
- raise IOError('cwd lookup failed')
-
- cookie_path = stem.util.system.expand_path(cookie_path, tor_cwd)
- except IOError as exc:
- resolver_labels = {
- stem.util.system.pid_by_name: ' by name',
- stem.util.system.pid_by_port: ' by port',
- stem.util.system.pid_by_open_file: ' by socket file',
- }
-
- pid_resolver_label = resolver_labels.get(pid_resolver, '')
- log.debug('unable to expand relative tor cookie path%s: %s' % (pid_resolver_label, exc))
-
- protocolinfo_response.cookie_path = cookie_path
-
-
class AuthenticationFailure(Exception):
"""
Base error for authentication failures.
diff --git a/test/unit/response/protocolinfo.py b/test/unit/response/protocolinfo.py
index 9b2c9b1..ab6dd0e 100644
--- a/test/unit/response/protocolinfo.py
+++ b/test/unit/response/protocolinfo.py
@@ -2,7 +2,6 @@
Unit tests for the stem.response.protocolinfo.ProtocolInfoResponse class.
"""
-import os
import unittest
import stem.response
@@ -156,37 +155,3 @@ class TestProtocolInfoResponse(unittest.TestCase):
control_message = ControlMessage.from_str(UNICODE_COOKIE_PATH, 'PROTOCOLINFO', normalize = True)
self.assertEqual(EXPECTED_UNICODE_PATH, control_message.cookie_path)
-
- @patch('stem.util.proc.is_available', Mock(return_value = False))
- @patch('stem.util.system.is_available', Mock(return_value = True))
- def test_relative_cookie(self):
- """
- Checks an authentication cookie with a relative path where expansion both
- succeeds and fails.
- """
-
- # we need to mock both pid and cwd lookups since the general cookie
- # expanion works by...
- # - resolving the pid of the "tor" process
- # - using that to get tor's cwd
-
- def call_function(command, default):
- if command == stem.util.system.GET_PID_BY_NAME_PGREP % 'tor':
- return ['10']
- elif command == stem.util.system.GET_CWD_PWDX % 10:
- return ['10: /tmp/foo']
-
- with patch('stem.util.system.call') as call_mock:
- call_mock.side_effect = call_function
-
- control_message = ControlMessage.from_str(RELATIVE_COOKIE_PATH, 'PROTOCOLINFO', normalize = True)
- stem.connection._expand_cookie_path(control_message, stem.util.system.pid_by_name, 'tor')
-
- self.assertEqual(os.path.join('/tmp/foo', 'tor-browser_en-US', 'Data', 'control_auth_cookie'), control_message.cookie_path)
-
- # exercise cookie expansion where both calls fail (should work, just
- # leaving the path unexpanded)
-
- with patch('stem.util.system.call', Mock(return_value = None)):
- control_message = ControlMessage.from_str(RELATIVE_COOKIE_PATH, 'PROTOCOLINFO', normalize = True)
- self.assertEqual('./tor-browser_en-US/Data/control_auth_cookie', control_message.cookie_path)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits