commit d60ac492e2f2abb4f2c0764e28d77eb096365b17 Author: Damian Johnson atagar@torproject.org Date: Sun Dec 30 14:58:55 2018 -0800
Better type checking for RELAY cell replies
The message we give when RELAY cells receive an unexpected response are pretty bad...
ProtocolError: Circuit response should be a series of RELAY cells, but received an unexpected size for a response: 4048
Instead checking the cell types, providing a more descriptive error if they mismatch. This doesn't fix the issue I'm trying to solve, but it gets me a bit closer to the true problem of ticket #28961...
ProtocolError: RELAY cells should be 512 bytes, but received 464 --- stem/client/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/stem/client/__init__.py b/stem/client/__init__.py index 8e8bb118..c0d060ba 100644 --- a/stem/client/__init__.py +++ b/stem/client/__init__.py @@ -258,10 +258,12 @@ class Circuit(object): reply = self.relay._orport.recv() reply_cells = []
- if len(reply) % self.relay.link_protocol.fixed_cell_length != 0: - raise stem.ProtocolError('Circuit response should be a series of RELAY cells, but received an unexpected size for a response: %i' % len(reply)) - while reply: + reply_cmd = stem.client.datatype.Size.CHAR.pop(reply[self.relay.link_protocol.circ_id_size.size:])[0] + + if reply_cmd != stem.client.cell.RelayCell.VALUE: + raise stem.ProtocolError('Circuit response should be a series of RELAY cells, but received an unexpected %s (%i)' % (stem.client.cell.Cell.by_value(reply_cmd), reply_cmd)) + encrypted_cell, reply = split(reply, self.relay.link_protocol.fixed_cell_length) decrypted_cell, backward_key, backward_digest = stem.client.cell.RelayCell.decrypt(self.relay.link_protocol, encrypted_cell, self.backward_key, self.backward_digest)
tor-commits@lists.torproject.org