1. 29 Jun, 2021 5 commits
  2. 08 Mar, 2021 1 commit
  3. 02 Feb, 2021 1 commit
    • anonym's avatar
      onion-grater: transparently recover lost tor controller connections. · e4ff28a7
      anonym authored
      If we lose the tor controller connection (most likely because tor
      restarts) we now transparently re-establishes a controller connection,
      restore the previous connection's state (only event subscriptions) so
      the client can keep on using the control port as if nothing happened.
      
      We detect a lost controller connection in two ways to cover all bases:
      
      1. We are sending a synchronous command and expect a response: this is
         very straightforward to handle, we just have to catch and handle the
         relevant (stem) exception that is thrown and retry the command.
      
      2. We have subscribed to events, which arrive asynchronously: to
         handle them we have to regularly check if the socket is still
         alive.
      
      Refs: #16993
      e4ff28a7
  4. 01 Feb, 2021 1 commit
  5. 15 Jan, 2021 3 commits
  6. 07 Oct, 2020 1 commit
  7. 09 Oct, 2019 1 commit
  8. 11 Jul, 2019 2 commits
  9. 30 May, 2019 1 commit
    • anonym's avatar
      onion-grater: retry connecting to the real control port. · f74cec4d
      anonym authored
      This should not be necessary and is just placed here as a workaround
      until I can figure out the real issue (bug in onion-grater? bug in
      stem?).
      
      When working on the Tor Browser 9.0 migration there were issues with
      Tor Launcher. It starts and does its initial connection to the control
      port where it successfully fetches CONFs etc. When clicking "Connect"
      it successfully sends a few more things and disconnects, only to
      reconnect immediately later (due to some implementation detail in Tor
      Launcher). This reconnection fails:
      
          [...]
          /usr/local/lib/tor-browser/firefox-unconfined (pid: 8865, user: tor-launcher, port: 57472, filter: tor-launcher): -> SAVECONF
          /usr/local/lib/tor-browser/firefox-unconfined (pid: 8865, user: tor-launcher, port: 57472, filter: tor-launcher) disconnected: Client closed its socket
          [ Here comes the reconnect: ]
          /usr/local/lib/tor-browser/firefox-unconfined (pid: 8865, user: tor-launcher, port: 57476, filter: tor-launcher) connected: loaded filter: tor-launcher
          Final rules: [...]
          Unable to connect to tor. Maybe it's running without a ControlPort?
          /usr/local/lib/tor-browser/firefox-unconfined (pid: 8865, user: tor-launcher, port: 57476, filter: tor-launcher) disconnected: client quit
          ----------------------------------------
          Exception happened during processing of request from ('127.0.0.1', 57476)
          Traceback (most recent call last):
            File "/usr/lib/python3.5/socketserver.py", line 625, in process_request_thread
              self.finish_request(request, client_address)
            File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
              self.RequestHandlerClass(request, client_address, self)
            File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
              self.handle()
            File "/usr/local/lib/onion-grater", line 629, in handle
              self.controller = self.connect_to_real_control_port()
            File "/usr/local/lib/onion-grater", line 570, in connect_to_real_control_port
              stem.connection.authenticate_cookie(controller, cookie_path=global_args.control_cookie_path)
            File "/usr/lib/python3/dist-packages/stem/connection.py", line 803, in authenticate_cookie
              auth_response = _msg(controller, msg)
            File "/usr/lib/python3/dist-packages/stem/connection.py", line 1055, in _msg
              return controller.msg(message)
          AttributeError: 'NoneType' object has no attribute 'msg'
          ----------------------------------------
      
      But if we just connect yet again, it works, hence the workaround.
      
      Refs: #16356, #15709
      f74cec4d
  10. 16 Oct, 2018 1 commit
    • Patrick Schleizer's avatar
      fix Tor control auth cookie authentication even if HashedControlPassword is set · fdd71c2d
      Patrick Schleizer authored
      fix custom auth cookie authentication path
      
      Previously the following line in Tor config...
      
      ```
      HashedControlPassword
      16:88A1B9F6EBD74C6960E1E60CC725B6C94A990C65223358EFF0DF41E8BA
      ```
      
      Was leading the the following error:
      
      ```
      Sep 13 22:02:08 host onion-grater[10460]: Exception happened during
      processing of request from ('10.137.0.45', 48828)
      Sep 13 22:02:08 host onion-grater[10460]: Traceback (most recent call last):
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3.5/socketserver.py", line 625, in process_request_thread
      Sep 13 22:02:08 host onion-grater[10460]:
      self.finish_request(request, client_address)
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
      Sep 13 22:02:08 host onion-grater[10460]:
      self.RequestHandlerClass(request, client_address, self)
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3.5/socketserver.py", line 681, in __init__
      Sep 13 22:02:08 host onion-grater[10460]:     self.handle()
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/onion-grater", line 651, in handle
      Sep 13 22:02:08 host onion-grater[10460]:     self.controller =
      self.connect_to_real_control_port()
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/onion-grater", line 592, in connect_to_real_control_port
      Sep 13 22:02:08 host onion-grater[10460]:
      controller.authenticate(cookie)
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3/dist-packages/stem/control.py", line 1071, in authenticate
      Sep 13 22:02:08 host onion-grater[10460]:
      stem.connection.authenticate(self, *args, **kwargs)
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3/dist-packages/stem/connection.py", line 575, in
      authenticate
      Sep 13 22:02:08 host onion-grater[10460]:
      authenticate_password(controller, password, False)
      Sep 13 22:02:08 host onion-grater[10460]:   File
      "/usr/lib/python3/dist-packages/stem/connection.py", line 711, in
      authenticate_password
      Sep 13 22:02:08 host onion-grater[10460]:     password =
      password.replace('"', '\\"')
      Sep 13 22:02:08 host onion-grater[10460]: TypeError: a bytes-like object
      is required, not 'str'
      ```
      
      ```
      ls -la /var/run/tor/
      ```
      ```
      total 148
      drwxr-sr-x  2 debian-tor debian-tor    140 Sep 13 22:15 .
      drwxr-xr-x 28 root       root          760 Sep 13 22:00 ..
      srw-rw----  1 debian-tor debian-tor      0 Sep 13 22:15 control
      -rw-r-----  1 debian-tor debian-tor     32 Sep 13 22:15 control.authcookie
      -rw-r-----  1 debian-tor debian-tor 143123 Sep 13 22:15 log
      srw-rw-rw-  1 debian-tor debian-tor      0 Sep 13 22:15 socks
      -rw-r--r--  1 debian-tor debian-tor      6 Sep 13 22:15 tor.pid
      ```
      ```
      DataDirectory /var/lib/tor
      PidFile /var/run/tor/tor.pid
      RunAsDaemon 1
      User debian-tor
      
      ControlSocket /var/run/tor/control GroupWritable RelaxDirModeCheck
      ControlSocketsGroupWritable 1
      SocksPort unix:/var/run/tor/socks WorldWritable
      SocksPort 9050
      
      CookieAuthentication 1
      CookieAuthFileGroupReadable 1
      CookieAuthFile /var/run/tor/control.authcookie
      
      Log notice file /var/log/tor/log
      ```
      
      The HashedControlPassword confused python-stem even
      though cookie authentication was functional without that HashedControlPassword.
      
      There is no need to manually read Tor authentication cookie file.
      
              with open(global_args.control_cookie_path, "rb") as f:
                  cookie = f.read()
      
      python-stem can do that for us.
      
      Line
      
      ```
      controller.authenticate(cookie)
      ```
      
      was wrong. `controller.authenticate` does not take
      
      Syntax from manual:
      
      https://stem.torproject.org/api/connection.html#stem.connection.authenticate
      
      ```
      stem.connection.authenticate(controller, password=None, chroot_path=None, protocolinfo_response=None)
      ```
      fdd71c2d
  11. 27 Jun, 2018 1 commit
  12. 29 Mar, 2018 1 commit
  13. 20 Mar, 2017 2 commits
  14. 16 Mar, 2017 1 commit
  15. 25 Jan, 2017 3 commits
  16. 10 Jan, 2017 2 commits
  17. 09 Jan, 2017 1 commit
  18. 29 Dec, 2016 1 commit
  19. 28 Dec, 2016 1 commit
  20. 11 Dec, 2016 2 commits
  21. 09 Dec, 2016 3 commits
  22. 08 Dec, 2016 5 commits