[Pkg-privacy-commits] [pyptlib] 59/136: Add support for TOR_PT_AUTH_COOKIE_FILE.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository pyptlib.
commit f3c8ea38109f2eee713b19646d97fcbb8d839401
Author: George Kadianakis <desnacked at riseup.net>
Date: Sat Nov 24 14:38:05 2012 +0200
Add support for TOR_PT_AUTH_COOKIE_FILE.
---
pyptlib/server.py | 18 +++++++++--------
pyptlib/server_config.py | 19 ++++++++++++++++++
pyptlib/test/test_server.py | 48 ++++++++++++++++++++++++++++++++++++++++-----
sphinx/API.rst | 17 ++++++++--------
4 files changed, 81 insertions(+), 21 deletions(-)
diff --git a/pyptlib/server.py b/pyptlib/server.py
index 3ccfb6f..05b03e6 100644
--- a/pyptlib/server.py
+++ b/pyptlib/server.py
@@ -19,14 +19,15 @@ def init(supported_transports):
:returns: dictionary that contains information for the application:
- ========== ========== ==========
- Key Type Value
- ========== ========== ==========
- state_loc string Directory where the managed proxy should dump its state files (if needed).
- orport tuple (ip,port) tuple pointing to Tor's ORPort.
- ext_orport tuple (ip,port) tuple pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
- transports dict A dictionary 'transport => (ip,port)' where 'transport' is the name of the transport that should be spawned, and '(ip,port)' is the location where the transport should bind. The dictionary can be empty.
- ========== ========== ==========
+ =============== ========== ==========
+ Key Type Value
+ ================ ========== ==========
+ state_loc string Directory where the managed proxy should dump its state files (if needed).
+ orport tuple (ip,port) tuple pointing to Tor's ORPort.
+ ext_orport tuple (ip,port) tuple pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
+ transports dict A dictionary 'transport => (ip,port)' where 'transport' is the name of the transport that should be spawned, and '(ip,port)' is the location where the transport should bind. The dictionary can be empty.
+ auth_cookie_file string Directory where the managed proxy should find the Extended ORPort authentication cookie.
+ ================ ========== ==========
:raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
"""
@@ -47,6 +48,7 @@ def init(supported_transports):
retval['orport'] = config.getORPort()
retval['ext_orport'] = config.getExtendedORPort()
retval['transports'] = _getTransportsDict(supported_transports, config)
+ retval['auth_cookie_file'] = config.getAuthCookieFile()
return retval
diff --git a/pyptlib/server_config.py b/pyptlib/server_config.py
index 233f987..06c4fe1 100644
--- a/pyptlib/server_config.py
+++ b/pyptlib/server_config.py
@@ -14,6 +14,7 @@ class ServerConfig(config.Config):
:var tuple ORPort: (ip,port) pointing to Tor's ORPort.
:var tuple extendedORPort: (ip,port) pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
:var dict serverBindAddr: A dictionary {<transport> : [<addr>, <port>]}, where <transport> is the name of the transport that must be spawned, and [<addr>, <port>] is a list containing the location where that transport should bind. The dictionary can be empty.
+ :var string authCookieFile: String representing the filesystem path where the Extended ORPort Authentication cookie is stored. None if Extended ORPort authentication is not supported.
:raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
"""
@@ -31,6 +32,18 @@ class ServerConfig(config.Config):
else:
self.extendedORPort = self.get_addrport('TOR_PT_EXTENDED_SERVER_PORT')
+ if self.check('TOR_PT_AUTH_COOKIE_FILE'):
+ self.authCookieFile = self.get('TOR_PT_AUTH_COOKIE_FILE')
+ else:
+ self.authCookieFile = None
+
+ # Check that either both Extended ORPort and the Extended
+ # ORPort Authentication Cookie are present, or neither.
+ if self.extendedORPort and not self.authCookieFile:
+ raise config.EnvError("Extended ORPort address provided, but no cookie file.")
+ elif self.authCookieFile and not self.extendedORPort:
+ raise config.EnvError("Extended ORPort Authentication cookie file provided, but no Extended ORPort address.")
+
# Get ORPort.
self.ORPort = self.get_addrport('TOR_PT_ORPORT')
@@ -75,6 +88,12 @@ class ServerConfig(config.Config):
"""
return self.transports
+ def getAuthCookieFile(self):
+ """
+ :returns: :attr:`pyptlib.server_config.ServerConfig.authCookieFile`
+ """
+ return self.authCookieFile
+
def writeMethod(self, name, addrport, options):
"""
Write a message to stdout announcing that a server transport was
diff --git a/pyptlib/test/test_server.py b/pyptlib/test/test_server.py
index 3838ebc..e5896e8 100644
--- a/pyptlib/test/test_server.py
+++ b/pyptlib/test/test_server.py
@@ -9,7 +9,7 @@ class testServer(unittest.TestCase):
"""Legit environment."""
TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
"TOR_PT_MANAGED_TRANSPORT_VER" : "1",
- "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "",
"TOR_PT_ORPORT" : "127.0.0.1:43210",
"TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
"TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
@@ -20,7 +20,7 @@ class testServer(unittest.TestCase):
def test_bad_environment(self):
"""Missing TOR_PT_MANAGED_TRANSPORT_VER."""
TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
- "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "",
"TOR_PT_ORPORT" : "127.0.0.1:43210",
"TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
"TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
@@ -32,7 +32,7 @@ class testServer(unittest.TestCase):
"""Missing TOR_PT_ORPORT."""
TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
"TOR_PT_MANAGED_TRANSPORT_VER" : "1",
- "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "",
"TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
"TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
@@ -139,7 +139,7 @@ class testServer(unittest.TestCase):
"""Application only supports unknown transport."""
TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
"TOR_PT_MANAGED_TRANSPORT_VER" : "1",
- "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "",
"TOR_PT_ORPORT" : "127.0.0.1:43210",
"TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
"TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
@@ -152,7 +152,7 @@ class testServer(unittest.TestCase):
"""Application only supports some transport."""
TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
"TOR_PT_MANAGED_TRANSPORT_VER" : "1",
- "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "",
"TOR_PT_ORPORT" : "127.0.0.1:43210",
"TOR_PT_SERVER_BINDADDR" : "midnight-127.0.0.1:5556,herbie-127.0.0.1:6666,landing-127.0.0.1:9999",
"TOR_PT_SERVER_TRANSPORTS" : "midnight,herbie,landing" }
@@ -163,6 +163,44 @@ class testServer(unittest.TestCase):
self.assertIn("landing",retval['transports'])
self.assertEquals(len(retval['transports']), 2)
+ def test_correct_ext_orport(self):
+ """Correct Extended ORPort configuration."""
+ TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
+ "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_AUTH_COOKIE_FILE" : "/lulzie",
+ "TOR_PT_ORPORT" : "127.0.0.1:43210",
+ "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
+ "TOR_PT_SERVER_TRANSPORTS" : "what" }
+
+ os.environ = TEST_ENVIRON
+ retval = pyptlib.server.init(["what"])
+ self.assertEquals(retval['auth_cookie_file'], '/lulzie')
+ self.assertEquals(retval['ext_orport'], ['127.0.0.1', '5555'])
+
+ def test_ext_or_but_no_auth_cookie(self):
+ """TOR_PT_EXTENDED_SERVER_PORT without TOR_PT_AUTH_COOKIE_FILE."""
+ TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
+ "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
+ "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
+ "TOR_PT_ORPORT" : "127.0.0.1:43210",
+ "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
+ "TOR_PT_SERVER_TRANSPORTS" : "what" }
+
+ os.environ = TEST_ENVIRON
+ self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["what"])
+
+ def test_auth_cookie_but_no_ext_or(self):
+ """TOR_PT_AUTH_COOKIE_FILE without TOR_PT_EXTENDED_SERVER_PORT."""
+ TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
+ "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
+ "TOR_PT_AUTH_COOKIE_FILE" : "/lulzie",
+ "TOR_PT_ORPORT" : "127.0.0.1:43210",
+ "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
+ "TOR_PT_SERVER_TRANSPORTS" : "what" }
+
+ os.environ = TEST_ENVIRON
+ self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["what"])
if __name__ == '__main__':
unittest.main()
diff --git a/sphinx/API.rst b/sphinx/API.rst
index 7ec3725..7287a3b 100644
--- a/sphinx/API.rst
+++ b/sphinx/API.rst
@@ -101,14 +101,15 @@ Server case (skip if you are a client):
If your application is a server, the return value of
:func:`pyptlib.server.init` is a dictionary of the format:
-========== ========== ==========
-Key Type Value
-========== ========== ==========
-state_loc string Directory where the managed proxy should dump its state files (if needed).
-orport tuple (ip,port) tuple pointing to Tor's ORPort.
-ext_orport tuple (ip,port) tuple pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
-transports dict A dictionary 'transport => (ip,port)' where 'transport' is the name of the transport that should be spawned, and '(ip,port)' is the location where the transport should bind. The dictionary can be empty.
-========== ========== ==========
+=============== ========== ==========
+Key Type Value
+================ ========== ==========
+state_loc string Directory where the managed proxy should dump its state files (if needed).
+orport tuple (ip,port) tuple pointing to Tor's ORPort.
+ext_orport tuple (ip,port) tuple pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
+transports dict A dictionary 'transport => (ip,port)' where 'transport' is the name of the transport that should be spawned, and '(ip,port)' is the location where the transport should bind. The dictionary can be empty.
+auth_cookie_file string Directory where the managed proxy should find the Extended ORPort authentication cookie.
+================ ========== ==========
Your application should then use the *transports* key and attempt to
launch the appropriate transports. Furthermore, since the application
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git
More information about the Pkg-privacy-commits
mailing list