Exemplo n.º 1
0
 def getHSEndpoint(data_dir):
     if LooseVersion(txtorcon_version) >= LooseVersion('0.10.0'):
         return TCPHiddenServiceEndpoint(reactor,
                                         torconfig,
                                         80,
                                         hidden_service_dir=data_dir)
     else:
         return TCPHiddenServiceEndpoint(reactor,
                                         torconfig,
                                         80,
                                         data_dir=data_dir)
Exemplo n.º 2
0
 def test_failure(self):
     self.reactor.failures = 1
     ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
     d = ep.listen(NoOpProtocolFactory())
     self.config.bootstrap()
     d.addErrback(self.check_error)
     return d
Exemplo n.º 3
0
    def test_stealth_auth(self):
        '''
        make sure we produce a HiddenService instance with stealth-auth
        lines if we had authentication specified in the first place.
        '''

        config = TorConfig(self.protocol)
        ep = TCPHiddenServiceEndpoint(self.reactor,
                                      config,
                                      123,
                                      '/dev/null',
                                      stealth_auth=['alice', 'bob'])

        # make sure listen() correctly configures our hidden-serivce
        # with the explicit directory we passed in above
        d = ep.listen(NoOpProtocolFactory())

        def foo(fail):
            print "ERROR", fail

        d.addErrback(foo)
        port = yield d
        self.assertEqual(1, len(config.HiddenServices))
        self.assertEqual(config.HiddenServices[0].dir, '/dev/null')
        self.assertEqual(config.HiddenServices[0].authorize_client[0],
                         'stealth alice,bob')
        self.assertEqual(None, ep.onion_uri)
        config.HiddenServices[0].hostname = 'oh my'
        self.assertEqual('oh my', ep.onion_uri)
Exemplo n.º 4
0
def setupCollector(tor_process_protocol):
    def setup_complete(port):
        print("Exposed collector Tor hidden service on httpo://%s"
              % port.onion_uri)

    tempfile.tempdir = os.path.join(_repo_dir, 'tmp')
    if not os.path.isdir(tempfile.gettempdir()):
        os.makedirs(tempfile.gettempdir())
    _temp_dir = tempfile.mkdtemp()

    if config.main.tor_datadir is None:
        log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
        log.msg("Creating tmp directory in current directory for datadir.")
        log.debug("Using %s" % _temp_dir)
        datadir = _temp_dir
    else:
        datadir = config.main.tor_datadir

    torconfig = TorConfig(tor_process_protocol.tor_protocol)
    public_port = 80
    # XXX there is currently a bug in txtorcon that prevents data_dir from
    # being passed properly. Details on the bug can be found here:
    # https://github.com/meejah/txtorcon/pull/22
    hs_endpoint = TCPHiddenServiceEndpoint(reactor, torconfig, public_port,
                                           data_dir=datadir)
    hidden_service = hs_endpoint.listen(reportingBackend)
    hidden_service.addCallback(setup_complete)
    hidden_service.addErrback(txSetupFailed)
Exemplo n.º 5
0
    def test_multiple_listen(self):
        ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
        d0 = ep.listen(NoOpProtocolFactory())

        @defer.inlineCallbacks
        def more_listen(arg):
            yield arg.stopListening()
            d1 = ep.listen(NoOpProtocolFactory())

            def foo(arg):
                return arg

            d1.addBoth(foo)
            defer.returnValue(arg)
            return

        d0.addBoth(more_listen)
        self.config.bootstrap()

        def check(arg):
            self.assertEqual('127.0.0.1', ep.tcp_endpoint._interface)
            self.assertEqual(len(self.config.HiddenServices), 1)

        d0.addCallback(check).addErrback(self.fail)
        return d0
Exemplo n.º 6
0
 def test_basic(self):
     ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
     d = ep.listen(FakeProtocolFactory())
     self.protocol.answers.append(
         'config/names=\nHiddenServiceOptions Virtual\nOK')
     self.protocol.answers.append('HiddenServiceOptions')
     self.config.bootstrap()
     return d
