Exemple #1
0
    def __init__(self, path_node, legacy=False):
        '''
        :param bool legacy: if **True**, make a legacy link specifier.
            make an IPv4 or IPv6 link specifier otherwise according to
            the relay's public IP address.
        '''
        if legacy is True:
            self.lstype = DEF.LSTYPE_LEGACY
            self.lslen = DEF.LSLEN_LEGACY
            self.lspec = decodeMicrodescriptorIdentifier(
                                                    path_node.microdescriptor)
        else:
            address = path_node.router_status_entry.address
            addr = ipaddress.ip_address(unicode(address))
            port = path_node.router_status_entry.or_port
            if isinstance(addr, ipaddress.IPv4Address):
                self.lstype = DEF.LSTYPE_IPv4
                self.lslen = DEF.LSLEN_IPv4
            else:
                self.lstype = DEF.LSTYPE_IPv6
                self.lslen = DEF.LSLEN_IPv6

            self.lspec = addr.packed + struct.pack('!H', port)

        if len(self.lspec) != self.lslen:
            raise BadLinkSpecifier()
Exemple #2
0
 def __new__(cls, microdescriptor):
     relay_identity = decodeMicrodescriptorIdentifier(microdescriptor)
     relay_ntor_onion_key = base64.b64decode(microdescriptor.ntor_onion_key)
     secret_key = PrivateKey.generate()
     public_key = secret_key.public_key
     return super(NTorState, cls).__new__(
         cls, relay_identity, relay_ntor_onion_key, secret_key, public_key)
Exemple #3
0
 def test_decodeMicrodescriptorIdentifier_pad1(self, mock_b64d):
     md = mock.Mock()
     md.identifier = 'tes'
     ret = tools.decodeMicrodescriptorIdentifier(md)
     self.assertEqual(ret, 'ret')
     mock_b64d.assert_called_once_with('tes=')