Skip to content

Commit

Permalink
Merge pull request #175 from david415/174.add_null_control_auth.0
Browse files Browse the repository at this point in the history
Add support for NULL control port authentication
  • Loading branch information
meejah committed Jul 7, 2016
2 parents 9fd243d + 4fba599 commit ccb32dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/releases.rst
Expand Up @@ -11,6 +11,8 @@ unreleased

`git master <https://github.com/meejah/txtorcon>`_ *will likely become v0.15.0*

* added support for NULL control-port-authentication which is often
appropriate when used with a UNIX domain socket
* switched to `ipaddress
<https://docs.python.org/3/library/ipaddress.html>`_ instead of
Google's ``ipaddr``; the API should be the same from a user
Expand Down
11 changes: 11 additions & 0 deletions test/test_torcontrolprotocol.py
Expand Up @@ -104,6 +104,17 @@ def test_authenticate_password(self):

self.assertEqual(self.transport.value(), 'AUTHENTICATE %s\r\n' % "foo".encode("hex"))

def test_authenticate_null(self):
self.protocol.makeConnection(self.transport)
self.assertEqual(self.transport.value(), 'PROTOCOLINFO 1\r\n')
self.transport.clear()
self.send('250-PROTOCOLINFO 1')
self.send('250-AUTH METHODS=NULL')
self.send('250-VERSION Tor="0.2.2.34"')
self.send('250 OK')

self.assertEqual(self.transport.value(), 'AUTHENTICATE\r\n')

def test_authenticate_password_deferred(self):
d = defer.Deferred()
self.protocol.password_function = lambda: d
Expand Down
6 changes: 6 additions & 0 deletions txtorcon/torcontrolprotocol.py
Expand Up @@ -749,6 +749,12 @@ def _do_authenticate(self, protoinfo):
d.addErrback(self._auth_failed)
return

if 'NULL' in methods:
d = self.queue_command('AUTHENTICATE')
d.addCallback(self._bootstrap)
d.addErrback(self._auth_failed)
return

raise RuntimeError(
"The Tor I connected to doesn't support SAFECOOKIE nor COOKIE"
" authentication and I have no password_function specified."
Expand Down

0 comments on commit ccb32dd

Please sign in to comment.