예제 #1
0
 def test_get_exits(self):
     self.assertRaises(AssertionError, relayselector.get_exits, '/tmp',
                       'at', True, True, None, None, None, [])
     # assert with no cached descriptors
     with self.assertRaises(SystemExit) as exits:
         relayselector.get_exits('/tmp', 'at', True, False, None,
                                 None, None, [])
     self.assertEqual(exits.exception.code, 1)
예제 #2
0
 def test_get_exits(self):
     self.assertRaises(AssertionError, relayselector.get_exits, '/tmp',
                       'at', True, True, None, None, None, [])
     # assert with no cached descriptors
     with self.assertRaises(SystemExit) as exits:
         relayselector.get_exits('/tmp', 'at', True, False, None, None,
                                 None, [])
     self.assertEqual(exits.exception.code, 1)
예제 #3
0
 def test_get_exits(self):
     with self.assertRaises(SystemExit) as exits:
         relayselector.get_exits('/tmp',
                                 good_exit=True,
                                 bad_exit=True,
                                 version=None,
                                 nickname=None,
                                 address=None,
                                 country_code='at',
                                 requested_exits=None,
                                 destinations=None)
     self.assertEqual(exits.exception.code, 1)
예제 #4
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    hosts = []

    if module.destinations is not None:
        hosts = [(socket.gethostbyname(host), port) for (host, port) in module.destinations]

    # '-e' was used to specify a single exit relay.

    if args.exit:
        exit_relays = [args.exit]
        total = len(exit_relays)
    else:
        total, exit_relays = relayselector.get_exits(args.tor_dir, country_code=args.country, hosts=hosts)

    logger.debug("Successfully selected exit relays after %s." % str(datetime.datetime.now() - before))

    logger.info(
        "%d%s exits out of all %s exit relays allow exiting to %s."
        % (len(exit_relays), " %s" % args.country if args.country else "", total, hosts)
    )

    assert isinstance(exit_relays, list)

    random.shuffle(exit_relays)

    return exit_relays
예제 #5
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    hosts = []

    if module.destinations is not None:
        hosts = [(socket.gethostbyname(host), port) for
                 (host, port) in module.destinations]

    if args.exit:
        # '-e' was used to specify a single exit relay.

        exit_relays = [args.exit]
        total = len(exit_relays)
    elif args.exit_file:
        # '-E' was used to specify a file containing exit relays

        try:
           exit_relays = [line.strip() for line in open(args.exit_file)]
           total = len(exit_relays)
        except Exception as err:
           logger.error("Could not read file %s", args.exit_file)
           sys.exit(1)
    else:
        good_exits = False if (args.all_exits or args.bad_exits) else True
        total, exit_relays = relayselector.get_exits(args.tor_dir,
                                                     country_code=args.country,
                                                     bad_exit=args.bad_exits,
                                                     good_exit=good_exits,
                                                     hosts=hosts)

    logger.debug("Successfully selected exit relays after %s." %
                 str(datetime.datetime.now() - before))

    pretty_hosts = ["%s:%d" % (host, port) for host, port in hosts]
    logger.info("%d%s exit relays out of all %s exit relays allow traffic "
                "to: %s" % (len(exit_relays),
                            " %s" % args.country if args.country else "",
                            total,
                            ", ".join(pretty_hosts)))

    assert isinstance(exit_relays, list)

    random.shuffle(exit_relays)

    return exit_relays
