Пример #1
0
    def test_neighbor_closeness_random(self):
        onions = []
        p = subprocess.Popen(["scripts/generate-onions.py", '100'],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        for line in iter(p.stdout.readline, b''):
            line = line.decode()
            onions.append(line.strip())
        p.terminate()
        main = '7uifxsgidchopmdwmtip6x4ydra6cpf2ov4ghj2lzx5uydyssduh5qid.onion'
        main_num = int.from_bytes(extract_ed25519_from_onion_address(main),
                                  'big')

        test_data = identify_neighbors(main, onions, 100)

        my_result = []
        for i in onions:
            my_result.append(
                (i,
                 abs(main_num - int.from_bytes(
                     extract_ed25519_from_onion_address(i), 'big'))))
        my_result.sort(key=lambda p: p[1])

        final = []
        for i in my_result:
            final.append(i[0])
        self.assertListEqual(final, test_data)
Пример #2
0
 def test_fail_length_onion(self):
     hardcodedCorrect = b'y\xbc\xc6%\x18K\x05\x19Iu\xc2\x8bf\xb6k\x04i\xf7\xf6Uo\xb1\xac1\x89\xa7\x9b@\xdd\xa3/\x1f'
     correct = b32decode(b'pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd'.upper())[:-3]
     self.assertEqual(correct, hardcodedCorrect)
     try:
         extract_ed25519_from_onion_address(b'pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscry.onion')
     except binascii.Error:
         pass
Пример #3
0
    def test_neighbor_closeness_consistent(self):
        main = '7uifxsgidchopmdwmtip6x4ydra6cpf2ov4ghj2lzx5uydyssduh5qid.onion'
        others = [
            'bxxajpimlonmbxb5jzjre3go3dvfobqyayqwpksd6zpjz4s4mknstwyd.onion',
            '2zofaifd6s3flwbv5wl4vtgnesbprc4f2ptljl4a47dfkvrbmw3e5iqd.onion',
            '6umslj7jtzu27n4jgf3byn55ztz5mkoqocx32zwjya6rbnxqjpyysyyd.onion'
        ]
        main_num = int.from_bytes(extract_ed25519_from_onion_address(main),
                                  'big')

        test_data = identify_neighbors(main, others, 3)

        my_result = []
        for i in others:
            my_result.append(
                (i,
                 abs(main_num - int.from_bytes(
                     extract_ed25519_from_onion_address(i), 'big'))))
        my_result.sort(key=lambda p: p[1])

        final = []
        for i in my_result:
            final.append(i[0])
        self.assertListEqual(final, test_data)
Пример #4
0
 def test_extract_no_ext_bytes(self):
     hardcodedCorrect = b'y\xbc\xc6%\x18K\x05\x19Iu\xc2\x8bf\xb6k\x04i\xf7\xf6Uo\xb1\xac1\x89\xa7\x9b@\xdd\xa3/\x1f'
     correct = b32decode(b'pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd'.upper())[:-3]
     self.assertEqual(correct, hardcodedCorrect)
     self.assertEqual(correct, extract_ed25519_from_onion_address(b'pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd'))