Beispiel #1
0
    def __init__(self, nickname, fingerprint, ip, or_port, dir_port,
                 flags, version=None, digest=None, **kwargs):
        self._nickname = nickname
        if type(fingerprint) is not bytes:
            fingerprint = b64decode(fingerprint)
        self._fingerprint = fingerprint
        self._digest = b64decode(digest) if digest else None
        self._ip = ip
        self._or_port = or_port
        self._dir_port = dir_port
        self._version = version
        self._flags = flags

        self._consensus = None
        self._service_key = None
Beispiel #2
0
    def _get_intro_points(self, response, descriptor_cookie):
        intro_points_raw_base64 = HSDescriptorParser.parse(response)
        intro_points_raw = b64decode(intro_points_raw_base64)

        # Check whether it's encrypted
        if intro_points_raw[0] == AuthType.Basic or intro_points_raw[
                0] == AuthType.Stealth:
            if not descriptor_cookie:
                raise Exception(
                    'Hidden service needs descriptor_cookie for authorization')
            enc_buff = EncPointsBuffer(intro_points_raw)
            intro_points_raw = enc_buff.decrypt(descriptor_cookie)
        elif descriptor_cookie:
            logger.warning(
                "Descriptor cookie was specified but hidden service hasn't encrypted intro points"
            )

        if not intro_points_raw.startswith(b'introduction-point '):
            raise Exception('Unknown introduction point data received')

        intro_points_raw = intro_points_raw.decode()
        intro_points_info_list = IntroPointParser.parse(intro_points_raw)

        for intro_point_info in intro_points_info_list:
            router = self._info_to_router(intro_point_info)
            yield IntroductionPoint(router, self._circuit)
Beispiel #3
0
 def parse(data):
     m = __class__.regex.search(data)
     if m:
         return {k: b64decode(v) for k, v in m.groupdict().items()}
     else:
         logger.debug("Can't parse router descriptor: %r", data)
         raise Exception("Can't parse router descriptor")
Beispiel #4
0
 def _read_ml(self, lines):
     line = next(lines)
     if line != self._ml_start_line:
         raise Exception(f'Begin line for {self.keyword} not found')
     ml = ""
     for line in lines:
         if line == self._ml_end_line:
             break
         ml += line
     return b64decode(ml)
Beispiel #5
0
 def __init__(self, onion, descriptor_cookie=None, auth_type=AuthType.No):
     assert onion.endswith('.onion'), 'You must specify valid onion hostname'
     # TODO: only v2 onion
     self._onion = onion[:-6][-16:]
     self._rendezvous_cookie = os.urandom(20)
     self._descriptor_cookie = b64decode(descriptor_cookie) if descriptor_cookie else None
     self._auth_type = auth_type
     if descriptor_cookie and auth_type == AuthType.No:
         raise RuntimeError('You must specify auth type')
     if not descriptor_cookie and auth_type != AuthType.No:
         raise RuntimeError('You must specify descriptor cookie')
Beispiel #6
0
 def __init__(self,
              onion_address,
              descriptor_cookie=None,
              auth_type=AuthType.No):
     self._onion_address, self._permanent_id, self._onion_identity_pk = self._parse_onion(
         onion_address)
     self._descriptor_cookie = b64decode(
         descriptor_cookie) if descriptor_cookie else None
     self._auth_type = auth_type
     if descriptor_cookie and auth_type == AuthType.No:
         raise RuntimeError('You must specify auth type')
     if not descriptor_cookie and auth_type != AuthType.No:
         raise RuntimeError('You must specify descriptor cookie')
Beispiel #7
0
 def __init__(self,
              onion_address,
              descriptor_cookie=None,
              auth_type=AuthType.No):
     self._onion_address, self._permanent_id, onion_identity_pk = self.parse_onion(
         onion_address)
     self._onion_identity_pk = curve25519_public_from_bytes(
         onion_identity_pk) if onion_identity_pk else None
     if self._onion_identity_pk:
         raise Exception('v3 onion hidden service not supported yet')
     self._descriptor_cookie = b64decode(
         descriptor_cookie) if descriptor_cookie else None
     self._auth_type = auth_type
     if descriptor_cookie and auth_type == AuthType.No:
         raise RuntimeError('You must specify auth type')
     if not descriptor_cookie and auth_type != AuthType.No:
         raise RuntimeError('You must specify descriptor cookie')
Beispiel #8
0
 def descriptor_url(self, fingerprint):
     return '{}/{}'.format(self.descriptor_url_prefix,
                           b16encode(b64decode(fingerprint)).decode())
Beispiel #9
0
 def fingerprint(self):
     return b64decode(self._fingerprint)
Beispiel #10
0
 def _decode(d):
     for k in ('onion_key', 'service_key'):
         d[k] = b64decode(d[k])
     return d