예제 #6
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    hosts = []

    if module.destinations is not None:
        hosts = [(socket.gethostbyname(host), port) for
                 (host, port) in module.destinations]

    if args.exit:
        # '-e' was used to specify a single exit relay.

        exit_relays = [args.exit]
        total = len(exit_relays)
    elif args.exit_file:
        # '-E' was used to specify a file containing exit relays

        try:
            exit_relays = [line.strip() for line in open(args.exit_file)]
            total = len(exit_relays)
        except Exception as err:
            logger.error("Could not read file %s", args.exit_file)
            sys.exit(1)
    else:
        good_exits = False if (args.all_exits or args.bad_exits) else True
        total, exit_relays = relayselector.get_exits(args.tor_dir,
                                                     country_code=args.country,
                                                     bad_exit=args.bad_exits,
                                                     good_exit=good_exits,
                                                     hosts=hosts)

    logger.debug("Successfully selected exit relays after %s." %
                 str(datetime.datetime.now() - before))

    pretty_hosts = ["%s:%d" % (host, port) for host, port in hosts]
    logger.info("%d%s exit relays out of all %s exit relays allow traffic "
                "to: %s" % (len(exit_relays),
                            " %s" % args.country if args.country else "",
                            total,
                            ", ".join(pretty_hosts)))

    assert isinstance(exit_relays, list)

    random.shuffle(exit_relays)

    return exit_relays
예제 #7
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    hosts = []

    consensus = util.get_consensus_path(args)

    if not os.path.exists(consensus):
        raise IOError("The consensus file \"%s\" does not exist." % consensus)

    if module.destinations is not None:
        hosts = [(socket.gethostbyname(host), port)
                 for (host, port) in module.destinations]

    # '-e' was used to specify a single exit relay.

    if args.exit:
        exit_relays = [args.exit]
        total = len(exit_relays)
    else:
        total, exit_relays = relayselector.get_exits(consensus,
                                                     country_code=args.country,
                                                     hosts=hosts)

    logger.debug("Successfully selected exit relays after %s." %
                 str(datetime.datetime.now() - before))

    logger.info("%d%s exits out of all %s exit relays allow exiting to %s." %
                (len(exit_relays),
                 " %s" % args.country if args.country else "", total, hosts))

    assert isinstance(exit_relays, list)

    random.shuffle(exit_relays)

    return exit_relays
예제 #8
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    destinations = lookup_destinations(module)

    if args.exit:
        # '-e' was used to specify a single exit relay.
        requested_exits = [args.exit]
    elif args.exit_file:
        # '-E' was used to specify a file containing exit relays.
        try:
            requested_exits = [line.strip() for line in open(args.exit_file)]
        except OSError as err:
            logger.error("Could not read %s: %s", args.exit_file,
                         err.strerror)
            sys.exit(1)
        except Exception as err:
            logger.error("Could not read %s: %s", args.exit_file, err)
            sys.exit(1)
    else:
        requested_exits = None

    exit_destinations = relayselector.get_exits(
        args.tor_dir,
        good_exit       = args.all_exits or (not args.bad_exits),
        bad_exit        = args.all_exits or args.bad_exits,
        country_code    = args.country,
        requested_exits = requested_exits,
        destinations    = destinations)

    logger.debug("Successfully selected exit relays after %s." %
                 str(datetime.datetime.now() - before))

    return exit_destinations
예제 #9
0
def select_exits(args, module):
    """
    Select exit relays which allow exiting to the module's scan destinations.

    We select exit relays based on their published exit policy.  In particular,
    we check if the exit relay's exit policy specifies that we can connect to
    our intended destination(s).
    """

    before = datetime.datetime.now()
    destinations = lookup_destinations(module)

    if args.exit:
        # '-e' was used to specify a single exit relay.
        requested_exits = [args.exit]
    elif args.exit_file:
        # '-E' was used to specify a file containing exit relays.
        try:
            requested_exits = [line.strip() for line in open(args.exit_file)]
        except OSError as err:
            logger.error("Could not read %s: %s", args.exit_file,
                         err.strerror)
            sys.exit(1)
        except Exception as err:
            logger.error("Could not read %s: %s", args.exit_file, err)
            sys.exit(1)
    else:
        requested_exits = None

    exit_destinations = relayselector.get_exits(
        args.tor_dir,
        good_exit       = args.all_exits or (not args.bad_exits),
        bad_exit        = args.all_exits or args.bad_exits,
        country_code    = args.country,
        requested_exits = requested_exits,
        destinations    = destinations)

    logger.debug("Successfully selected exit relays after %s." %
                 str(datetime.datetime.now() - before))

    return exit_destinations