[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Python3 support for hidden service descriptor decryption
commit 378bfaf32c2eda1e22d92c6b2bce67f973af25da
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Mar 10 09:10:50 2015 -0700
Python3 support for hidden service descriptor decryption
Didn't have pycrypto for python3 so this test was being skipped for me. There
were two issues...
* we need to normalize the cookie to be bytes
* indexing into bytes provides an int in python3, so we need to use an
equivalent slice instead
Caught by toralf (on irc) and cypherpunks (on #15004).
---
stem/descriptor/hidden_service_descriptor.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/stem/descriptor/hidden_service_descriptor.py b/stem/descriptor/hidden_service_descriptor.py
index f64036d..8c3ce7d 100644
--- a/stem/descriptor/hidden_service_descriptor.py
+++ b/stem/descriptor/hidden_service_descriptor.py
@@ -28,6 +28,7 @@ import hashlib
import io
import stem.util.connection
+import stem.util.str_tools
from stem.descriptor import (
PGP_BLOCK_END,
@@ -287,11 +288,11 @@ class HiddenServiceDescriptor(Descriptor):
try:
missing_padding = len(authentication_cookie) % 4
- authentication_cookie = base64.b64decode(authentication_cookie + '=' * missing_padding)
+ authentication_cookie = base64.b64decode(stem.util.str_tools._to_bytes(authentication_cookie) + b'=' * missing_padding)
except TypeError as exc:
raise DecryptionFailure('authentication_cookie must be a base64 encoded string (%s)' % exc)
- authentication_type = int(binascii.hexlify(content[0]), 16)
+ authentication_type = int(binascii.hexlify(content[0:1]), 16)
if authentication_type == BASIC_AUTH:
content = HiddenServiceDescriptor._decrypt_basic_auth(content, authentication_cookie)
@@ -314,7 +315,7 @@ class HiddenServiceDescriptor(Descriptor):
from Crypto.Util.number import bytes_to_long
try:
- client_blocks = int(binascii.hexlify(content[1]), 16)
+ client_blocks = int(binascii.hexlify(content[1:2]), 16)
except ValueError:
raise DecryptionFailure("When using basic auth the content should start with a number of blocks but wasn't a hex digit: %s" % binascii.hexlify(content[1]))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits