Example #1
0
 def content(cls, attr=None, exclude=()):
     return _descriptor_content(attr, exclude, (
         ('r', '%s ARIJF2zbqirB9IwsW0mQznccWww %s %s 9001 9030' %
          (_random_nickname(), _random_date(), _random_ipv4_address())),
         ('m', 'aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70'),
         ('s', 'Fast Guard HSDir Named Running Stable V2Dir Valid'),
     ))
Example #2
0
 def content(cls, attr=None, exclude=()):
     return _descriptor_content(attr, exclude, (
         ('r',
          '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0'
          % (_random_nickname(), _random_date(), _random_ipv4_address())),
         ('s', 'Fast Named Running Stable Valid'),
     ))
Example #3
0
 def content(cls, attr = None, exclude = ()):
   return _descriptor_content(attr, exclude, (
     ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
     ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'),
     ('published', _random_date()),
     ('bandwidth', '409600 819200 5120'),
     ('reject', '*:*'),
   ))
Example #4
0
    def content(
            cls: Type['stem.descriptor.server_descriptor.RelayDescriptor'],
            attr: Optional[Mapping[str, str]] = None,
            exclude: Sequence[str] = (),
            sign: bool = False,
            signing_key: Optional['stem.descriptor.SigningKey'] = None,
            exit_policy: Optional['stem.exit_policy.ExitPolicy'] = None
    ) -> bytes:
        attr = dict(attr) if attr else {}

        if exit_policy is None:
            exit_policy = REJECT_ALL_POLICY

        base_header = [
            ('router', '%s %s 9001 0 0' %
             (_random_nickname(), _random_ipv4_address())),
            ('published', _random_date()),
            ('bandwidth', '153600 256000 104590'),
        ] + [
            tuple(line.split(' ', 1))
            for line in str(exit_policy).splitlines()  # type: ignore
        ] + [
            ('onion-key', _random_crypto_blob('RSA PUBLIC KEY')),
            ('signing-key', _random_crypto_blob('RSA PUBLIC KEY')),
        ]

        if sign or signing_key:
            if attr and 'signing-key' in attr:
                raise ValueError(
                    'Cannot sign the descriptor if a signing-key has been provided'
                )
            elif attr and 'router-signature' in attr:
                raise ValueError(
                    'Cannot sign the descriptor if a router-signature has been provided'
                )

            if signing_key is None:
                signing_key = create_signing_key()

            if 'fingerprint' not in attr:
                fingerprint = hashlib.sha1(
                    _bytes_for_block(
                        stem.util.str_tools._to_unicode(
                            signing_key.public_digest.strip()))).hexdigest(
                            ).upper()
                attr['fingerprint'] = ' '.join(
                    stem.util.str_tools._split_by_length(fingerprint, 4))

            attr['signing-key'] = signing_key.public_digest

            content = _descriptor_content(
                attr, exclude, base_header) + b'\nrouter-signature\n'
            return _append_router_signature(content, signing_key.private)
        else:
            return _descriptor_content(attr, exclude, base_header, (
                ('router-sig-ed25519', None),
                ('router-signature', _random_crypto_blob('SIGNATURE')),
            ))
Example #5
0
 def content(
     cls: Type['stem.descriptor.router_status_entry.RouterStatusEntryV2'],
     attr: Optional[Mapping[str, str]] = None,
     exclude: Sequence[str] = ()
 ) -> bytes:
     return _descriptor_content(attr, exclude, ((
         'r',
         '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0'
         % (_random_nickname(), _random_date(), _random_ipv4_address())), ))
Example #6
0
    def content(cls, attr=None, exclude=(), sign=False):
        if sign:
            raise NotImplementedError('Signing of %s not implemented' %
                                      cls.__name__)

        return _descriptor_content(attr, exclude, ((
            'r',
            '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0'
            % (_random_nickname(), _random_date(), _random_ipv4_address())), ))
Example #7
0
    def content(cls, attr=None, exclude=(), sign=False):
        if sign:
            raise NotImplementedError('Signing of %s not implemented' %
                                      cls.__name__)

        return _descriptor_content(attr, exclude, (
            ('r', '%s ARIJF2zbqirB9IwsW0mQznccWww %s %s 9001 9030' %
             (_random_nickname(), _random_date(), _random_ipv4_address())),
            ('m', 'aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70'),
            ('s', 'Fast Guard HSDir Named Running Stable V2Dir Valid'),
        ))
Example #8
0
  def content(cls, attr = None, exclude = (), sign = False):
    if sign:
      raise NotImplementedError('Signing of %s not implemented' % cls.__name__)

    return _descriptor_content(attr, exclude, (
      ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
      ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'),
      ('published', _random_date()),
      ('bandwidth', '409600 819200 5120'),
      ('reject', '*:*'),
    ))
Example #9
0
  def content(cls, attr = None, exclude = (), sign = False):
    if sign:
      raise NotImplementedError('Signing of %s not implemented' % cls.__name__)

    return _descriptor_content(attr, exclude, (
      ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
      ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'),
      ('published', _random_date()),
      ('bandwidth', '409600 819200 5120'),
      ('reject', '*:*'),
    ))