Exemplo n.º 7
0
def getHSEndpoint(endpoint_config):
    from txtorcon import TCPHiddenServiceEndpoint
    hsdir = endpoint_config['hsdir']
    hsdir = os.path.expanduser(hsdir)
    hsdir = os.path.realpath(hsdir)
    return TCPHiddenServiceEndpoint(reactor,
                                    config=get_global_tor(reactor),
                                    public_port=80,
                                    hidden_service_dir=hsdir)
Exemplo n.º 8
0
    def test_already_bootstrapped(self):
        self.protocol.answers.append('''config/names=
HiddenServiceOptions Virtual
OK''')
        self.protocol.answers.append('HiddenServiceOptions')

        self.config.bootstrap()

        ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
        d = ep.listen(FakeProtocolFactory())
        return d
Exemplo n.º 9
0
    def test_too_many_failures(self):
        self.reactor.failures = 12
        ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
        d = ep.listen(FakeProtocolFactory())

        self.protocol.answers.append(
            'config/names=\nHiddenServiceOptions Virtual\nOK')
        self.protocol.answers.append('HiddenServiceOptions')
        self.config.bootstrap()
        d.addErrback(self.check_error)
        return d
Exemplo n.º 10
0
    def test_progress_updates(self):
        config = TorConfig()
        ep = TCPHiddenServiceEndpoint(self.reactor, config, 123)

        self.assertTrue(IProgressProvider.providedBy(ep))
        prog = IProgressProvider(ep)
        ding = Mock()
        prog.add_progress_listener(ding)
        args = (50, "blarg", "Doing that thing we talked about.")
        # kind-of cheating, test-wise?
        ep._tor_progress_update(*args)
        self.assertTrue(ding.called_with(*args))
Exemplo n.º 11
0
        def setupHSEndpoint(self, tor_process_protocol, torconfig, endpoint):
            endpointName = endpoint.settings['name']
            def setup_complete(port):
                print("Exposed %s Tor hidden service on httpo://%s" % (endpointName,
                    port.onion_uri))

            public_port = 80
            hs_endpoint = TCPHiddenServiceEndpoint(reactor, torconfig, public_port,
                    data_dir=os.path.join(torconfig.DataDirectory, endpointName))
            d = hs_endpoint.listen(endpoint)
            d.addCallback(setup_complete)
            d.addErrback(self.txSetupFailed)
            return d
Exemplo n.º 12
0
    def test_explicit_data_dir(self):
        config = TorConfig(self.protocol)
        ep = TCPHiddenServiceEndpoint(self.reactor, config, 123, '/dev/null')

        # make sure listen() correctly configures our hidden-serivce
        # with the explicit directory we passed in above
        d = ep.listen(NoOpProtocolFactory())

        def foo(fail):
            print "ERROR", fail

        d.addErrback(foo)
        port = yield d
        self.assertEqual(1, len(config.HiddenServices))
        self.assertEqual(config.HiddenServices[0].dir, '/dev/null')
Exemplo n.º 13
0
def setupBouncer(tor_process_protocol, datadir):
    def setup_complete(port):
        #XXX: drop some other noise about what API are available on this machine
        print("Exposed bouncer Tor hidden service on httpo://%s"
              % port.onion_uri)

    torconfig = TorConfig(tor_process_protocol.tor_protocol)
    public_port = 80

    hs_endpoint = TCPHiddenServiceEndpoint(reactor, torconfig, public_port,
                                           data_dir=os.path.join(datadir, 'bouncer'))

    d = hs_endpoint.listen(ooniBouncer)
    d.addCallback(setup_complete)
    d.addErrback(txSetupFailed)
Exemplo n.º 14
0
    def test_explicit_data_dir_valid_hostname(self):
        datadir = tempfile.mkdtemp()
        with open(os.path.join(datadir, 'hostname'), 'w') as f:
            f.write('timaq4ygg2iegci7.onion')
        with open(os.path.join(datadir, 'private_key'), 'w') as f:
            f.write('foo\nbar')

        try:
            ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123,
                                          datadir)
            self.assertEqual(ep.onion_uri, 'timaq4ygg2iegci7.onion')
            self.assertEqual(ep.onion_private_key, 'foo\nbar')

        finally:
            shutil.rmtree(datadir, ignore_errors=True)
