[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Allow brackets in all ipv6 descriptor fields
commit 3c7ea19c05dfb5c373cafd367e08741a79c8d9d3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Jan 10 13:45:10 2016 -0800
Allow brackets in all ipv6 descriptor fields
BridgeDB is presently sad because ipv6 addresses are bracketed in extrainfo
transport lines...
transport obfs4 [2001:4ba0:fff1:2a::3]:443 cert=rYA/I7gVIxyz7RwRJUrk1aCCacPMlT+kFF0b9j8NWdlpiAuko66S/ERwzfKGJ/39aVPaTw,iat-mode=0
Our is_valid_ipv6_address() needs the allow_brackets flag, and to normalize the
addresses afterward.
---
docs/change_log.rst | 1 +
stem/descriptor/extrainfo_descriptor.py | 3 ++-
stem/descriptor/router_status_entry.py | 4 ++--
stem/descriptor/server_descriptor.py | 9 ++-------
4 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index ec56301..798eb86 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -66,6 +66,7 @@ The following are only available within Stem's `git repository
* TypeError under python3 when using 'use_mirrors = True' (:trac:`17083`)
* Deprecated hidden service descriptor's *introduction_points_auth* field, which was never implemented in tor (:trac:`15190`, :spec:`9c218f9`)
* Fixed parsing of server descriptor's *allow-single-hop-exits* and *caches-extra-info* lines
+ * Bracketed IPv6 addresses were mistreated as being invalid content
* Updated dannenberg's v3ident (:trac:`17906`)
* **Utilities**
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 3d424ee..e366bee 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -284,11 +284,12 @@ def _parse_transport_line(descriptor, entries):
address, port_str = value_comp[1].rsplit(':', 1)
if not stem.util.connection.is_valid_ipv4_address(address) or \
- stem.util.connection.is_valid_ipv6_address(address):
+ stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True):
raise ValueError('Transport line has a malformed address: transport %s' % value)
elif not stem.util.connection.is_valid_port(port_str):
raise ValueError('Transport line has a malformed port: transport %s' % value)
+ address.lstrip('[').rstrip(']')
port = int(port_str)
args = value_comp[2:] if len(value_comp) >= 3 else []
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 1bcebe8..b3cd637 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -172,11 +172,11 @@ def _parse_a_line(descriptor, entries):
address = address[1:-1] # remove brackets
if not ((not is_ipv6 and stem.util.connection.is_valid_ipv4_address(address)) or
- (is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
+ (is_ipv6 and stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True))):
raise ValueError("%s 'a' line must start with an IPv6 address: a %s" % (descriptor._name(), value))
if stem.util.connection.is_valid_port(port):
- or_addresses.append((address, int(port), is_ipv6))
+ or_addresses.append((address.lstrip('[').rstrip(']'), int(port), is_ipv6))
else:
raise ValueError("%s 'a' line had an invalid port (%s): a %s" % (descriptor._name(), port, value))
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 84bd025..f096499 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -344,19 +344,14 @@ def _parse_or_address_line(descriptor, entries):
raise ValueError('or-address line missing a colon: %s' % line)
address, port = entry.rsplit(':', 1)
- is_ipv6 = address.startswith('[') and address.endswith(']')
- if is_ipv6:
- address = address[1:-1] # remove brackets
-
- if not ((not is_ipv6 and stem.util.connection.is_valid_ipv4_address(address)) or
- (is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
+ if not stem.util.connection.is_valid_ipv4_address(address) and not stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True):
raise ValueError('or-address line has a malformed address: %s' % line)
if not stem.util.connection.is_valid_port(port):
raise ValueError('or-address line has a malformed port: %s' % line)
- or_addresses.append((address, int(port), is_ipv6))
+ or_addresses.append((address.lstrip('[').rstrip(']'), int(port), stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True)))
descriptor.or_addresses = or_addresses
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits