[tor-commits] [stem/master] Support HSFETCH for v3 hidden services

atagar at torproject.org atagar at torproject.org
Sun Mar 3 23:32:05 UTC 2019


commit 53ef191a081a82ff94c947693ed57464e66f2fb6
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Mar 3 15:16:17 2019 -0800

    Support HSFETCH for v3 hidden services
    
    Tor recently added HSFETCH support for v3 services...
    
      https://trac.torproject.org/projects/tor/ticket/25417
      https://gitweb.torproject.org/torspec.git/commit/?id=34518e1
    
    Leveraging this new capability takes nothing more than
    providing the longer hidden service v3 address to the
    command. This is neat since it means all we need to do
    on our end is stop rejecting v3 addresses.
    
    Our only use of is_valid_hidden_service_address() is
    get_hidden_service_descriptor(), so simply adjusting our
    helper to recognize both v2 and v3 addresses.
---
 docs/change_log.rst    |  4 ++++
 stem/util/tor_tools.py | 14 ++++++++++----
 stem/version.py        |  2 ++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index 21b6c85e..89626ca4 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -73,6 +73,10 @@ The following are only available within Stem's `git repository
 
   * Sockets with ORPorts errored if responses exceeded a hardcoded buffer size (:trac:`28961`)
 
+ * **Utilities**
+
+  * :func:`~stem.util.tor_tools.is_valid_hidden_service_address` now provides *true* if a v3 hidden servie address
+
  * **Website**
 
   * Added NetBSD to our `download page <download.html>`_
diff --git a/stem/util/tor_tools.py b/stem/util/tor_tools.py
index 301d7ea0..2aed5130 100644
--- a/stem/util/tor_tools.py
+++ b/stem/util/tor_tools.py
@@ -39,9 +39,10 @@ import stem.util.str_tools
 NICKNAME_PATTERN = re.compile('^[a-zA-Z0-9]{1,19}$')
 CIRC_ID_PATTERN = re.compile('^[a-zA-Z0-9]{1,16}$')
 
-# Hidden service addresses are sixteen base32 characters.
+# Hidden service addresses are sixteen or fifty six base32 characters.
 
-HS_ADDRESS_PATTERN = re.compile('^[a-z2-7]{16}$')
+HS_V2_ADDRESS_PATTERN = re.compile('^[a-z2-7]{16}$')
+HS_V3_ADDRESS_PATTERN = re.compile('^[a-z2-7]{56}$')
 
 
 def is_valid_fingerprint(entry, check_prefix = False):
@@ -132,14 +133,19 @@ def is_valid_hidden_service_address(entry):
   Checks if a string is a valid format for being a hidden service address (not
   including the '.onion' suffix).
 
-  :returns: **True** if the string could be a hidden service address, **False** otherwise
+  .. versionchanged:: 1.8.0
+     Responds with **True** if a version 3 hidden service address, rather than
+     just version 2 addresses.
+
+  :returns: **True** if the string could be a hidden service address, **False**
+    otherwise
   """
 
   if isinstance(entry, bytes):
     entry = stem.util.str_tools._to_unicode(entry)
 
   try:
-    return bool(HS_ADDRESS_PATTERN.match(entry))
+    return bool(HS_V2_ADDRESS_PATTERN.match(entry)) or bool(HS_V3_ADDRESS_PATTERN.match(entry))
   except TypeError:
     return False
 
diff --git a/stem/version.py b/stem/version.py
index cafe37a6..21dc3a0b 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -66,6 +66,7 @@ easily parsed and compared, for instance...
   **GETINFO_MICRODESCRIPTORS**          'GETINFO md/all' query
   **HIDDEN_SERVICE_V3**                 Support for v3 hidden services
   **HSFETCH**                           HSFETCH requests
+  **HSFETCH_V3**                        HSFETCH for version 3 hidden services
   **HSPOST**                            HSPOST requests
   **ADD_ONION**                         ADD_ONION and DEL_ONION requests
   **ADD_ONION_BASIC_AUTH**              ADD_ONION supports basic authentication
@@ -380,6 +381,7 @@ Requirement = stem.util.enum.Enum(
   ('GETINFO_MICRODESCRIPTORS', Version('0.3.5.1-alpha')),
   ('HIDDEN_SERVICE_V3', Version('0.3.3.1-alpha')),
   ('HSFETCH', Version('0.2.7.1-alpha')),
+  ('HSFETCH_V3', Version('0.4.1.1-alpha')),
   ('HSPOST', Version('0.2.7.1-alpha')),
   ('ADD_ONION', Version('0.2.7.1-alpha')),
   ('ADD_ONION_BASIC_AUTH', Version('0.2.9.1-alpha')),



More information about the tor-commits mailing list