def launchServer(self, name, bindaddr, managedInfo): """ Launch a client of transport 'name' using the environment information in 'managedInfo'. Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether the function was successful, and (<addr>, <port> is a tuple representing where we managed to bind. """ serverClass = transports.get_transport_class_from_name_and_mode( name, 'server') if not serverClass: log.error("Could not find transport class for '%s' (%s)." % (name, 'server')) return False, None factory = network.StaticDestinationServerFactory( managedInfo['orport'], 'server', serverClass()) try: addrport = reactor.listenTCP(int(bindaddr[1]), factory) except CannotListenError: log.error("Could not set up a listener for TCP port '%s'." % bindaddr[1]) return False, None return True, (addrport.getHost().host, addrport.getHost().port)
def launchClient(self, name, managedInfo): """ Launch a client of transport 'name' using the environment information in 'managedInfo'. Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether the function was successful, and (<addr>, <port> is a tuple representing where we managed to bind. """ clientClass = transports.get_transport_class_from_name_and_mode( name, 'client') if not clientClass: log.error("Could not find transport class for '%s' (%s)." % (name, 'client')) return False, None factory = socks.SOCKSv4Factory(clientClass()) try: addrport = reactor.listenTCP(0, factory, interface='localhost') except error.CannotListenError: log.error("Could not set up a client listener.") return False, None return True, (addrport.getHost().host, addrport.getHost().port)
def do_managed_mode(): # XXX bad code """This function starts obfsproxy's managed-mode functionality.""" # XXX original code caught exceptions here!!! if checkClientMode(): log.debug('Entering client managed-mode.') ManagedClient() else: log.error('Entering server managed-mode.') ManagedServer()
def validate_external_mode_cli(cls, args): """ Given the parsed CLI arguments in 'args', validate them and make sure they make sense. Return True if they are kosher, otherwise return False. Override for your own needs. """ # If we are not 'socks', we need to have a static destination # to send our data to. if (args.mode != 'socks') and (not args.dest): log.error("'client' and 'server' modes need a destination address.") return False return True
def consider_cli_args(args): """Check out parsed CLI arguments and take the appropriate actions.""" if args.log_file: log.set_log_file(args.log_file) if args.log_min_severity: log.set_log_severity(args.log_min_severity) if args.no_log: log.disable_logs() # validate: if (args.name == 'managed') and (not args.log_file) and (args.log_min_severity): log.error("obfsproxy in managed-proxy mode can only log to a file!") sys.exit(1) elif (args.name == 'managed') and (not args.log_file): # managed proxies without a logfile must not log at all. log.disable_logs()
def validate_external_mode_cli(cls, args): """ Given the parsed CLI arguments in 'args', validate them and make sure they make sense. Return True if they are kosher, otherwise return False. Override for your own needs. """ # If we are not 'socks', we need to have a static destination # to send our data to. if (args.mode != 'socks') and (not args.dest): log.error( "'client' and 'server' modes need a destination address.") return False return True
def launchClient(self, name, managedInfo): """ Launch a client of transport 'name' using the environment information in 'managedInfo'. Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether the function was successful, and (<addr>, <port> is a tuple representing where we managed to bind. """ clientClass = transports.get_transport_class_from_name_and_mode(name, 'client') if not clientClass: log.error("Could not find transport class for '%s' (%s)." % (name, 'client')) return False, None factory = socks.SOCKSv4Factory(clientClass()) try: addrport = reactor.listenTCP(0, factory, interface='localhost') except error.CannotListenError: log.error("Could not set up a client listener.") return False, None return True, (addrport.getHost().host, addrport.getHost().port)
def do_external_mode(args): """This function starts obfsproxy's external-mode functionality.""" assert(args) assert(args.name) assert(args.name in transports.transports) transportClass = transports.get_transport_class_from_name_and_mode(args.name, args.mode) if (transportClass is None): log.error("Transport class was not found for '%s' in mode '%s'" % (args.name, args.mode)) sys.exit(1) # XXX functionify import obfsproxy.network.network as network import obfsproxy.network.socks as socks from twisted.internet import reactor, error, address, tcp if (args.mode == 'client') or (args.mode == 'server'): factory = network.StaticDestinationServerFactory(args.dest, args.mode, transportClass()) elif args.mode == 'socks': factory = socks.SOCKSv4Factory(transportClass()) reactor.listenTCP(int(args.listen_addr[1]), factory) reactor.run()
def launchServer(self, name, bindaddr, managedInfo): """ Launch a client of transport 'name' using the environment information in 'managedInfo'. Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether the function was successful, and (<addr>, <port> is a tuple representing where we managed to bind. """ serverClass = transports.get_transport_class_from_name_and_mode(name, 'server') if not serverClass: log.error("Could not find transport class for '%s' (%s)." % (name, 'server')) return False, None factory = network.StaticDestinationServerFactory(managedInfo['orport'], 'server', serverClass()) try: addrport = reactor.listenTCP(int(bindaddr[1]), factory) except CannotListenError: log.error("Could not set up a listener for TCP port '%s'." % bindaddr[1]) return False, None return True, (addrport.getHost().host, addrport.getHost().port)