commit 1a7040063df5cd4ec030f3498ea3601e44e92e69 Author: Damian Johnson atagar@torproject.org Date: Tue Oct 15 13:46:15 2019 -0700
Move get_subcredential() into HiddenServiceDescriptorV3
I'm not entirely sure yet if we need a helper for this, but for the moment moving it alongside _public_key_from_address(). --- stem/descriptor/hidden_service.py | 13 ++++++++++--- stem/descriptor/hsv3_crypto.py | 18 ------------------ 2 files changed, 10 insertions(+), 21 deletions(-)
diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py index 9885fe7a..daae516b 100644 --- a/stem/descriptor/hidden_service.py +++ b/stem/descriptor/hidden_service.py @@ -1003,7 +1003,7 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
# Get the main encrypted descriptor body revision_counter_int = int(time.time()) - subcredential = hsv3_crypto.get_subcredential(public_identity_key_bytes, blinded_pubkey_bytes) + subcredential = HiddenServiceDescriptorV3._subcredential(public_identity_key_bytes, blinded_pubkey_bytes)
# XXX It would be more elegant to have all the above variables attached to # this descriptor object so that we don't have to carry them around @@ -1099,8 +1099,7 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor): raise ValueError('No signing key is present')
identity_public_key = HiddenServiceDescriptorV3._public_key_from_address(onion_address) - - subcredential = hsv3_crypto.get_subcredential(identity_public_key, blinded_key) + subcredential = HiddenServiceDescriptorV3._subcredential(identity_public_key, blinded_key)
outer_layer = OuterLayer._decrypt(self.superencrypted, self.revision_counter, subcredential, blinded_key) self._inner_layer = InnerLayer._decrypt(outer_layer, self.revision_counter, subcredential, blinded_key) @@ -1136,6 +1135,14 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
return pubkey
+ @staticmethod + def _subcredential(public_key, blinded_key): + # credential = H('credential' | public-identity-key) + # subcredential = H('subcredential' | credential | blinded-public-key) + + credential = hashlib.sha3_256(b'credential%s' % public_key).digest() + return hashlib.sha3_256(b'subcredential%s%s' % (credential, blinded_key)).digest() +
class OuterLayer(Descriptor): """ diff --git a/stem/descriptor/hsv3_crypto.py b/stem/descriptor/hsv3_crypto.py index 71f76e9c..2b99f030 100644 --- a/stem/descriptor/hsv3_crypto.py +++ b/stem/descriptor/hsv3_crypto.py @@ -75,24 +75,6 @@ class HSv3PublicBlindedKey(object):
""" -subcredential - - subcredential = H("subcredential" | credential | blinded-public-ke - credential = H("credential" | public-identity-key) -""" - - -def get_subcredential(public_identity_key, blinded_key): - cred_bytes_constant = 'credential'.encode() - subcred_bytes_constant = 'subcredential'.encode() - - 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() - - return subcredential - - -""" Onion address
onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"