[Pkg-privacy-commits] [obfsproxy] 129/353: Add a transport method to parse SOCKS arguments.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:50 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 1ba7d90c27fb576aff2d958aca846ae6a6c88e00
Author: George Kadianakis <desnacked at riseup.net>
Date: Tue Mar 5 00:53:31 2013 +0200
Add a transport method to parse SOCKS arguments.
---
obfsproxy/network/socks.py | 38 ++++++++++++++++++++++++++++++++++++++
obfsproxy/test/test_socks.py | 18 ++++++++++++++++++
obfsproxy/transports/base.py | 8 ++++++++
3 files changed, 64 insertions(+)
diff --git a/obfsproxy/network/socks.py b/obfsproxy/network/socks.py
index 8271837..2ecd098 100644
--- a/obfsproxy/network/socks.py
+++ b/obfsproxy/network/socks.py
@@ -1,11 +1,22 @@
+import csv
+
from twisted.protocols import socks
from twisted.internet.protocol import Factory
import obfsproxy.common.log as logging
import obfsproxy.network.network as network
+import obfsproxy.transports.base as base
log = logging.get_obfslogger()
+def split_socks_args(args_str):
+ """
+ Given a string containing the SOCKS arguments (delimited by
+ semicolons, and with semicolons and backslashes escaped), parse it
+ and return a list of the unescaped SOCKS arguments.
+ """
+ return csv.reader([args_str], delimiter=';', escapechar='\\').next()
+
class MySOCKSv4Outgoing(socks.SOCKSv4Outgoing, network.GenericProtocol):
"""
Represents a downstream connection from the SOCKS server to the
@@ -106,6 +117,33 @@ class SOCKSv4Protocol(socks.SOCKSv4, network.GenericProtocol):
self.circuit.dataReceived(self.buffer, self)
+ def authorize(self, code, server, port, user):
+ """
+ (Overriden)
+ Accept or reject a SOCKS client that wants to connect to
+ 'server':'port', with the SOCKS4 username 'user'.
+ """
+
+ if not user: # No SOCKS arguments were specified.
+ return True
+
+ # If the client sent us SOCKS arguments, we must parse them
+ # and send them to the appropriate transport.
+ log.debug("Got '%s' as SOCKS arguments." % user)
+
+ try:
+ socks_args = split_socks_args(user)
+ except csv.Error, err:
+ log.warning("split_socks_args failed (%s)" % str(err))
+ return False
+
+ try:
+ self.circuit.transport.handle_socks_args(socks_args)
+ except base.SOCKSArgsError:
+ return False # Transports should log the issue themselves
+
+ return True
+
def connectionLost(self, reason):
network.GenericProtocol.connectionLost(self, reason)
diff --git a/obfsproxy/test/test_socks.py b/obfsproxy/test/test_socks.py
new file mode 100644
index 0000000..e8fb855
--- /dev/null
+++ b/obfsproxy/test/test_socks.py
@@ -0,0 +1,18 @@
+import obfsproxy.network.socks as socks
+
+import twisted.trial.unittest
+
+class test_SOCKS(twisted.trial.unittest.TestCase):
+ def test_socks_args_splitting(self):
+ socks_args = socks.split_socks_args("monday=blue;tuesday=grey;wednesday=too;thursday=don\\;tcareabout\\\\you;friday=i\\;minlove")
+ self.assertListEqual(socks_args, ["monday=blue", "tuesday=grey", "wednesday=too", "thursday=don;tcareabout\\you", "friday=i;minlove"])
+
+ socks_args = socks.split_socks_args("monday=blue")
+ self.assertListEqual(socks_args, ["monday=blue"])
+
+ socks_args = socks.split_socks_args("monday=;tuesday=grey")
+ self.assertListEqual(socks_args, ["monday=", "tuesday=grey"])
+
+ socks_args = socks.split_socks_args("\\;=\\;;\\\\=\\;")
+ self.assertListEqual(socks_args, [";=;", "\\=;"])
+
diff --git a/obfsproxy/transports/base.py b/obfsproxy/transports/base.py
index 5b2c8a4..6cbb0ce 100644
--- a/obfsproxy/transports/base.py
+++ b/obfsproxy/transports/base.py
@@ -61,6 +61,13 @@ class BaseTransport(object):
"""
pass
+ def handle_socks_args(self, args):
+ """
+ 'args' is a list of k=v strings that serve as configuration
+ parameters to the pluggable transport.
+ """
+ pass
+
@classmethod
def register_external_mode_cli(cls, subparser):
"""
@@ -104,3 +111,4 @@ class BaseTransport(object):
return True
class PluggableTransportError(Exception): pass
+class SOCKSArgsError(Exception): pass
--
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