commit 0d0a018d721db77015453d284bb348e7db72cb84 Author: Damian Johnson atagar@torproject.org Date: Wed Feb 7 10:35:59 2018 -0800
Only validate RELAY cells when unencrypted
When the cell is encrypted these fields are obviously essentially noise. In practice this seems to be causing inconsistent failures roughly 1/10 of the time...
Traceback (most recent call last): File "client-or-stream-raw.py", line 30, in <module> reply = circ.send('RELAY_BEGIN_DIR', stream_id = 1) File "/home/atagar/Desktop/tor/endosome/stem/client/__init__.py", line 246, in send reply = next(stem.client.cell.Cell.unpack(self.relay._orport.recv(), self.relay.link_protocol)) File "/home/atagar/Desktop/tor/endosome/stem/client/cell.py", line 135, in unpack cell, content = Cell.pop(content, link_protocol) File "/home/atagar/Desktop/tor/endosome/stem/client/cell.py", line 166, in pop return cls._unpack(payload, circ_id, link_protocol), content File "/home/atagar/Desktop/tor/endosome/stem/client/cell.py", line 349, in _unpack return RelayCell(circ_id, command, data, digest, stream_id, recognized) File "/home/atagar/Desktop/tor/endosome/stem/client/cell.py", line 327, in __init__ raise ValueError('%s relay cells concern the circuit itself and cannot have a stream id' % self.command) ValueError: RELAY_TRUNCATE relay cells concern the circuit itself and cannot have a stream id --- stem/client/__init__.py | 4 +--- stem/client/cell.py | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/stem/client/__init__.py b/stem/client/__init__.py index f4fc718b..2b853baa 100644 --- a/stem/client/__init__.py +++ b/stem/client/__init__.py @@ -218,7 +218,7 @@ class Circuit(object): self.forward_key = Cipher(algorithms.AES(kdf.forward_key), ctr, default_backend()).encryptor() self.backward_key = Cipher(algorithms.AES(kdf.backward_key), ctr, default_backend()).decryptor()
- def send(self, command, data, stream_id = 0): + def send(self, command, data = '', stream_id = 0): """ Sends a message over the circuit.
@@ -227,8 +227,6 @@ class Circuit(object): :param int stream_id: specific stream this concerns """
- # TODO: move RelayCommand to this base module? - with self.relay._orport_lock: orig_digest = self.forward_digest.copy() orig_key = copy.copy(self.forward_key) diff --git a/stem/client/cell.py b/stem/client/cell.py index 13f14f3c..c5f8f20b 100644 --- a/stem/client/cell.py +++ b/stem/client/cell.py @@ -321,10 +321,11 @@ class RelayCell(CircuitCell): self.digest = digest self.stream_id = stream_id
- if not stream_id and self.command in STREAM_ID_REQUIRED: - raise ValueError('%s relay cells require a stream id' % self.command) - elif stream_id and self.command in STREAM_ID_DISALLOWED: - raise ValueError('%s relay cells concern the circuit itself and cannot have a stream id' % self.command) + if digest == 0: + if not stream_id and self.command in STREAM_ID_REQUIRED: + raise ValueError('%s relay cells require a stream id' % self.command) + elif stream_id and self.command in STREAM_ID_DISALLOWED: + raise ValueError('%s relay cells concern the circuit itself and cannot have a stream id' % self.command)
def pack(self, link_protocol): payload = io.BytesIO()