[Pkg-privacy-commits] [obfsproxy] 06/353: Reformatted code with PythonTidy
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository obfsproxy.
commit 73826cb54531d6742e179e025cb0539c871a29f4
Author: Brandon Wiley <brandon at blanu.net>
Date: Fri Jun 29 13:24:50 2012 -0500
Reformatted code with PythonTidy
---
setup.py | 52 +++----
src/__init__.py | 3 +
src/obfsproxy/__init__.py | 2 +
src/obfsproxy/cli/obfsproxy.py | 65 +++++----
src/obfsproxy/framework/__init__.py | 2 +
src/obfsproxy/framework/daemon.py | 55 ++++---
src/obfsproxy/framework/external/__init__.py | 2 +
src/obfsproxy/framework/external/client.py | 82 ++++++-----
src/obfsproxy/framework/external/server.py | 80 ++++++-----
src/obfsproxy/framework/loopback.py | 104 +++++++-------
src/obfsproxy/framework/managed/__init__.py | 2 +
src/obfsproxy/framework/managed/client.py | 82 ++++++-----
src/obfsproxy/framework/managed/server.py | 80 ++++++-----
src/obfsproxy/framework/proxy.py | 27 ++--
src/obfsproxy/framework/shared.py | 86 ++++++-----
src/obfsproxy/framework/socks.py | 101 +++++++------
src/obfsproxy/manager/__init__.py | 2 +
src/obfsproxy/manager/clientManager.py | 17 ++-
src/obfsproxy/manager/manager.py | 29 ++--
src/obfsproxy/manager/serverManager.py | 23 +--
src/obfsproxy/transports/__init__.py | 2 +
src/obfsproxy/transports/dummy.py | 24 ++--
src/obfsproxy/transports/rot13.py | 43 ++++--
src/obfsproxy/util.py | 205 +++++++++++++++------------
24 files changed, 673 insertions(+), 497 deletions(-)
diff --git a/setup.py b/setup.py
index 83353dc..30851ae 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import sys
@@ -6,26 +7,29 @@ sys.path.insert(0, 'src')
from setuptools import setup
-setup(name='pyptlib',
- version='0.1',
- description='A python implementation of the Pluggable Transports for Circumvention specification for Tor',
- long_description='A python implementation of the Pluggable Transports for Circumvention specification for Tor',
- author='Brandon Wiley',
- author_email='brandon at blanu.net',
- url='http://stepthreeprivacy.org/',
- classifiers=[
- "Development Status :: 3 - Alpha",
- "Environment :: No Input/Output (Daemon)",
- "License :: OSI Approved :: BSD License",
- "Programming Language :: Python",
- "Intended Audience :: Developers",
- "Operating System :: OS Independent",
- "Topic :: Internet",
- "Topic :: Security :: Cryptography",
- "Topic :: Software Development :: Libraries :: Python Modules",
- ],
- keywords='cryptography privacy internet',
- license='BSD',
- package_dir={'pyptlib': 'src/pyptlib'},
- packages=['pyptlib'],
- )
+setup(
+ name='pyptlib',
+ version='0.1',
+ description='A python implementation of the Pluggable Transports for Circumvention specification for Tor'
+ ,
+ long_description='A python implementation of the Pluggable Transports for Circumvention specification for Tor'
+ ,
+ author='Brandon Wiley',
+ author_email='brandon at blanu.net',
+ url='http://stepthreeprivacy.org/',
+ classifiers=[
+ 'Development Status :: 3 - Alpha',
+ 'Environment :: No Input/Output (Daemon)',
+ 'License :: OSI Approved :: BSD License',
+ 'Programming Language :: Python',
+ 'Intended Audience :: Developers',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet',
+ 'Topic :: Security :: Cryptography',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ],
+ keywords='cryptography privacy internet',
+ license='BSD',
+ package_dir={'pyptlib': 'src/pyptlib'},
+ packages=['pyptlib'],
+ )
diff --git a/src/__init__.py b/src/__init__.py
index e69de29..e0e3e1a 100644
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -0,0 +1,3 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
diff --git a/src/obfsproxy/__init__.py b/src/obfsproxy/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/__init__.py
+++ b/src/obfsproxy/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/cli/obfsproxy.py b/src/obfsproxy/cli/obfsproxy.py
index e2d81bf..60e13ca 100644
--- a/src/obfsproxy/cli/obfsproxy.py
+++ b/src/obfsproxy/cli/obfsproxy.py
@@ -1,36 +1,51 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import argparse
from pyptlib.framework.server import ManagedServer
from pyptlib.framework.client import ManagedClient
-protocols=['dummy', 'rot13']
+protocols = ['dummy', 'rot13']
-if __name__=='__main__':
- parser=argparse.ArgumentParser(description="* Available protocols: "+(' '.join(protocols)))
- parser.add_argument('--log-file', nargs=1, help='set logfile')
- parser.add_argument('--log-min-severity', nargs=1, default='notice', choices=['warn', 'notice', 'info', 'debug'], help='set minimum logging severity (default: %(default)s)')
- parser.add_argument('--no-log', action='store_false', default=True, help='disable logging')
- parser.add_argument('--no-safe-logging', action='store_false', default=True, help='disable safe (scrubbed address) logging')
- parser.add_argument('--managed', action='store_true', default=False, help='enabled managed mode, for use when called by tor')
- parser.add_argument('--dest', nargs=1, help='set destination, enable client mode instead of server mode')
+if __name__ == '__main__':
+ parser = \
+ argparse.ArgumentParser(description='* Available protocols: '
+ + ' '.join(protocols))
+ parser.add_argument('--log-file', nargs=1, help='set logfile')
+ parser.add_argument('--log-min-severity', nargs=1, default='notice'
+ , choices=['warn', 'notice', 'info', 'debug'],
+ help='set minimum logging severity (default: %(default)s)'
+ )
+ parser.add_argument('--no-log', action='store_false', default=True,
+ help='disable logging')
+ parser.add_argument('--no-safe-logging', action='store_false',
+ default=True,
+ help='disable safe (scrubbed address) logging')
+ parser.add_argument('--managed', action='store_true',
+ default=False,
+ help='enabled managed mode, for use when called by tor'
+ )
+ parser.add_argument('--dest', nargs=1,
+ help='set destination, enable client mode instead of server mode'
+ )
- parser.add_argument('obfsproxy_args')
- parser.add_argument('protocol_name')
- parser.add_argument('protocol_args')
- parser.add_argument('protocol_options')
- parser.add_argument('protocol_name')
+ parser.add_argument('obfsproxy_args')
+ parser.add_argument('protocol_name')
+ parser.add_argument('protocol_args')
+ parser.add_argument('protocol_options')
+ parser.add_argument('protocol_name')
- args = parser.parse_args()
+ args = parser.parse_args()
- print(args)
+ print args
- if managed:
- if dest:
- client=ManagedClient()
+ if managed:
+ if dest:
+ client = ManagedClient()
+ else:
+ server = ManagedServer()
else:
- server=ManagedServer()
- else:
- if dest:
- client=ExternalClient()
- else:
- server=ExternalServer()
+ if dest:
+ client = ExternalClient()
+ else:
+ server = ExternalServer()
diff --git a/src/obfsproxy/framework/__init__.py b/src/obfsproxy/framework/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/framework/__init__.py
+++ b/src/obfsproxy/framework/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/framework/daemon.py b/src/obfsproxy/framework/daemon.py
index a82f6d4..eda9125 100644
--- a/src/obfsproxy/framework/daemon.py
+++ b/src/obfsproxy/framework/daemon.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import sys
import time
@@ -11,42 +12,52 @@ from monocle import _o, Return
monocle.init('tornado')
from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service, Client, ConnectionLost
+from monocle.stack.network import add_service, Service, Client, \
+ ConnectionLost
from pyptlib.framework.loopback import FakeSocket
from pyptlib.framework.shared import *
from pyptlib.framework.socks import *
+
class Daemon:
- config=None
- handler=None
- supportedTransportVersion='1'
- supportedTransport='dummy'
+ config = None
+ handler = None
+
+ supportedTransportVersion = '1'
+ supportedTransport = 'dummy'
+
+ def __init__(self, configManager, handler):
+ self.config = configManager
+ self.handler = handler
- def __init__(self, configManager, handler):
- self.config=configManager
- self.handler=handler
+ if self.config.checkManagedTransportVersion(self.supportedTransportVersion):
+ self.config.writeVersion(self.supportedTransportVersion)
+ else:
+ self.config.writeVersionError()
+ raise UnsupportedManagedTransportVersionException()
- if self.config.checkManagedTransportVersion(self.supportedTransportVersion):
- self.config.writeVersion(self.supportedTransportVersion)
- else:
- self.config.writeVersionError()
- raise UnsupportedManagedTransportVersionException()
+ if not self.config.checkTransportEnabled(self.supportedTransport):
+ raise NoSupportedTransportsException()
- if not self.config.checkTransportEnabled(self.supportedTransport):
- raise NoSupportedTransportsException()
+ def run(self):
+ eventloop.run()
- def run(self):
- eventloop.run()
class UnsupportedManagedTransportVersionException(Exception):
- pass
+
+ pass
+
class NoSupportedTransportsException(Exception):
- pass
+
+ pass
+
class TransportLaunchException(Exception):
- def __init__(self, message):
- self.message=message
+
+ def __init__(self, message):
+ self.message = message
+
diff --git a/src/obfsproxy/framework/external/__init__.py b/src/obfsproxy/framework/external/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/framework/external/__init__.py
+++ b/src/obfsproxy/framework/external/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/framework/external/client.py b/src/obfsproxy/framework/external/client.py
index 8326ceb..50beb8a 100755
--- a/src/obfsproxy/framework/external/client.py
+++ b/src/obfsproxy/framework/external/client.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python -u
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
import sys
@@ -13,7 +14,8 @@ from monocle import _o, Return
monocle.init('tornado')
from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service, Client, ConnectionLost
+from monocle.stack.network import add_service, Service, Client, \
+ ConnectionLost
from pyptlib.framework.loopback import FakeSocket
from pyptlib.framework.socks import SocksHandler
@@ -24,40 +26,46 @@ from pyptlib.framework.daemon import *
from pyptlib.transports.dummy import DummyClient
+
class ManagedClient(Daemon):
- def __init__(self):
- try:
- Daemon.__init__(self, ClientConfig(), SocksHandler())
- except EnvException:
- print('error 0')
- return
- except UnsupportedManagedTransportVersionException:
- print('error 1')
- return
- except NoSupportedTransportsException:
- print('error 2')
- return
-
- try:
- self.launchClient(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport, 5, ('127.0.0.1', 8182), None, None)
- except TransportLaunchException as e:
- print('error 3')
- self.config.writeMethodError(self.supportedTransport, e.message)
-
- self.config.writeMethodEnd()
-
- self.run()
-
- def launchClient(self, name, port):
- if name!=self.supportedTransport:
- raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
-
- client=DummyClient()
- self.handler.setTransport(client)
- add_service(Service(self.handler, port=port))
-
-if __name__=='__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- server=ManagedClient()
+
+ def __init__(self):
+ try:
+ Daemon.__init__(self, ClientConfig(), SocksHandler())
+ except EnvException:
+ print 'error 0'
+ return
+ except UnsupportedManagedTransportVersionException:
+ print 'error 1'
+ return
+ except NoSupportedTransportsException:
+ print 'error 2'
+ return
+
+ try:
+ self.launchClient(self.supportedTransport, 8182)
+ self.config.writeMethod(self.supportedTransport, 5,
+ ('127.0.0.1', 8182), None, None)
+ except TransportLaunchException, e:
+ print 'error 3'
+ self.config.writeMethodError(self.supportedTransport,
+ e.message)
+
+ self.config.writeMethodEnd()
+
+ self.run()
+
+ def launchClient(self, name, port):
+ if name != self.supportedTransport:
+ raise TransportLaunchException('Tried to launch unsupported transport %s'
+ % name)
+
+ client = DummyClient()
+ self.handler.setTransport(client)
+ add_service(Service(self.handler, port=port))
+
+
+if __name__ == '__main__':
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ server = ManagedClient()
diff --git a/src/obfsproxy/framework/external/server.py b/src/obfsproxy/framework/external/server.py
index d397050..61c0d1b 100755
--- a/src/obfsproxy/framework/external/server.py
+++ b/src/obfsproxy/framework/external/server.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python -u
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
import sys
@@ -23,40 +24,47 @@ from pyptlib.framework.proxy import ProxyHandler
from pyptlib.transports.dummy import DummyServer
+
class ManagedServer(Daemon):
- def __init__(self):
- try:
- Daemon.__init__(self, ServerConfig(), ProxyHandler())
- except EnvException:
- print('error 0')
- return
- except UnsupportedManagedTransportVersionException:
- print('error 1')
- return
- except NoSupportedTransportsException:
- print('error 2')
- return
-
- try:
- self.launchServer(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport, ('127.0.0.1', 8182), MethodOptions())
- except TransportLaunchException as e:
- print('error 3')
- self.config.writeMethodError(self.supportedTransport, e.message)
-
- self.config.writeMethodEnd()
-
- self.run()
-
- def launchServer(self, name, port):
- if name!=self.supportedTransport:
- raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
-
- client=DummyServer()
- self.handler.setTransport(client)
- add_service(Service(self.handler, port=port))
-
-if __name__=='__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- server=ManagedServer()
+
+ def __init__(self):
+ try:
+ Daemon.__init__(self, ServerConfig(), ProxyHandler())
+ except EnvException:
+ print 'error 0'
+ return
+ except UnsupportedManagedTransportVersionException:
+ print 'error 1'
+ return
+ except NoSupportedTransportsException:
+ print 'error 2'
+ return
+
+ try:
+ self.launchServer(self.supportedTransport, 8182)
+ self.config.writeMethod(self.supportedTransport,
+ ('127.0.0.1', 8182),
+ MethodOptions())
+ except TransportLaunchException, e:
+ print 'error 3'
+ self.config.writeMethodError(self.supportedTransport,
+ e.message)
+
+ self.config.writeMethodEnd()
+
+ self.run()
+
+ def launchServer(self, name, port):
+ if name != self.supportedTransport:
+ raise TransportLaunchException('Tried to launch unsupported transport %s'
+ % name)
+
+ client = DummyServer()
+ self.handler.setTransport(client)
+ add_service(Service(self.handler, port=port))
+
+
+if __name__ == '__main__':
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ server = ManagedServer()
diff --git a/src/obfsproxy/framework/loopback.py b/src/obfsproxy/framework/loopback.py
index ecdb4d3..38ef29f 100644
--- a/src/obfsproxy/framework/loopback.py
+++ b/src/obfsproxy/framework/loopback.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import monocle
from monocle import _o
monocle.init('tornado')
@@ -8,57 +10,61 @@ from monocle.stack import eventloop
from monocle.stack.network import Connection, ConnectionLost
from monocle.experimental import Channel
-buffsize=1024
+buffsize = 1024
+
class FakeSocket(object):
- def __init__(self, a=None, b=None):
- if a==None:
- self.a=Channel(buffsize)
- else:
- self.a=a
- if b==None:
- self.b=Channel(buffsize)
- else:
- self.b=b
-
- self.inBuff=b''
- self.outBuff=b''
-
- def invert(self):
- return FakeSocket(a=self.b, b=self.a)
-
- @_o
- def read(self, x):
- while len(self.inBuff)<x:
- data=yield self.a.recv()
- if data:
- self.inBuff=self.inBuff+data
- else:
- yield ConnectionLost()
-
- data=self.inBuff[:x]
- self.inBuff=self.inBuff[x:]
-
- yield Return(data)
-
- @_o
- def read_some(self):
- if len(self.inBuff)>0:
- data=self.inBuff
- self.inBuff=b''
- yield Return(data)
- else:
- data=b''
- while len(data)==0:
- data=yield self.a.recv()
- if data:
+
+ def __init__(self, a=None, b=None):
+ if a == None:
+ self.a = Channel(buffsize)
+ else:
+ self.a = a
+ if b == None:
+ self.b = Channel(buffsize)
+ else:
+ self.b = b
+
+ self.inBuff = ''
+ self.outBuff = ''
+
+ def invert(self):
+ return FakeSocket(a=self.b, b=self.a)
+
+ @_o
+ def read(self, x):
+ while len(self.inBuff) < x:
+ data = (yield self.a.recv())
+ if data:
+ self.inBuff = self.inBuff + data
+ else:
+ yield ConnectionLost()
+
+ data = self.inBuff[:x]
+ self.inBuff = self.inBuff[x:]
+
yield Return(data)
- else:
- yield ConnectionLost()
- @_o
- def write(self, bs):
- yield self.b.send(bs)
+ @_o
+ def read_some(self):
+ if len(self.inBuff) > 0:
+ data = self.inBuff
+ self.inBuff = ''
+ yield Return(data)
+ else:
+ data = ''
+ while len(data) == 0:
+ data = (yield self.a.recv())
+ if data:
+ yield Return(data)
+ else:
+ yield ConnectionLost()
+
+ @_o
+ def write(self, bs):
+ yield self.b.send(bs)
+
+ def close(self):
+ yield self.b.send(None)
+
- def close(self):
- yield self.b.send(None)
diff --git a/src/obfsproxy/framework/managed/__init__.py b/src/obfsproxy/framework/managed/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/framework/managed/__init__.py
+++ b/src/obfsproxy/framework/managed/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index 8326ceb..50beb8a 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python -u
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
import sys
@@ -13,7 +14,8 @@ from monocle import _o, Return
monocle.init('tornado')
from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service, Client, ConnectionLost
+from monocle.stack.network import add_service, Service, Client, \
+ ConnectionLost
from pyptlib.framework.loopback import FakeSocket
from pyptlib.framework.socks import SocksHandler
@@ -24,40 +26,46 @@ from pyptlib.framework.daemon import *
from pyptlib.transports.dummy import DummyClient
+
class ManagedClient(Daemon):
- def __init__(self):
- try:
- Daemon.__init__(self, ClientConfig(), SocksHandler())
- except EnvException:
- print('error 0')
- return
- except UnsupportedManagedTransportVersionException:
- print('error 1')
- return
- except NoSupportedTransportsException:
- print('error 2')
- return
-
- try:
- self.launchClient(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport, 5, ('127.0.0.1', 8182), None, None)
- except TransportLaunchException as e:
- print('error 3')
- self.config.writeMethodError(self.supportedTransport, e.message)
-
- self.config.writeMethodEnd()
-
- self.run()
-
- def launchClient(self, name, port):
- if name!=self.supportedTransport:
- raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
-
- client=DummyClient()
- self.handler.setTransport(client)
- add_service(Service(self.handler, port=port))
-
-if __name__=='__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- server=ManagedClient()
+
+ def __init__(self):
+ try:
+ Daemon.__init__(self, ClientConfig(), SocksHandler())
+ except EnvException:
+ print 'error 0'
+ return
+ except UnsupportedManagedTransportVersionException:
+ print 'error 1'
+ return
+ except NoSupportedTransportsException:
+ print 'error 2'
+ return
+
+ try:
+ self.launchClient(self.supportedTransport, 8182)
+ self.config.writeMethod(self.supportedTransport, 5,
+ ('127.0.0.1', 8182), None, None)
+ except TransportLaunchException, e:
+ print 'error 3'
+ self.config.writeMethodError(self.supportedTransport,
+ e.message)
+
+ self.config.writeMethodEnd()
+
+ self.run()
+
+ def launchClient(self, name, port):
+ if name != self.supportedTransport:
+ raise TransportLaunchException('Tried to launch unsupported transport %s'
+ % name)
+
+ client = DummyClient()
+ self.handler.setTransport(client)
+ add_service(Service(self.handler, port=port))
+
+
+if __name__ == '__main__':
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ server = ManagedClient()
diff --git a/src/obfsproxy/framework/managed/server.py b/src/obfsproxy/framework/managed/server.py
index d397050..61c0d1b 100755
--- a/src/obfsproxy/framework/managed/server.py
+++ b/src/obfsproxy/framework/managed/server.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python -u
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
import sys
@@ -23,40 +24,47 @@ from pyptlib.framework.proxy import ProxyHandler
from pyptlib.transports.dummy import DummyServer
+
class ManagedServer(Daemon):
- def __init__(self):
- try:
- Daemon.__init__(self, ServerConfig(), ProxyHandler())
- except EnvException:
- print('error 0')
- return
- except UnsupportedManagedTransportVersionException:
- print('error 1')
- return
- except NoSupportedTransportsException:
- print('error 2')
- return
-
- try:
- self.launchServer(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport, ('127.0.0.1', 8182), MethodOptions())
- except TransportLaunchException as e:
- print('error 3')
- self.config.writeMethodError(self.supportedTransport, e.message)
-
- self.config.writeMethodEnd()
-
- self.run()
-
- def launchServer(self, name, port):
- if name!=self.supportedTransport:
- raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
-
- client=DummyServer()
- self.handler.setTransport(client)
- add_service(Service(self.handler, port=port))
-
-if __name__=='__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- server=ManagedServer()
+
+ def __init__(self):
+ try:
+ Daemon.__init__(self, ServerConfig(), ProxyHandler())
+ except EnvException:
+ print 'error 0'
+ return
+ except UnsupportedManagedTransportVersionException:
+ print 'error 1'
+ return
+ except NoSupportedTransportsException:
+ print 'error 2'
+ return
+
+ try:
+ self.launchServer(self.supportedTransport, 8182)
+ self.config.writeMethod(self.supportedTransport,
+ ('127.0.0.1', 8182),
+ MethodOptions())
+ except TransportLaunchException, e:
+ print 'error 3'
+ self.config.writeMethodError(self.supportedTransport,
+ e.message)
+
+ self.config.writeMethodEnd()
+
+ self.run()
+
+ def launchServer(self, name, port):
+ if name != self.supportedTransport:
+ raise TransportLaunchException('Tried to launch unsupported transport %s'
+ % name)
+
+ client = DummyServer()
+ self.handler.setTransport(client)
+ add_service(Service(self.handler, port=port))
+
+
+if __name__ == '__main__':
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ server = ManagedServer()
diff --git a/src/obfsproxy/framework/proxy.py b/src/obfsproxy/framework/proxy.py
index 68d9a16..d518033 100644
--- a/src/obfsproxy/framework/proxy.py
+++ b/src/obfsproxy/framework/proxy.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
from struct import unpack
from socket import inet_ntoa
@@ -8,20 +10,23 @@ from pyptlib.util import encode
from pyptlib.framework.shared import pump
+
class ProxyHandler:
- transport=None
- def setTransport(self, transport):
- self.transport=transport
+ transport = None
+
+ def setTransport(self, transport):
+ self.transport = transport
+
+ @_o
+ def handle(self, conn):
+ print 'connection'
+ client = Client()
+ yield client.connect('blanu.net', 7051)
- @_o
- def handle(self, conn):
- print('connection')
- client = Client()
- yield client.connect('blanu.net', 7051)
+ coder = (yield handshake(client))
- coder=yield handshake(client)
+ monocle.launch(pump, conn, client, coder.encrypt)
+ yield pump(client, conn, coder.decrypt)
- monocle.launch(pump, conn, client, coder.encrypt)
- yield pump(client, conn, coder.decrypt)
diff --git a/src/obfsproxy/framework/shared.py b/src/obfsproxy/framework/shared.py
index 274b825..488914e 100644
--- a/src/obfsproxy/framework/shared.py
+++ b/src/obfsproxy/framework/shared.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import monocle
from monocle import _o, Return
@@ -5,43 +7,53 @@ from monocle.stack.network import ConnectionLost
from pyptlib.util import encode
+
@_o
-def pump(input, output, transform, debug=False):
- while True:
- try:
- message = yield input.read_some()
+def pump(
+ input,
+ output,
+ transform,
+ debug=False,
+ ):
+ while True:
+ try:
+ message = (yield input.read_some())
+
# message=yield input.read(1)
- if not message or len(message)==0:
- print('0 from '+str(input)+' '+str(type(message)))
- raise(Exception())
+
+ if not message or len(message) == 0:
+ print '0 from ' + str(input) + ' ' + str(type(message))
+ raise Exception()
+
# message=yield input.read(1)
- if debug:
- print('receive '+str(len(message)))
- except ConnectionLost:
- print('Client connection closed')
- output.close()
- break
- except IOError:
- output.close()
- break
-
- if transform:
- message=yield transform(message)
-
- if debug:
- print('sending '+str(len(message)))
- try:
- yield output.write(message)
- except ConnectionLost:
- print('Connection lost')
- input.close()
- return
- except IOError:
- print('IOError')
- input.close()
- return
- except Exception, e:
- print('Exception')
- print(e)
- input.close()
- return
+
+ if debug:
+ print 'receive ' + str(len(message))
+ except ConnectionLost:
+ print 'Client connection closed'
+ output.close()
+ break
+ except IOError:
+ output.close()
+ break
+
+ if transform:
+ message = (yield transform(message))
+
+ if debug:
+ print 'sending ' + str(len(message))
+ try:
+ yield output.write(message)
+ except ConnectionLost:
+ print 'Connection lost'
+ input.close()
+ return
+ except IOError:
+ print 'IOError'
+ input.close()
+ return
+ except Exception, e:
+ print 'Exception'
+ print e
+ input.close()
+ return
diff --git a/src/obfsproxy/framework/socks.py b/src/obfsproxy/framework/socks.py
index c5659f0..5070e25 100644
--- a/src/obfsproxy/framework/socks.py
+++ b/src/obfsproxy/framework/socks.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
from struct import unpack
from socket import inet_ntoa
@@ -8,64 +10,73 @@ from pyptlib.util import encode
from pyptlib.framework.shared import pump
+
def uncompact(x):
- ip, port = unpack("!4sH", x)
- return inet_ntoa(ip), port
+ (ip, port) = unpack('!4sH', x)
+ return (inet_ntoa(ip), port)
+
@_o
def readHandshake(input):
- version=yield input.read(1)
- print('version: '+encode(str(version)))
- nauth=yield input.read(1)
- nauth=unpack('B', nauth)[0]
- auths=[]
- for x in range(nauth):
- auth=yield input.read(1)
- auth=unpack('B', auth)[0]
- auths.append(auth)
+ version = (yield input.read(1))
+ print 'version: ' + encode(str(version))
+ nauth = (yield input.read(1))
+ nauth = unpack('B', nauth)[0]
+ auths = []
+ for x in range(nauth):
+ auth = (yield input.read(1))
+ auth = unpack('B', auth)[0]
+ auths.append(auth)
+
@_o
def sendHandshake(output):
- yield output.write(b"\x05\x00")
+ yield output.write('\x05\x00')
+
@_o
def readRequest(input):
- version=yield input.read(1)
- command=yield input.read(1)
- reserved=yield input.read(1)
- addrtype=yield input.read(1)
- dest=yield input.read(6)
+ version = (yield input.read(1))
+ command = (yield input.read(1))
+ reserved = (yield input.read(1))
+ addrtype = (yield input.read(1))
+ dest = (yield input.read(6))
+
+ yield Return(dest)
- yield Return(dest)
@_o
def sendResponse(dest, output):
- yield output.write(b"\x05\x00\x00\x01"+dest)
+ yield output.write('\x05\x00\x00\x01' + dest)
+
class SocksHandler:
- transport=None
-
- def setTransport(self, transport):
- self.transport=transport
-
- @_o
- def handle(self, conn):
- print('handle_socks')
- yield readHandshake(conn)
- print('read handshake')
- yield sendHandshake(conn)
- print('send handshake')
- dest=yield readRequest(conn)
- print('read request: '+str(dest))
- yield sendResponse(dest, conn)
- print('sent response')
-
- addr, port=uncompact(dest)
- print(addr)
- print(port)
-
- client = Client()
- yield client.connect(addr, port)
- print('connected '+str(addr)+', '+str(port))
- monocle.launch(pump, conn, client, None)
- yield pump(client, conn, None)
+
+ transport = None
+
+ def setTransport(self, transport):
+ self.transport = transport
+
+ @_o
+ def handle(self, conn):
+ print 'handle_socks'
+ yield readHandshake(conn)
+ print 'read handshake'
+ yield sendHandshake(conn)
+ print 'send handshake'
+ dest = (yield readRequest(conn))
+ print 'read request: ' + str(dest)
+ yield sendResponse(dest, conn)
+ print 'sent response'
+
+ (addr, port) = uncompact(dest)
+ print addr
+ print port
+
+ client = Client()
+ yield client.connect(addr, port)
+ print 'connected ' + str(addr) + ', ' + str(port)
+ monocle.launch(pump, conn, client, None)
+ yield pump(client, conn, None)
+
+
diff --git a/src/obfsproxy/manager/__init__.py b/src/obfsproxy/manager/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/manager/__init__.py
+++ b/src/obfsproxy/manager/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/manager/clientManager.py b/src/obfsproxy/manager/clientManager.py
index 2846ab1..6d51d9b 100644
--- a/src/obfsproxy/manager/clientManager.py
+++ b/src/obfsproxy/manager/clientManager.py
@@ -1,14 +1,19 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
from pyptlib.manager.manager import Manager
+
class ClientManager(Manager):
- def __init__(self):
- Manager.__init__(self)
- os.environ['TOR_PT_CLIENT_TRANSPORTS']='dummy'
+ def __init__(self):
+ Manager.__init__(self)
+
+ os.environ['TOR_PT_CLIENT_TRANSPORTS'] = 'dummy'
+
-if __name__=='__main__':
- manager=ClientManager()
- manager.launch('src/pyptlib/framework/client.py')
+if __name__ == '__main__':
+ manager = ClientManager()
+ manager.launch('src/pyptlib/framework/client.py')
diff --git a/src/obfsproxy/manager/manager.py b/src/obfsproxy/manager/manager.py
index b5f0ee9..869e11f 100644
--- a/src/obfsproxy/manager/manager.py
+++ b/src/obfsproxy/manager/manager.py
@@ -1,17 +1,24 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
import sys
import subprocess
+
class Manager:
- def __init__(self):
- os.environ['TOR_PT_STATE_LOCATION']='/'
- os.environ['TOR_PT_MANAGED_TRANSPORT_VER']='1'
- def launch(self, path):
- p=subprocess.Popen(['python', '-u', path], stdout=subprocess.PIPE)
- line=p.stdout.readline().strip()
- while line!=None and line !='':
- print(str(line))
- sys.stdout.flush()
- line=p.stdout.readline().strip()
- print('Done!')
+ def __init__(self):
+ os.environ['TOR_PT_STATE_LOCATION'] = '/'
+ os.environ['TOR_PT_MANAGED_TRANSPORT_VER'] = '1'
+
+ def launch(self, path):
+ p = subprocess.Popen(['python', '-u', path],
+ stdout=subprocess.PIPE)
+ line = p.stdout.readline().strip()
+ while line != None and line != '':
+ print str(line)
+ sys.stdout.flush()
+ line = p.stdout.readline().strip()
+ print 'Done!'
+
+
diff --git a/src/obfsproxy/manager/serverManager.py b/src/obfsproxy/manager/serverManager.py
index a82b5b5..a3a3efe 100644
--- a/src/obfsproxy/manager/serverManager.py
+++ b/src/obfsproxy/manager/serverManager.py
@@ -1,16 +1,21 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
import os
from pyptlib.manager.manager import Manager
+
class ServerManager(Manager):
- def __init__(self):
- Manager.__init__(self)
- os.environ['TOR_PT_EXTENDED_SERVER_PORT']='127.0.0.1:22211'
- os.environ['TOR_PT_ORPORT']='127.0.0.1:43210'
- os.environ['TOR_PT_SERVER_BINDADDR']='dummy-127.0.0.1:46466'
- os.environ['TOR_PT_SERVER_TRANSPORTS']='dummy'
+ def __init__(self):
+ Manager.__init__(self)
+
+ os.environ['TOR_PT_EXTENDED_SERVER_PORT'] = '127.0.0.1:22211'
+ os.environ['TOR_PT_ORPORT'] = '127.0.0.1:43210'
+ os.environ['TOR_PT_SERVER_BINDADDR'] = 'dummy-127.0.0.1:46466'
+ os.environ['TOR_PT_SERVER_TRANSPORTS'] = 'dummy'
+
-if __name__=='__main__':
- manager=ServerManager()
- manager.launch('src/pyptlib/framework/server.py')
+if __name__ == '__main__':
+ manager = ServerManager()
+ manager.launch('src/pyptlib/framework/server.py')
diff --git a/src/obfsproxy/transports/__init__.py b/src/obfsproxy/transports/__init__.py
index e69de29..836e3e8 100644
--- a/src/obfsproxy/transports/__init__.py
+++ b/src/obfsproxy/transports/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
diff --git a/src/obfsproxy/transports/dummy.py b/src/obfsproxy/transports/dummy.py
index 06473f5..6921704 100644
--- a/src/obfsproxy/transports/dummy.py
+++ b/src/obfsproxy/transports/dummy.py
@@ -1,14 +1,22 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+
class DummyClient:
- def encode(self, data):
- return data
- def decode(self, data):
- return data
+ def encode(self, data):
+ return data
+
+ def decode(self, data):
+ return data
+
class DummyServer:
- def encode(self, data):
- return data
- def decode(self, data):
- return data
+ def encode(self, data):
+ return data
+
+ def decode(self, data):
+ return data
+
diff --git a/src/obfsproxy/transports/rot13.py b/src/obfsproxy/transports/rot13.py
index afe2256..15f32b1 100644
--- a/src/obfsproxy/transports/rot13.py
+++ b/src/obfsproxy/transports/rot13.py
@@ -1,22 +1,35 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+
def rot13(data):
- for x in range(len(data)):
- ascii=ord(data[x])
- if ascii>=97 and ascii<=122: # a-z
- data[x]=(((ascii-97)+13)%26)+97
- elif ascii>=65 and ascii<=90: # A-Z
- data[x]=(((ascii-65)+13)%26)+65
- return data
+ for x in range(len(data)):
+ ascii = ord(data[x])
+ if ascii >= 97 and ascii <= 122: # a-z
+ data[x] = (ascii - 97 + 13) % 26 + 97
+ elif ascii >= 65 and ascii <= 90:
+
+ # A-Z
+
+ data[x] = (ascii - 65 + 13) % 26 + 65
+ return data
+
class Rot13Client:
- def encode(self, data):
- return rot13(data)
- def decode(self, data):
- return rot13(data)
+ def encode(self, data):
+ return rot13(data)
+
+ def decode(self, data):
+ return rot13(data)
+
class Rot13Server:
- def encode(self, data):
- return rot13(data)
- def decode(self, data):
- return rot13(data)
+ def encode(self, data):
+ return rot13(data)
+
+ def decode(self, data):
+ return rot13(data)
+
+
diff --git a/src/obfsproxy/util.py b/src/obfsproxy/util.py
index e307e5c..ced88b1 100644
--- a/src/obfsproxy/util.py
+++ b/src/obfsproxy/util.py
@@ -1,3 +1,6 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
import re
import sys
import binascii
@@ -5,131 +8,155 @@ import binascii
from struct import pack, unpack
from socket import inet_aton, inet_ntoa
-v3=(sys.version[0]=='3')
+v3 = sys.version[0] == '3'
+
def uncompact(x):
- ip, port = unpack("!4sH", x)
- return inet_ntoa(ip), port
+ (ip, port) = unpack('!4sH', x)
+ return (inet_ntoa(ip), port)
+
def encode(s):
- return binascii.hexlify(s).decode('ascii')
+ return binascii.hexlify(s).decode('ascii')
+
def decode(s):
- return binascii.unhexlify(s.encode('ascii'))
+ return binascii.unhexlify(s.encode('ascii'))
+
def encodeAddress(addr):
- ip=addr[0]
- if ip=='':
- ip='::'
- port=addr[1]
- if '.' in ip:
- return ip+':'+str(port)
- else:
- return '['+ip+']:'+str(port)
+ ip = addr[0]
+ if ip == '':
+ ip = '::'
+ port = addr[1]
+ if '.' in ip:
+ return ip + ':' + str(port)
+ else:
+ return '[' + ip + ']:' + str(port)
+
def decodeAddress(s):
- if '.' in s:
- parts=s.split(':')
- return (parts[0], int(parts[1]), False)
- else:
- m=re.match('\[([0-9a-f:]+)\]:([0-9]+)', s)
- return (m.group(1), int(m.group(2)), True)
+ if '.' in s:
+ parts = s.split(':')
+ return (parts[0], int(parts[1]), False)
+ else:
+ m = re.match('\[([0-9a-f:]+)\]:([0-9]+)', s)
+ return (m.group(1), int(m.group(2)), True)
+
def getAddress(port):
- return encodeAddress((getPublicIP(), port))
+ return encodeAddress((getPublicIP(), port))
+
def splitFields(msg, fields, optionalData=False):
- values=[]
- for field in fields:
- value=msg[:field]
- msg=msg[field:]
- values.append(value)
- if len(msg)>0:
- values.append(msg)
- elif optionalData:
- values.append(None)
- return values
+ values = []
+ for field in fields:
+ value = msg[:field]
+ msg = msg[field:]
+ values.append(value)
+ if len(msg) > 0:
+ values.append(msg)
+ elif optionalData:
+ values.append(None)
+ return values
+
def splitField(msg, field):
- return msg[:field], msg[field:]
+ return (msg[:field], msg[field:])
+
def decodeFlags(flagsByte):
- from bitstring import BitString
- bits=BitString(bytes=flagsByte)
- bools=[]
- for x in range(bits.length):
- bools.append(bits.readbit().uint==1)
- return bools
+ from bitstring import BitString
+ bits = BitString(bytes=flagsByte)
+ bools = []
+ for x in range(bits.length):
+ bools.append(bits.readbit().uint == 1)
+ return bools
+
def encodeFlags(bools):
- from bitstring import BitString
- bits=BitString()
- for bool in bools:
- if bool:
- bits.append(BitString('0b1'))
- else:
- bits.append(BitString('0b0'))
- return bits.bytes
+ from bitstring import BitString
+ bits = BitString()
+ for bool in bools:
+ if bool:
+ bits.append(BitString('0b1'))
+ else:
+ bits.append(BitString('0b0'))
+ return bits.bytes
+
def fill(bs, size):
- while len(bs)<size:
+ while len(bs) < size:
+ if v3:
+ filler = bytes('\x00', 'ascii')
+ else:
+ filler = '\x00'
+ bs = bs + filler
+ return bs
+
+
+def xor(a, b):
+ if len(a) != len(b):
+ print ('xor parameters must be the same length:', len(a),
+ len(b))
+ return None
if v3:
- filler=bytes('\x00', 'ascii')
+ c = bytearray()
+ for x in range(len(a)):
+ c.append(a[x] ^ b[x])
+ return bytes(c)
else:
- filler='\x00'
- bs=bs+filler
- return bs
+ c = ''
+ for x in range(len(a)):
+ c = c + chr(ord(a[x]) ^ ord(b[x]))
+ return c
-def xor(a, b):
- if len(a)!=len(b):
- print('xor parameters must be the same length:', len(a), len(b))
- return None
- if v3:
- c=bytearray()
- for x in range(len(a)):
- c.append(a[x] ^ b[x])
- return bytes(c)
- else:
- c=''
- for x in range(len(a)):
- c=c+chr(ord(a[x]) ^ ord(b[x]))
- return c
if v3:
- from urllib.request import urlopen
+ from urllib.request import urlopen
else:
- from urllib2 import urlopen
+ from urllib2 import urlopen
+
def getPublicIP(v6=True):
- if v6:
+ if v6:
+
# try:
- text=urlopen("http://ipv6.ip6.me/").read()
- if v3:
- match=re.search(bytes("\+3>([^<]+)<", 'ascii'), text)
- else:
- match=re.search("\+3>([^<]+)<", text)
- ip=match.group(1)
- ip=ip.decode('ascii')
- return ip
+
+ text = urlopen('http://ipv6.ip6.me/').read()
+ if v3:
+ match = re.search(bytes("\+3>([^<]+)<", 'ascii'), text)
+ else:
+ match = re.search("\+3>([^<]+)<", text)
+ ip = match.group(1)
+ ip = ip.decode('ascii')
+ return ip
+ else:
+
# except Exception as e:
# print(e)
# ip=urlopen("http://whatismyv6ip.com/myip").read()
# return ip.decode('ascii')
- else:
- text=urlopen("http://ip4.me/").read()
- if v3:
- match=re.search(bytes("\+3>([^<]+)<", 'ascii'), text)
- else:
- match=re.search("\+3>([^<]+)<", text)
+
+ text = urlopen('http://ip4.me/').read()
+ if v3:
+ match = re.search(bytes("\+3>([^<]+)<", 'ascii'), text)
+ else:
+ match = re.search("\+3>([^<]+)<", text)
+
# ip=urlopen("http://whatismyv6ip.com/myip").read()
# return ip.decode('ascii')
- ip=match.group(1)
- ip=ip.decode('ascii')
- return ip
+
+ ip = match.group(1)
+ ip = ip.decode('ascii')
+ return ip
+
def randomPort():
- import random
- minPort=5000
- maxPort=10000
- port=random.randint(minPort, maxPort)
- return port
+ import random
+ minPort = 5000
+ maxPort = 10000
+ port = random.randint(minPort, maxPort)
+ return port
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git
More information about the Pkg-privacy-commits
mailing list