示例#1
0
    def test_is_onion_address(self):
        self.assertEqual(
            onion.is_onion_address('httpo://thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address('thirteenchars123.onion'),
                         True)

        self.assertEqual(
            onion.is_onion_address('http://thirteenchars123.onion'), True)

        self.assertEqual(
            onion.is_onion_address('https://thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address('http://thirteenchars123.com'),
                         False)
示例#2
0
    def test_is_onion_address(self):
        self.assertEqual(onion.is_onion_address(
            'httpo://thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address(
            'thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address(
            'http://thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address(
            'https://thirteenchars123.onion'), True)

        self.assertEqual(onion.is_onion_address(
            'http://thirteenchars123.com'), False)
示例#3
0
def guess_backend_type(address):
    if address is None:
        raise e.InvalidAddress
    if onion.is_onion_address(address):
        return 'onion'
    elif address.startswith('https://'):
        return 'https'
    elif address.startswith('http://'):
        return 'http'
    else:
        raise e.InvalidAddress
示例#4
0
def guess_backend_type(address):
    if address is None:
        raise e.InvalidAddress
    if onion.is_onion_address(address):
        return 'onion'
    elif address.startswith('https://'):
        return 'https'
    elif address.startswith('http://'):
        return 'http'
    else:
        raise e.InvalidAddress
示例#5
0
 def _guessBackendType(self):
     if self.base_address is None:
         raise e.InvalidAddress
     if onion.is_onion_address(self.base_address):
         self.backend_type = 'onion'
     elif self.base_address.startswith('https://'):
         self.backend_type = 'https'
     elif self.base_address.startswith('http://'):
         self.backend_type = 'http'
     else:
         raise e.InvalidAddress
示例#6
0
 def _setupBaseAddress(self):
     parsed_address = urlparse(self.base_address)
     if self.backend_type == 'onion':
         if not onion.is_onion_address(self.base_address):
             log.err("Invalid onion address.")
             raise e.InvalidAddress(self.base_address)
         if parsed_address.scheme in ('http', 'httpo'):
             self.base_address = ("http://%s" % parsed_address.netloc)
         else:
             self.base_address = ("%s://%s" % (parsed_address.scheme,
                                               parsed_address.netloc))
     elif self.backend_type == 'http':
         self.base_address = ("http://%s" % parsed_address.netloc)
     elif self.backend_type in ('https', 'cloudfront'):
         self.base_address = ("https://%s" % parsed_address.netloc)
     self.base_address = self.base_address.encode('ascii')
示例#7
0
 def _setupBaseAddress(self):
     parsed_address = urlparse(self.base_address)
     if self.backend_type == 'onion':
         if not onion.is_onion_address(self.base_address):
             log.err("Invalid onion address.")
             raise e.InvalidAddress(self.base_address)
         if parsed_address.scheme in ('http', 'httpo'):
             self.base_address = ("http://%s" % parsed_address.netloc)
         else:
             self.base_address = (
                 "%s://%s" % (parsed_address.scheme, parsed_address.netloc))
     elif self.backend_type == 'http':
         self.base_address = ("http://%s" % parsed_address.netloc)
     elif self.backend_type == 'https':
         self.base_address = ("https://%s" % parsed_address.netloc)
     elif self.backend_type == 'cloudfront':
         self.base_headers['Host'] = [parsed_address.netloc]
         self.base_address = ("https://%s" % self.front)
     self.base_address = self.base_address.encode('ascii')
示例#8
0
文件: deck.py 项目: irl/ooni-probe
    def sortAddressesByPriority(self, priority_address, alternate_addresses):
        onion_addresses= []
        cloudfront_addresses= []
        https_addresses = []
        plaintext_addresses = []

        if onion.is_onion_address(priority_address):
            priority_address = {
                'address': priority_address,
                'type': 'onion'
            }
        elif priority_address.startswith('https://'):
            priority_address = {
                'address': priority_address,
                'type': 'https'
            }
        elif priority_address.startswith('http://'):
            priority_address = {
                'address': priority_address,
                'type': 'http'
            }
        else:
            raise e.InvalidOONIBCollectorAddress

        def filter_by_type(collectors, collector_type):
            return filter(lambda x: x['type'] == collector_type,
                          collectors)
        onion_addresses += filter_by_type(alternate_addresses, 'onion')
        https_addresses += filter_by_type(alternate_addresses, 'https')
        cloudfront_addresses += filter_by_type(alternate_addresses,
                                                'cloudfront')

        plaintext_addresses += filter_by_type(alternate_addresses, 'http')

        return ([priority_address] +
                onion_addresses +
                https_addresses +
                cloudfront_addresses +
                plaintext_addresses)