Example #10
0
 def content(
     cls: Type[
         'stem.descriptor.router_status_entry.RouterStatusEntryMicroV3'],
     attr: Optional[Mapping[str, str]] = None,
     exclude: Sequence[str] = ()
 ) -> bytes:
     return _descriptor_content(attr, exclude, (
         ('r', '%s ARIJF2zbqirB9IwsW0mQznccWww %s %s 9001 9030' %
          (_random_nickname(), _random_date(), _random_ipv4_address())),
         ('m', 'aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70'),
         ('s', 'Fast Guard HSDir Named Running Stable V2Dir Valid'),
     ))
Example #11
0
 def content(
     cls: Type['stem.descriptor.server_descriptor.BridgeDescriptor'],
     attr: Optional[Mapping[str, str]] = None,
     exclude: Sequence[str] = ()
 ) -> bytes:
     return _descriptor_content(attr, exclude, (
         ('router', '%s %s 9001 0 0' %
          (_random_nickname(), _random_ipv4_address())),
         ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'),
         ('published', _random_date()),
         ('bandwidth', '409600 819200 5120'),
         ('reject', '*:*'),
     ))
Example #12
0
    def content(cls, attr=None, exclude=(), sign=False, signing_key=None):
        if signing_key:
            sign = True

        if attr is None:
            attr = {}

        base_header = (
            ('router',
             '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
            ('published', _random_date()),
            ('bandwidth', '153600 256000 104590'),
            ('reject', '*:*'),
            ('onion-key', _random_crypto_blob('RSA PUBLIC KEY')),
            ('signing-key', _random_crypto_blob('RSA PUBLIC KEY')),
        )

        if sign:
            if attr and 'signing-key' in attr:
                raise ValueError(
                    'Cannot sign the descriptor if a signing-key has been provided'
                )
            elif attr and 'router-signature' in attr:
                raise ValueError(
                    'Cannot sign the descriptor if a router-signature has been provided'
                )

            if signing_key is None:
                signing_key = create_signing_key()

            if 'fingerprint' not in attr:
                fingerprint = hashlib.sha1(
                    _bytes_for_block(
                        stem.util.str_tools._to_unicode(
                            signing_key.public_digest.strip()))).hexdigest(
                            ).upper()
                attr['fingerprint'] = ' '.join(
                    stem.util.str_tools._split_by_length(fingerprint, 4))

            attr['signing-key'] = signing_key.public_digest

            content = _descriptor_content(
                attr, exclude, base_header) + b'\nrouter-signature\n'
            return _append_router_signature(content, signing_key.private)
        else:
            return _descriptor_content(attr, exclude, base_header, (
                ('router-sig-ed25519', None),
                ('router-signature', _random_crypto_blob('SIGNATURE')),
            ))
Example #13
0
  def content(cls, attr = None, exclude = (), sign = False, signing_key = None):
    if signing_key:
      sign = True

    if attr is None:
      attr = {}

    base_header = (
      ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
      ('published', _random_date()),
      ('bandwidth', '153600 256000 104590'),
      ('reject', '*:*'),
      ('onion-key', _random_crypto_blob('RSA PUBLIC KEY')),
      ('signing-key', _random_crypto_blob('RSA PUBLIC KEY')),
    )

    if sign:
      if attr and 'signing-key' in attr:
        raise ValueError('Cannot sign the descriptor if a signing-key has been provided')
      elif attr and 'router-signature' in attr:
        raise ValueError('Cannot sign the descriptor if a router-signature has been provided')

      if signing_key is None:
        signing_key = create_signing_key()

      if 'fingerprint' not in attr:
        fingerprint = hashlib.sha1(_bytes_for_block(stem.util.str_tools._to_unicode(signing_key.public_digest.strip()))).hexdigest().upper()
        attr['fingerprint'] = ' '.join(stem.util.str_tools._split_by_length(fingerprint, 4))

      attr['signing-key'] = signing_key.public_digest

      content = _descriptor_content(attr, exclude, base_header) + b'\nrouter-signature\n'
      return _append_router_signature(content, signing_key.private)
    else:
      return _descriptor_content(attr, exclude, base_header, (
        ('router-sig-ed25519', None),
        ('router-signature', _random_crypto_blob('SIGNATURE')),
      ))
Example #14
0
  def content(cls, attr = None, exclude = (), sign = False):
    if sign:
      raise NotImplementedError('Signing of %s not implemented' % cls.__name__)

    return _descriptor_content(attr, exclude, (
      ('r', '%s ARIJF2zbqirB9IwsW0mQznccWww %s %s 9001 9030' % (_random_nickname(), _random_date(), _random_ipv4_address())),
      ('m', 'aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70'),
      ('s', 'Fast Guard HSDir Named Running Stable V2Dir Valid'),
    ))
Example #15
0
  def content(cls, attr = None, exclude = (), sign = False):
    if sign:
      raise NotImplementedError('Signing of %s not implemented' % cls.__name__)

    return _descriptor_content(attr, exclude, (
      ('r', '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0' % (_random_nickname(), _random_date(), _random_ipv4_address())),
      ('s', 'Fast Named Running Stable Valid'),
    ))