[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Converting cookie auth token to unicode
commit 2b2a645ac778570d99961f9b9592769fdc9caa10
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Feb 1 07:48:21 2013 -0800
Converting cookie auth token to unicode
Well, this is dumb. Making a formatted string with ascii bytes includes the b''
wrapper in python 3. This broke our authentication calls, making calls like...
AUTHENTICATE b'd55e81eb9c3a1e22a2db919ec2efd22df4aeb88ee0ab3d10e64dbb2450d06921'
Converting the token to unicode to avoid this.
======================================================================
ERROR: test_authenticate_cookie
----------------------------------------------------------------------
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/connection/authentication.py", line 400, in _check_auth
stem.connection.authenticate_cookie(control_socket, auth_arg)
File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 604, in authenticate_cookie
raise CookieAuthRejected(str(auth_response), cookie_path, False, auth_response)
stem.connection.CookieAuthRejected: Invalid hexadecimal encoding. Maybe you tried a plain text password? If so, the standard requires that you put it in double quotes.
During handling of the above exception, another exception occurred:
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/connection/authentication.py", line 303, in test_authenticate_cookie
self._check_auth(auth_type, auth_value)
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/connection/authentication.py", line 411, in _check_auth
failure_msg = _get_auth_failure_message(auth_type)
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/connection/authentication.py", line 99, in _get_auth_failure_message
raise ValueError("No methods of authentication. If this is an open socket then auth shouldn't fail.")
ValueError: No methods of authentication. If this is an open socket then auth shouldn't fail.
---
stem/connection.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/stem/connection.py b/stem/connection.py
index 1a72399..a581c99 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -583,7 +583,18 @@ def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
cookie_data = _read_cookie(cookie_path, False)
try:
- msg = "AUTHENTICATE %s" % binascii.b2a_hex(stem.util.str_tools.to_bytes(cookie_data))
+ # binascii.b2a_hex() takes a byte string and returns one too. With python 3
+ # this is a problem because string formatting for byte strings includes the
+ # b'' wrapper...
+ #
+ # >>> "AUTHENTICATE %s" % b'content'
+ # "AUTHENTICATE b'content'"
+ #
+ # This seems dumb but oh well. Converting the result to unicode so it won't
+ # misbehave.
+
+ auth_token_hex = binascii.b2a_hex(stem.util.str_tools.to_bytes(cookie_data))
+ msg = "AUTHENTICATE %s" % stem.util.str_tools.to_unicode(auth_token_hex)
auth_response = _msg(controller, msg)
# if we got anything but an OK response then error
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits