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

[tor-commits] [stem/master] Add CANNOT_DIRECTLY_UNPACK facility; set True for existing RelayCell



commit 77310c9cb96c0367412afbc6535ea54fe25fc442
Author: Dave Rolek <dmr-x@xxxxxxxxxx>
Date:   Tue Aug 7 21:45:26 2018 +0000

    Add CANNOT_DIRECTLY_UNPACK facility; set True for existing RelayCell
    
    Since RELAY cells come across the wire encrypted, they cannot be
    directly unpacked - their payload must first be decrypted.
    
    Note that this breaks unpacking RelayCell in the interim.
---
 stem/client/cell.py      | 5 +++--
 test/unit/client/cell.py | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index a4fb1a67..dcebc544 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -109,7 +109,7 @@ class Cell(object):
     """
 
     for _, cls in inspect.getmembers(sys.modules[__name__]):
-      if name == getattr(cls, 'NAME', UNDEFINED):
+      if name == getattr(cls, 'NAME', UNDEFINED) and not getattr(cls, 'CANNOT_DIRECTLY_UNPACK', False):
         return cls
 
     raise ValueError("'%s' isn't a valid cell type" % name)
@@ -125,7 +125,7 @@ class Cell(object):
     """
 
     for _, cls in inspect.getmembers(sys.modules[__name__]):
-      if value == getattr(cls, 'VALUE', UNDEFINED):
+      if value == getattr(cls, 'VALUE', UNDEFINED) and not getattr(cls, 'CANNOT_DIRECTLY_UNPACK', False):
         return cls
 
     raise ValueError("'%s' isn't a valid cell value" % value)
@@ -371,6 +371,7 @@ class RelayCell(CircuitCell):
   NAME = 'RELAY'
   VALUE = 3
   IS_FIXED_SIZE = True
+  CANNOT_DIRECTLY_UNPACK = True
 
   def __init__(self, circ_id, command, data, digest = 0, stream_id = 0, recognized = 0, unused = b''):
     if 'HASH' in str(type(digest)):
diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index a6ddf3ea..b8fe58df 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -220,6 +220,8 @@ class TestCell(unittest.TestCase):
       self.assertRaisesWith(ValueError, expected_message_format % payload_len, BaseRelayCell, arbitrary_circ_id, ZERO * payload_len)
 
   def test_relay_cell(self):
+    self.assertEquals(True, RelayCell.CANNOT_DIRECTLY_UNPACK)
+
     for cell_bytes, (command, command_int, circ_id, stream_id, data, digest, unused, link_protocol) in RELAY_CELLS.items():
       if not unused.strip(ZERO):
         self.assertEqual(cell_bytes, RelayCell(circ_id, command, data, digest, stream_id).pack(link_protocol))



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