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

[tor-commits] [stem/master] Processing controller descriptors as bytes



commit ad82c905347f3e5849930fdb3e63721b294d38b4
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue May 21 21:30:49 2013 -0700

    Processing controller descriptors as bytes
    
    When descriptor content was fetched by the Controller it was first converted to
    unicode, then back into bytes. As a result descriptors with content that
    couldn't be converted (usually on the contact line) got mangled, and this in
    turn caused our check of its signature to fail.
    
    Caught thanks to aj00200 on...
    
    https://trac.torproject.org/8755
---
 stem/control.py |   23 ++++++++++++-----------
 test/mocking.py |    2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 9ea77f8..6ec0006 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -151,11 +151,12 @@ import stem.response.events
 import stem.socket
 import stem.util.connection
 import stem.util.enum
+import stem.util.str_tools
 import stem.util.tor_tools
 import stem.version
 
 from stem import UNDEFINED, CircStatus, Signal
-from stem.util import log, str_tools
+from stem.util import log
 
 # state changes a control socket can have
 
@@ -1018,8 +1019,8 @@ class Controller(BaseController):
       else:
         raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
 
-      desc_content = self.get_info(query)
-      return stem.descriptor.microdescriptor.Microdescriptor(str_tools._to_bytes(desc_content))
+      desc_content = self.get_info(query, get_bytes = True)
+      return stem.descriptor.microdescriptor.Microdescriptor(desc_content)
     except Exception as exc:
       if default == UNDEFINED:
         raise exc
@@ -1107,8 +1108,8 @@ class Controller(BaseController):
       else:
         raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
 
-      desc_content = self.get_info(query)
-      return stem.descriptor.server_descriptor.RelayDescriptor(str_tools._to_bytes(desc_content))
+      desc_content = self.get_info(query, get_bytes = True)
+      return stem.descriptor.server_descriptor.RelayDescriptor(desc_content)
     except Exception as exc:
       if default == UNDEFINED:
         raise exc
@@ -1141,9 +1142,9 @@ class Controller(BaseController):
       #
       # https://trac.torproject.org/8248
 
-      desc_content = self.get_info("desc/all-recent")
+      desc_content = self.get_info("desc/all-recent", get_bytes = True)
 
-      for desc in stem.descriptor.server_descriptor._parse_file(io.BytesIO(str_tools._to_bytes(desc_content))):
+      for desc in stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_content)):
         yield desc
     except Exception as exc:
       if default == UNDEFINED:
@@ -1186,8 +1187,8 @@ class Controller(BaseController):
       else:
         raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
 
-      desc_content = self.get_info(query)
-      return stem.descriptor.router_status_entry.RouterStatusEntryV2(str_tools._to_bytes(desc_content))
+      desc_content = self.get_info(query, get_bytes = True)
+      return stem.descriptor.router_status_entry.RouterStatusEntryV2(desc_content)
     except Exception as exc:
       if default == UNDEFINED:
         raise exc
@@ -1215,10 +1216,10 @@ class Controller(BaseController):
       #
       # https://trac.torproject.org/8248
 
-      desc_content = self.get_info("ns/all")
+      desc_content = self.get_info("ns/all", get_bytes = True)
 
       desc_iterator = stem.descriptor.router_status_entry._parse_file(
-        io.BytesIO(str_tools._to_bytes(desc_content)),
+        io.BytesIO(desc_content),
         True,
         entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV2,
       )
diff --git a/test/mocking.py b/test/mocking.py
index 50a0f0e..3b165d8 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -293,7 +293,7 @@ def return_for_args(args_to_return_value, default = None, is_method = False):
 
 
 def raise_exception(exception):
-  def _raise(*args):
+  def _raise(*args, **kwargs):
     raise exception
 
   return _raise

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