コード例 #1
0
    def content(cls, attr=None, exclude=(), sign=False, signing_key=None):
        base_header = (
            ('extra-info',
             '%s %s' % (_random_nickname(), _random_fingerprint())),
            ('published', _random_date()),
        )

        if signing_key:
            sign = True

        if sign:
            if 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()

            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-signature', _random_crypto_blob('SIGNATURE')), ))
コード例 #2
0
 def content(cls: Type['stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor'], attr: Optional[Mapping[str, str]] = None, exclude: Sequence[str] = ()) -> bytes:
   return _descriptor_content(attr, exclude, (
     ('extra-info', 'ec2bridgereaac65a3 %s' % _random_fingerprint()),
     ('published', _random_date()),
   ), (
     ('router-digest', _random_fingerprint()),
   ))
コード例 #3
0
ファイル: router_status_entry.py プロジェクト: xujinjin1/stem
 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'),
     ))
コード例 #4
0
ファイル: router_status_entry.py プロジェクト: xujinjin1/stem
 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'),
     ))
コード例 #5
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', '*:*'),
   ))
コード例 #6
0
ファイル: server_descriptor.py プロジェクト: sgmenda/stem
    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')),
            ))
コード例 #7
0
ファイル: router_status_entry.py プロジェクト: elias-pap/stem
    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())), ))
コード例 #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, (
            ('extra-info', 'ec2bridgereaac65a3 %s' % _random_fingerprint()),
            ('published', _random_date()),
        ), (('router-digest', _random_fingerprint()), ))
コード例 #9
0
ファイル: router_status_entry.py プロジェクト: patrickod/stem
  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'),
    ))
コード例 #10
0
ファイル: router_status_entry.py プロジェクト: sgmenda/stem
 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())), ))
コード例 #11
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'),
    ))
コード例 #12
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, (
      ('extra-info', 'ec2bridgereaac65a3 %s' % _random_fingerprint()),
      ('published', _random_date()),
    ), (
      ('router-digest', _random_fingerprint()),
    ))
コード例 #13
0
ファイル: server_descriptor.py プロジェクト: elias-pap/stem
  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', '*:*'),
    ))
コード例 #14
0
ファイル: server_descriptor.py プロジェクト: patrickod/stem
  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', '*:*'),
    ))
コード例 #15
0
ファイル: router_status_entry.py プロジェクト: sgmenda/stem
 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'),
     ))
コード例 #16
0
ファイル: server_descriptor.py プロジェクト: sgmenda/stem
 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', '*:*'),
     ))
コード例 #17
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')),
            ))
コード例 #18
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, (
      ('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')),
    ))
コード例 #19
0
  def content(cls: Type['stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor'], attr: Optional[Mapping[str, str]] = None, exclude: Sequence[str] = (), sign: bool = False, signing_key: Optional['stem.descriptor.SigningKey'] = None) -> bytes:
    base_header = (
      ('extra-info', '%s %s' % (_random_nickname(), _random_fingerprint())),
      ('published', _random_date()),
    )

    if sign or signing_key:
      if 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()

      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-signature', _random_crypto_blob('SIGNATURE')),
      ))
コード例 #20
0
  def content(cls, attr = None, exclude = (), sign = False, signing_key = None):
    base_header = (
      ('extra-info', '%s %s' % (_random_nickname(), _random_fingerprint())),
      ('published', _random_date()),
    )

    if signing_key:
      sign = True

    if sign:
      if 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()

      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-signature', _random_crypto_blob('SIGNATURE')),
      ))
コード例 #21
0
ファイル: server_descriptor.py プロジェクト: patrickod/stem
  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')),
      ))
コード例 #22
0
 def content(cls, attr=None, exclude=()):
     return _descriptor_content(attr, exclude, (
         ('extra-info', 'ec2bridgereaac65a3 %s' % _random_fingerprint()),
         ('published', _random_date()),
     ), (('router-digest', _random_fingerprint()), ))
コード例 #23
0
ファイル: router_status_entry.py プロジェクト: patrickod/stem
  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'),
    ))