def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        log.msg(
            "Connecting to %s with tor %s" %
            (self.bridge, onion.tor_details['version']))

        transport_name = onion.transport_name(self.bridge)
        if transport_name and transport_name == 'fte' and self.fteproxy_bin:
            config.ClientTransportPlugin = "%s exec %s --managed" % (
                transport_name, self.fteproxy_bin)
            self.report['transport_name'] = transport_name
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and transport_name == 'fte'\
                and not self.fteproxy_bin:
            log.err("Unable to test bridge because fteproxy is not installed")
            self.report['error'] = 'missing-fteproxy'
            return
        elif transport_name and self.pyobfsproxy_bin:
            config.ClientTransportPlugin = "%s exec %s managed" % (
                transport_name, self.pyobfsproxy_bin)
            self.report['transport_name'] = transport_name
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and not self.pyobfsproxy_bin:
            log.err(
                "Unable to test bridge because pyobfsproxy is not installed")
            self.report['error'] = 'missing-pyobfsproxy'
            return
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[0]

        if transport_name and transport_name == 'scramblesuit' and \
                onion.TorVersion('0.2.5.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return
        elif transport_name and \
                onion.TorVersion('0.2.4.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.log = 'notice'
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['tor_log'] = failure.value.message
            self.report['success'] = False

        return d
示例#2
0
    def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        log.msg(
            "Connecting to %s with tor %s" %
            (self.bridge, onion.tor_details['version']))

        transport_name = onion.transport_name(self.bridge)

        if transport_name:
            self.report['transport_name'] = transport_name

        if transport_name and transport_name == 'fte' and self.fteproxy_bin:
            config.ClientTransportPlugin = "%s exec %s --managed" % (
                transport_name, self.fteproxy_bin)
            log.debug("Using fte from %s" % self.fteproxy_bin)
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and transport_name == 'fte'\
                and not self.fteproxy_bin:
            log.err("Unable to test bridge because fteproxy is not installed")
            self.report['error'] = 'missing-fteproxy'
            return
        elif transport_name and self.pyobfsproxy_bin:
            config.ClientTransportPlugin = ("%s exec %s --log-min-severity info "
                "--log-file %s managed") % (transport_name,
                                            self.pyobfsproxy_bin,
                                            self.obfsproxy_logfile)
            if onion.OBFSProxyVersion('0.2') > onion.obfsproxy_details['version']:
                log.err(
                    "The obfsproxy version you are using appears to be outdated."
                )
                self.report['error'] = 'old-obfsproxy'
                return
            log.debug("Using pyobfsproxy from %s" % self.pyobfsproxy_bin)
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and not self.pyobfsproxy_bin:
            log.err(
                "Unable to test bridge because pyobfsproxy is not installed")
            self.report['error'] = 'missing-pyobfsproxy'
            return
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[0]

        if transport_name and transport_name == 'scramblesuit' and \
                onion.TorVersion('0.2.5.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return
        elif transport_name and \
                onion.TorVersion('0.2.4.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.log = ['notice stdout', 'notice file %s' % self.tor_logfile]
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['success'] = False
            self.report['error'] = 'timeout-reached'
            return

        @d.addCallback
        def write_log(_):
            with open(self.tor_logfile) as f:
                self.report['tor_log'] = f.read()
            os.remove(self.tor_logfile)
            with open(self.obfsproxy_logfile) as f:
                self.report['obfsproxy_log'] = f.read()
            os.remove(self.obfsproxy_logfile)

        return d
示例#3
0
    def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        config.DataDirectory = self.tor_datadir
        log.msg(
            "Connecting to %s with tor %s" %
            (self.bridge, onion.tor_details['version']))

        transport_name = onion.transport_name(self.bridge)
        if transport_name == None:
            self.report['bridge_address'] = self.bridge.split(' ')[0]
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[1]
            self.report['transport_name'] = transport_name

            try:
                config.ClientTransportPlugin = \
                        onion.bridge_line(transport_name, self.obfsproxy_logfile)
            except onion.UnrecognizedTransport:
                log.err("Unable to test bridge because we don't recognize "
                        "the %s transport" % transport_name)
                self.report['error'] = "unrecognized-transport"
                return
            except onion.UninstalledTransport:
                bin_name = onion.transport_bin_name.get(transport_name)
                log.err("Unable to test bridge because %s is not installed" %
                        bin_name)
                self.report['error'] = "missing-%s" % bin_name
                return
            except onion.OutdatedObfsproxy:
                log.err("The obfsproxy version you are using " \
                        "appears to be outdated.")
                self.report['error'] = 'old-obfsproxy'
                return
            except onion.OutdatedTor:
                log.err("Unsupported Tor version.")
                self.report['error'] = 'unsupported-tor-version'
                return

            log.debug("Using ClientTransportPlugin '%s'" % \
                      config.ClientTransportPlugin)

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.log = ['notice stdout', 'notice file %s' % self.tor_logfile]
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['success'] = False
            self.report['error'] = 'timeout-reached'
            return

        @d.addCallback
        def write_log(_):
            with open(self.tor_logfile) as f:
                self.report['tor_log'] = f.read()
            os.remove(self.tor_logfile)
            with open(self.obfsproxy_logfile) as f:
                self.report['obfsproxy_log'] = f.read()
            os.remove(self.obfsproxy_logfile)
            try:
                with open(os.path.join(self.tor_datadir,
                        'pt_state', 'obfs4proxy.log')) as f:
                    self.report['obfsproxy_log'] = f.read()
            except:
                pass
            finally:
                shutil.rmtree(self.tor_datadir)

        return d
示例#4
0
    def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        config.DataDirectory = self.tor_datadir
        log.msg(
            "Connecting to %s with tor %s" %
            (self.bridge, onion.tor_details['version']))

        transport_name = onion.transport_name(self.bridge)
        if transport_name == None:
            self.report['bridge_address'] = self.bridge.split(' ')[0]
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[1]
            self.report['transport_name'] = transport_name

            try:
                config.ClientTransportPlugin = \
                        onion.bridge_line(transport_name, self.obfsproxy_logfile)
            except onion.UnrecognizedTransport:
                log.err("Unable to test bridge because we don't recognize "
                        "the %s transport" % transport_name)
                self.report['error'] = "unrecognized-transport"
                return
            except onion.UninstalledTransport:
                bin_name = onion.transport_bin_name.get(transport_name)
                log.err("Unable to test bridge because %s is not installed" %
                        bin_name)
                self.report['error'] = "missing-%s" % bin_name
                return
            except onion.OutdatedObfsproxy:
                log.err("The obfsproxy version you are using " \
                        "appears to be outdated.")
                self.report['error'] = 'old-obfsproxy'
                return
            except onion.OutdatedTor:
                log.err("Unsupported Tor version.")
                self.report['error'] = 'unsupported-tor-version'
                return

            log.debug("Using ClientTransportPlugin '%s'" % \
                      config.ClientTransportPlugin)

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.log = ['notice stdout', 'notice file %s' % self.tor_logfile]
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['success'] = False
            self.report['error'] = 'timeout-reached'
            return

        @d.addCallback
        def write_log(_):
            with open(self.tor_logfile) as f:
                self.report['tor_log'] = f.read()
            os.remove(self.tor_logfile)
            with open(self.obfsproxy_logfile) as f:
                self.report['obfsproxy_log'] = f.read()
            os.remove(self.obfsproxy_logfile)
            try:
                with open(os.path.join(self.tor_datadir,
                        'pt_state', 'obfs4proxy.log')) as f:
                    self.report['obfsproxy_log'] = f.read()
            except:
                pass
            finally:
                shutil.rmtree(self.tor_datadir)

        return d
    def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        log.msg("Connecting to %s with tor %s" %
                (self.bridge, onion.tor_details['version']))

        transport_name = onion.transport_name(self.bridge)

        if transport_name:
            self.report['transport_name'] = transport_name

        if transport_name and transport_name == 'fte' and self.fteproxy_bin:
            config.ClientTransportPlugin = "%s exec %s --managed" % (
                transport_name, self.fteproxy_bin)
            log.debug("Using fte from %s" % self.fteproxy_bin)
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and transport_name == 'fte'\
                and not self.fteproxy_bin:
            log.err("Unable to test bridge because fteproxy is not installed")
            self.report['error'] = 'missing-fteproxy'
            return
        elif transport_name and self.pyobfsproxy_bin:
            config.ClientTransportPlugin = (
                "%s exec %s --log-min-severity info "
                "--log-file %s managed") % (transport_name,
                                            self.pyobfsproxy_bin,
                                            self.obfsproxy_logfile)
            if onion.OBFSProxyVersion(
                    '0.2') > onion.obfsproxy_details['version']:
                log.err(
                    "The obfsproxy version you are using appears to be outdated."
                )
                self.report['error'] = 'old-obfsproxy'
                return
            log.debug("Using pyobfsproxy from %s" % self.pyobfsproxy_bin)
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and not self.pyobfsproxy_bin:
            log.err(
                "Unable to test bridge because pyobfsproxy is not installed")
            self.report['error'] = 'missing-pyobfsproxy'
            return
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[0]

        if transport_name and transport_name == 'scramblesuit' and \
                onion.TorVersion('0.2.5.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return
        elif transport_name and \
                onion.TorVersion('0.2.4.1') > onion.tor_details['version']:
            self.report['error'] = 'unsupported-tor-version'
            log.err("Unsupported Tor version.")
            return

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.log = ['notice stdout', 'notice file %s' % self.tor_logfile]
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config,
                                reactor,
                                timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['success'] = False
            self.report['error'] = 'timeout-reached'
            return

        @d.addCallback
        def write_log(_):
            with open(self.tor_logfile) as f:
                self.report['tor_log'] = f.read()
            os.remove(self.tor_logfile)
            with open(self.obfsproxy_logfile) as f:
                self.report['obfsproxy_log'] = f.read()
            os.remove(self.obfsproxy_logfile)

        return d