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

On Windows 10 unable to open cookie auth file from utf8 encoded directory #57

Closed
HelloZeroNet opened this issue Feb 19, 2020 · 1 comment

Comments

@HelloZeroNet
Copy link

Stem version: 1.8.0
Python version: 3.7.3
Tor: 0.4.2.6 (git-971a6beff5a53434) running on Windows 8 [or later] with Libevent 2.1.8-stable, OpenSSL 1.1.1d, Zlib 1.2.11, Liblzma N/A, and Libzstd N/A.

Traceback (most recent call last):
  File "C:\Drive-E\Web\Today\ZeroNet-win-dist-win64 árvíztűrő tükörfúrógép\ZeroNet-win-dist-win64\test2.py", line 20, in <module>
    controller.authenticate()
  File "C:\Python3\lib\site-packages\stem\control.py", line 1112, in authenticate
    stem.connection.authenticate(self, *args, **kwargs)
  File "C:\Python3\lib\site-packages\stem\connection.py", line 534, in authenticate
    protocolinfo_response = get_protocolinfo(controller)
  File "C:\Python3\lib\site-packages\stem\connection.py", line 1029, in get_protocolinfo
    stem.response.convert('PROTOCOLINFO', protocolinfo_response)
  File "C:\Python3\lib\site-packages\stem\response\__init__.py", line 124, in convert
    message._parse_message(**kwargs)
  File "C:\Python3\lib\site-packages\stem\response\protocolinfo.py", line 110, in _parse_message
    self.cookie_path = line.pop_mapping(True, True, get_bytes = True)[1].decode(sys.getfilesystemencoding())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 44: invalid continuation byte

Starting tor.exe:

@ c:\Drive-E\Web\Today\ZeroNet-win-dist-win64 árvíztűrő tükörfúrógép\ZeroNet-win-dist-win64\core\tools\tor
$ tor.exe -f torrc --defaults-torrc torrc-defaults --ignore-missing-torrc

torrc-defaults file:

DataDirectory data
HiddenServiceStatistics 0
GeoIPFile geoip\geoip
GeoIPv6File geoip\geoip6

ControlPort 49051
SOCKSPort 49050

CookieAuthentication 1

Script:

import stem
import stem.connection

from stem.control import Controller

controller = Controller.from_port(port=49051)
controller.authenticate()

PROTOCOLINFO result:

import socket

conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

conn.connect(("127.0.0.1", 49051))

conn.sendall(b"PROTOCOLINFO\r\n")
print(conn.recv(1024 * 64).decode("utf8"))
250-PROTOCOLINFO 1

250-AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE="c:\\Drive-E\\Web\\Today\\ZeroNet-win-dist-win64 \341rv\355zt\373r\365 t\374k\366rf\372r\363g\351p\\ZeroNet-win-dist-win64\\core\\tools\\tor\\data\\control_auth_cookie"

250-VERSION Tor="0.4.2.6"

250 OK
ghost pushed a commit that referenced this issue Aug 22, 2020
When a PROTOCOLINFO's authentication cookie path mismatches our filesystem
encoding falling back to a couple common encodings (unicode and latin-1).

  #57
@atagar
Copy link
Contributor

atagar commented Aug 22, 2020

Hi ZeroNet, sorry for taking so long to get to this. The problem is that your filesystem is configured as unicode whereas that path is latin-1. For example, the first non-ascii character is an 'a' with an umlaut...

>>> b"\341".decode('utf-8')  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 0: unexpected end of data

>>> b"\341".decode('latin-1')
'á'

I just pushed a patch so we attempt to parse these paths as both unicode and latin-1 when our filesystem encoding doesn't work.

Thanks for pointing this out!

@atagar atagar closed this as completed Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants