commit 1986f7dfbd9f4281e4c7165041b0e0137f31a74e Author: Damian Johnson atagar@torproject.org Date: Sat Jul 1 12:15:04 2017 -0700
Randomize created hidden service descriptor fields --- stem/descriptor/hidden_service_descriptor.py | 29 ++++++++++------------- test/unit/descriptor/hidden_service_descriptor.py | 3 --- 2 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/stem/descriptor/hidden_service_descriptor.py b/stem/descriptor/hidden_service_descriptor.py index f9a5e35..c78c9f0 100644 --- a/stem/descriptor/hidden_service_descriptor.py +++ b/stem/descriptor/hidden_service_descriptor.py @@ -31,7 +31,6 @@ import stem.util.connection import stem.util.str_tools
from stem.descriptor import ( - CRYPTO_BLOB, PGP_BLOCK_END, Descriptor, _descriptor_content, @@ -42,6 +41,8 @@ from stem.descriptor import ( _parse_simple_line, _parse_timestamp_line, _parse_key_block, + _random_date, + _random_crypto_blob, )
try: @@ -82,20 +83,6 @@ SINGLE_INTRODUCTION_POINT_FIELDS = [ BASIC_AUTH = 1 STEALTH_AUTH = 2
-HIDDEN_SERVICE_HEADER = ( - ('rendezvous-service-descriptor', 'y3olqqblqw2gbh6phimfuiroechjjafa'), - ('version', '2'), - ('permanent-key', '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----' % CRYPTO_BLOB), - ('secret-id-part', 'e24kgecavwsznj7gpbktqsiwgvngsf4e'), - ('publication-time', '2015-02-23 20:00:00'), - ('protocol-versions', '2,3'), - ('introduction-points', '\n-----BEGIN MESSAGE-----\n-----END MESSAGE-----'), -) - -HIDDEN_SERVICE_FOOTER = ( - ('signature', '\n-----BEGIN SIGNATURE-----%s-----END SIGNATURE-----' % CRYPTO_BLOB), -) -
class IntroductionPoints(collections.namedtuple('IntroductionPoints', INTRODUCTION_POINTS_ATTR.keys())): """ @@ -255,7 +242,17 @@ class HiddenServiceDescriptor(Descriptor): if sign: raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
- return _descriptor_content(attr, exclude, sign, HIDDEN_SERVICE_HEADER, HIDDEN_SERVICE_FOOTER) + return _descriptor_content(attr, exclude, sign, ( + ('rendezvous-service-descriptor', 'y3olqqblqw2gbh6phimfuiroechjjafa'), + ('version', '2'), + ('permanent-key', _random_crypto_blob('RSA PUBLIC KEY')), + ('secret-id-part', 'e24kgecavwsznj7gpbktqsiwgvngsf4e'), + ('publication-time', _random_date()), + ('protocol-versions', '2,3'), + ('introduction-points', '\n-----BEGIN MESSAGE-----\n-----END MESSAGE-----'), + ), ( + ('signature', _random_crypto_blob('SIGNATURE')), + ))
@classmethod def create(cls, attr = None, exclude = (), validate = True, sign = False): diff --git a/test/unit/descriptor/hidden_service_descriptor.py b/test/unit/descriptor/hidden_service_descriptor.py index 09d8de5..1e8c135 100644 --- a/test/unit/descriptor/hidden_service_descriptor.py +++ b/test/unit/descriptor/hidden_service_descriptor.py @@ -418,14 +418,11 @@ class TestHiddenServiceDescriptor(unittest.TestCase):
self.assertEqual('y3olqqblqw2gbh6phimfuiroechjjafa', desc.descriptor_id) self.assertEqual(2, desc.version) - self.assertTrue(stem.descriptor.CRYPTO_BLOB in desc.permanent_key) self.assertEqual('e24kgecavwsznj7gpbktqsiwgvngsf4e', desc.secret_id_part) - self.assertEqual(datetime.datetime(2015, 2, 23, 20, 0, 0), desc.published) self.assertEqual([2, 3], desc.protocol_versions) self.assertEqual('-----BEGIN MESSAGE-----\n-----END MESSAGE-----', desc.introduction_points_encoded) self.assertEqual([], desc.introduction_points_auth) self.assertEqual(b'', desc.introduction_points_content) - self.assertTrue(stem.descriptor.CRYPTO_BLOB in desc.signature) self.assertEqual([], desc.introduction_points())
def test_unrecognized_line(self):
tor-commits@lists.torproject.org