[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Allow control connection to IPv6 addresses



commit 1087ebf6dadad2cc3ee81ad5ba8dc35e327cb665
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Sep 10 18:20:04 2020 -0700

    Allow control connection to IPv6 addresses
    
    Controller.from_port() improperly rejects IPv6 addresses as invalid...
    
      https://github.com/torproject/stem/issues/74
    
    This expands a few other methods to allow IPv6 addresses as well.
---
 docs/change_log.rst | 1 +
 stem/connection.py  | 4 ++--
 stem/control.py     | 8 ++++----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index bbd13ef5..5a9a8928 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -61,6 +61,7 @@ The following are only available within Stem's `git repository
   * Socket based control connections often raised BrokenPipeError when closed
   * Added :func:`~stem.control.Controller.add_hidden_service_auth`, :func:`~stem.control.Controller.remove_hidden_service_auth`, and :func:`~stem.control.Controller.list_hidden_service_auth` to the :class:`~stem.control.Controller`
   * Incorrect filesystem encoding broke latin-1 cookie path (:ticket:`57`)
+  * Allow control connection to IPv6 addresses (:ticket:`74`)
 
  * **Descriptors**
 
diff --git a/stem/connection.py b/stem/connection.py
index f5f92464..68cfda45 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -357,8 +357,8 @@ async def connect_async(control_port: Tuple[str, Union[str, int]] = ('127.0.0.1'
   elif control_port:
     if len(control_port) != 2:
       raise ValueError('The control_port argument for connect() should be an (address, port) tuple.')
-    elif not stem.util.connection.is_valid_ipv4_address(control_port[0]):
-      raise ValueError("'%s' isn't a vaid IPv4 address" % control_port[0])
+    elif not stem.util.connection.is_valid_ipv4_address(control_port[0]) and not stem.util.connection.is_valid_ipv6_address(control_port[0]):
+      raise ValueError("'%s' isn't a vaid address" % control_port[0])
     elif control_port[1] != 'default' and not stem.util.connection.is_valid_port(control_port[1]):
       raise ValueError("'%s' isn't a valid port" % control_port[1])
 
diff --git a/stem/control.py b/stem/control.py
index a232f4db..9a387f55 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1072,7 +1072,7 @@ class Controller(BaseController):
 
     import stem.connection
 
-    if not stem.util.connection.is_valid_ipv4_address(address):
+    if not stem.util.connection.is_valid_ipv4_address(address) and not stem.util.connection.is_valid_ipv6_address(address):
       raise ValueError('Invalid IP address: %s' % address)
     elif port != 'default' and not stem.util.connection.is_valid_port(port):
       raise ValueError('Invalid port: %s' % port)
@@ -2611,7 +2611,7 @@ class Controller(BaseController):
 
         if not stem.util.connection.is_valid_port(port):
           raise stem.ProtocolError('GETCONF provided an invalid HiddenServicePort port (%s): %s' % (port, content))
-        elif not stem.util.connection.is_valid_ipv4_address(target_address):
+        elif not stem.util.connection.is_valid_ipv4_address(target_address) and not stem.util.connection.is_valid_ipv6_address(target_address):
           raise stem.ProtocolError('GETCONF provided an invalid HiddenServicePort target address (%s): %s' % (target_address, content))
         elif not stem.util.connection.is_valid_port(target_port):
           raise stem.ProtocolError('GETCONF provided an invalid HiddenServicePort target port (%s): %s' % (target_port, content))
@@ -2722,8 +2722,8 @@ class Controller(BaseController):
 
     if not stem.util.connection.is_valid_port(port):
       raise ValueError("%s isn't a valid port number" % port)
-    elif target_address and not stem.util.connection.is_valid_ipv4_address(target_address):
-      raise ValueError("%s isn't a valid IPv4 address" % target_address)
+    elif target_address and not stem.util.connection.is_valid_ipv4_address(target_address) and not stem.util.connection.is_valid_ipv6_address(target_address):
+      raise ValueError("%s isn't a valid IP address" % target_address)
     elif target_port is not None and not stem.util.connection.is_valid_port(target_port):
       raise ValueError("%s isn't a valid port number" % target_port)
     elif auth_type not in (None, 'basic', 'stealth'):

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits