Ejemplo n.º 1
0
    def test_create_torrc(self):
        config = TorConfig()
        config.SocksPort = 1234
        config.hiddenservices = [HiddenService(config, '/some/dir', '80 127.0.0.1:1234',
                                               'auth', 2)]
        config.Log = ['80 127.0.0.1:80', '90 127.0.0.1:90']
        torrc = config.create_torrc()
        self.assertTrue(torrc == '''HiddenServiceDir /some/dir
HiddenServicePort 80 127.0.0.1:1234
HiddenServiceVersion 2
HiddenServiceAuthorizeClient auth
Log 80 127.0.0.1:80
Log 90 127.0.0.1:90
SocksPort 1234
''')
Ejemplo n.º 2
0
    def test_create_torrc(self):
        config = TorConfig()
        config.SocksPort = 1234
        config.hiddenservices = [HiddenService(config, '/some/dir', '80 127.0.0.1:1234',
                                               'auth', 2)]
        config.Log = ['80 127.0.0.1:80', '90 127.0.0.1:90']
        config.save()
        torrc = config.create_torrc()
        lines = torrc.split('\n')
        lines.sort()
        torrc = '\n'.join(lines).strip()
        self.assertEqual(torrc, '''HiddenServiceAuthorizeClient auth
HiddenServiceDir /some/dir
HiddenServicePort 80 127.0.0.1:1234
HiddenServiceVersion 2
Log 80 127.0.0.1:80
Log 90 127.0.0.1:90
SocksPort 1234''')
Ejemplo n.º 3
0
    def test_create_torrc(self):
        config = TorConfig()
        config.SocksPort = 1234
        config.hiddenservices = [
            HiddenService(config, '/some/dir', '80 127.0.0.1:1234', 'auth', 2)
        ]
        config.Log = ['80 127.0.0.1:80', '90 127.0.0.1:90']
        config.save()
        torrc = config.create_torrc()
        self.assertEqual(
            torrc, '''HiddenServiceDir /some/dir
HiddenServicePort 80 127.0.0.1:1234
HiddenServiceVersion 2
HiddenServiceAuthorizeClient auth
Log 80 127.0.0.1:80
Log 90 127.0.0.1:90
SocksPort 1234
''')
Ejemplo n.º 4
0
def _configTor():
    torconfig = TorConfig()

    if config.main.socks_port is None:
        config.main.socks_port = int(randomFreePort())
    torconfig.SocksPort = config.main.socks_port

    if config.main.control_port is None:
        config.main.control_port = int(randomFreePort())
    torconfig.ControlPort = config.main.control_port

    if config.main.tor2webmode is True:
        torconfig.Tor2webMode = 1
        torconfig.CircuitBuildTimeout = 60
    if config.main.tor_datadir is None:
        temporary_data_dir = tempfile.mkdtemp()
        log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
        log.warn("Using %s" % temporary_data_dir)
        torconfig.DataDirectory = temporary_data_dir
        uid = -1
        gid = -1
        if config.main.uid is not None:
            uid = config.main.uid
        if config.main.gid is not None:
            gid = config.main.gid
        os.chown(temporary_data_dir, uid, gid)
    else:
        if os.path.exists(config.main.tor_datadir):
            torconfig.DataDirectory = os.path.abspath(config.main.tor_datadir)
        else:
            raise Exception("Could not find tor datadir")

    if config.main.uid is not None:
        try:
            user = pwd.getpwuid(config.main.uid)[0]
        except KeyError:
            raise Exception("Invalid user ID")
        torconfig.User = user

    tor_log_file = os.path.join(torconfig.DataDirectory, "tor.log")
    torconfig.Log = ["notice stdout", "notice file %s" % tor_log_file]
    torconfig.save()
    return torconfig
Ejemplo n.º 5
0
def _configTor():
    torconfig = TorConfig()

    if config.main.socks_port is None:
        config.main.socks_port = int(randomFreePort())
    torconfig.SocksPort = config.main.socks_port

    if config.main.control_port is None:
        config.main.control_port = int(randomFreePort())
    torconfig.ControlPort = config.main.control_port

    if config.main.tor2webmode is True:
        torconfig.Tor2webMode = 1
        torconfig.CircuitBuildTimeout = 60
    if config.main.tor_datadir is None:
        temporary_data_dir = tempfile.mkdtemp()
        log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
        log.warn("Using %s" % temporary_data_dir)
        torconfig.DataDirectory = temporary_data_dir
        uid = -1
        gid = -1
        if config.main.uid is not None:
            uid = config.main.uid
        if config.main.gid is not None:
            gid = config.main.gid
        os.chown(temporary_data_dir, uid, gid)
    else:
        if os.path.exists(config.main.tor_datadir):
            torconfig.DataDirectory = os.path.abspath(config.main.tor_datadir)
        else:
            raise Exception("Could not find tor datadir")

    if config.main.uid is not None:
        try:
            user = pwd.getpwuid(config.main.uid)[0]
        except KeyError:
            raise Exception("Invalid user ID")
        torconfig.User = user

    tor_log_file = os.path.join(torconfig.DataDirectory, "tor.log")
    torconfig.Log = ["notice stdout", "notice file %s" % tor_log_file]
    torconfig.save()
    return torconfig
Ejemplo n.º 6
0
    def test_create_torrc(self):
        config = TorConfig()
        config.SocksPort = 1234
        config.hiddenservices = [
            HiddenService(config, '/some/dir', '80 127.0.0.1:1234',
                          'auth', 2, True)
        ]
        config.Log = ['80 127.0.0.1:80', '90 127.0.0.1:90']
        config.save()
        torrc = config.create_torrc()
        lines = torrc.split('\n')
        lines.sort()
        torrc = '\n'.join(lines).strip()
        self.assertEqual(torrc, '''HiddenServiceAuthorizeClient auth
HiddenServiceDir /some/dir
HiddenServicePort 80 127.0.0.1:1234
HiddenServiceVersion 2
Log 80 127.0.0.1:80
Log 90 127.0.0.1:90
SocksPort 1234''')