Exemplo n.º 15
0
    def test_explicit_data_dir(self, ftb):
        with util.TempDir() as tmp:
            d = str(tmp)
            with open(os.path.join(d, 'hostname'), 'w') as f:
                f.write('public')

            config = TorConfig(self.protocol)
            ep = TCPHiddenServiceEndpoint(self.reactor, config, 123, d)

            # make sure listen() correctly configures our hidden-serivce
            # with the explicit directory we passed in above
            yield ep.listen(NoOpProtocolFactory())

            self.assertEqual(1, len(config.HiddenServices))
            self.assertEqual(config.HiddenServices[0].dir, d)
            self.assertEqual(config.HiddenServices[0].hostname, 'public')
Exemplo n.º 16
0
    def test_basic(self):
        listen = RuntimeError("listen")
        connect = RuntimeError("connect")
        reactor = proto_helpers.RaisingMemoryReactor(listen, connect)
        reactor.addSystemEventTrigger = Mock()

        ep = TCPHiddenServiceEndpoint(reactor, self.config, 123)
        self.config.bootstrap()
        yield self.config.post_bootstrap
        self.assertTrue(IProgressProvider.providedBy(ep))

        try:
            port = yield ep.listen(NoOpProtocolFactory())
            self.fail("Should have been an exception")
        except RuntimeError as e:
            # make sure we called listenTCP not connectTCP
            self.assertEqual(e, listen)

        repr(self.config.HiddenServices)
Exemplo n.º 17
0
    def test_explicit_data_dir(self):
        d = tempfile.mkdtemp()
        try:
            with open(os.path.join(d, 'hostname'), 'w') as f:
                f.write('public')

            config = TorConfig(self.protocol)
            ep = TCPHiddenServiceEndpoint(self.reactor, config, 123, d)

            # make sure listen() correctly configures our hidden-serivce
            # with the explicit directory we passed in above
            port = yield ep.listen(NoOpProtocolFactory())

            self.assertEqual(1, len(config.HiddenServices))
            self.assertEqual(config.HiddenServices[0].dir, d)
            self.assertEqual(config.HiddenServices[0].hostname, 'public')

        finally:
            shutil.rmtree(d, ignore_errors=True)
Exemplo n.º 18
0
    def test_explicit_data_dir(self):
        config = TorConfig()
        td = tempfile.mkdtemp()
        ep = TCPHiddenServiceEndpoint(self.reactor, config, 123, td)

        # fake out some things so we don't actually have to launch + bootstrap
        class FakeTorProcessProtocol(object):
            tor_protocol = self.reactor.protocol

        process = FakeTorProcessProtocol()
        ep._launch_tor = Mock(return_value=process)
        config._update_proto(Mock())
        config.bootstrap()
        yield config.post_bootstrap

        # make sure listen() correctly configures our hidden-serivce
        # with the explicit directory we passed in above
        port = yield ep.listen(NoOpProtocolFactory())
        self.assertEqual(1, len(config.HiddenServices))
        self.assertEqual(config.HiddenServices[0].dir, td)
        shutil.rmtree(td)
Exemplo n.º 19
0
def setupCollector(tor_process_protocol, datadir):
    def setup_complete(port):
        #XXX: drop some other noise about what API are available on this machine
        print("Exposed collector Tor hidden service on httpo://%s"
              % port.onion_uri)

    torconfig = TorConfig(tor_process_protocol.tor_protocol)
    public_port = 80
    # XXX there is currently a bug in txtorcon that prevents data_dir from
    # being passed properly. Details on the bug can be found here:
    # https://github.com/meejah/txtorcon/pull/22

    #XXX: set up the various API endpoints, if configured and enabled
    #XXX: also set up a separate keyed hidden service for collectors to push their status to, if the bouncer is enabled
    hs_endpoint = TCPHiddenServiceEndpoint(reactor, torconfig, public_port,
                                           data_dir=os.path.join(datadir, 'collector'))
    d = hs_endpoint.listen(ooniBackend)
    
    d.addCallback(setup_complete)
    d.addErrback(txSetupFailed)

    return tor_process_protocol
Exemplo n.º 20
0
 def test_already_bootstrapped(self):
     self.config.bootstrap()
     ep = TCPHiddenServiceEndpoint(self.reactor, self.config, 123)
     d = ep.listen(NoOpProtocolFactory())
     return d