commit 1298d8fe460474703cac5598f6a4587ddd659dd3 Author: Damian Johnson atagar@torproject.org Date: Sun Sep 22 15:35:57 2019 -0700
Hex method unavailable in python 2.x
Python 3.5 added the hex() method. Prior to that binascii is used for hex conversion.
https://stackoverflow.com/questions/6624453/whats-the-correct-way-to-convert...
====================================================================== ERROR: test_for_decrypt ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/stem/test/unit/descriptor/hidden_service_v3.py", line 57, in test_for_decrypt desc._decrypt('sltib6sxkuxh2scmtuvd5w2g7pahnzkovefxpo4e4ptnkzl5kkq5h2ad.onion') File "/home/atagar/Desktop/stem/stem/descriptor/hidden_service.py", line 581, in _decrypt subcredential_bytes = stem.descriptor.hsv3_crypto.get_subcredential(identity_public_key_bytes, blinded_key_bytes) File "/home/atagar/Desktop/stem/stem/descriptor/hsv3_crypto.py", line 112, in get_subcredential print('public_identity_key: %s' % (public_identity_key.hex())) AttributeError: 'str' object has no attribute 'hex'
---------------------------------------------------------------------- --- stem/descriptor/hsv3_crypto.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/stem/descriptor/hsv3_crypto.py b/stem/descriptor/hsv3_crypto.py index a12ce52b..67ab2762 100644 --- a/stem/descriptor/hsv3_crypto.py +++ b/stem/descriptor/hsv3_crypto.py @@ -1,6 +1,6 @@ import base64 +import binascii import hashlib - import stem.prereq
# SHA3 requires Python 3.6+ *or* the pysha3 module... @@ -109,10 +109,10 @@ def get_subcredential(public_identity_key, blinded_key): credential = hashlib.sha3_256(b'%s%s' % (cred_bytes_constant, public_identity_key)).digest() subcredential = hashlib.sha3_256(b'%s%s%s' % (subcred_bytes_constant, credential, blinded_key)).digest()
- print('public_identity_key: %s' % (public_identity_key.hex())) - print('credential: %s' % (credential.hex())) - print('blinded_key: %s' % (blinded_key.hex())) - print('subcredential: %s' % (subcredential.hex())) + print('public_identity_key: %s' % (binascii.hexlify(public_identity_key))) + print('credential: %s' % (binascii.hexlify(credential))) + print('blinded_key: %s' % (binascii.hexlify(blinded_key))) + print('subcredential: %s' % (binascii.hexlify(subcredential)))
print('===')
@@ -173,8 +173,8 @@ def _ciphertext_mac_is_valid(key, salt, ciphertext, mac): my_mac = hashlib.sha3_256(my_mac_body).digest()
print('===') - print('my mac: %s' % my_mac.hex()) - print('their mac: %s' % mac.hex()) + print('my mac: %s' % binascii.hexlify(my_mac)) + print('their mac: %s' % binascii.hexlify(mac))
# Compare the two MACs return my_mac == mac @@ -198,9 +198,9 @@ def _decrypt_descriptor_layer(ciphertext_blob_b64, revision_counter, public_iden mac = ciphertext_blob[-32:]
print('encrypted blob lenth :%s' % len(ciphertext_blob)) - print('salt: %s' % salt.hex()) + print('salt: %s' % binascii.hexlify(salt)) print('ciphertext length: %s' % len(ciphertext)) - print('mac: %s' % mac.hex()) + print('mac: %s' % binascii.hexlify(mac)) print('===')
# INT_8(revision_counter) @@ -208,10 +208,10 @@ def _decrypt_descriptor_layer(ciphertext_blob_b64, revision_counter, public_iden secret_input = b'%s%s%s' % (secret_data, subcredential, rev_counter_int_8) secret_input = secret_input
- print('secret_data (%d): %s' % (len(secret_data), secret_data.hex())) - print('subcredential (%d): %s' % (len(subcredential), subcredential.hex())) - print('rev counter int 8 (%d): %s' % (len(rev_counter_int_8), rev_counter_int_8.hex())) - print('secret_input (%s): %s' % (len(secret_input), secret_input.hex())) + print('secret_data (%d): %s' % (len(secret_data), binascii.hexlify(secret_data))) + print('subcredential (%d): %s' % (len(subcredential), binascii.hexlify(subcredential))) + print('rev counter int 8 (%d): %s' % (len(rev_counter_int_8), binascii.hexlify(rev_counter_int_8))) + print('secret_input (%s): %s' % (len(secret_input), binascii.hexlify(secret_input))) print('===')
kdf = hashlib.shake_256(b'%s%s%s' % (secret_input, salt, string_constant)) @@ -221,9 +221,9 @@ def _decrypt_descriptor_layer(ciphertext_blob_b64, revision_counter, public_iden secret_iv = keys[S_KEY_LEN:S_KEY_LEN + S_IV_LEN] mac_key = keys[S_KEY_LEN + S_IV_LEN:]
- print('secret_key: %s' % secret_key.hex()) - print('secret_iv: %s' % secret_iv.hex()) - print('mac_key: %s' % mac_key.hex()) + print('secret_key: %s' % binascii.hexlify(secret_key)) + print('secret_iv: %s' % binascii.hexlify(secret_iv)) + print('mac_key: %s' % binascii.hexlify(mac_key))
# Now time to decrypt descriptor cipher = Cipher(algorithms.AES(secret_key), modes.CTR(secret_iv), default_backend())