Skip to content
Snippets Groups Projects
Commit e3fab7bf authored by Damian Johnson's avatar Damian Johnson
Browse files

Incorrect circuit digest for higher protocol versions

I only got stem.client working for link protocol 3 when cobbling it together.
We attempt to conform with the spec for higher protocol versions but it's
mostly untested.

While looking into #26060 I realized that we're using the wrong length for cell
headers when the link protocol is higher than three. Link v4 and greater use a
long for circuit identifiers rather than a short...

  circ_id (4 bytes) + command (1 byte) = 5 bytes
parent ee3bca1e
No related branches found
No related tags found
No related merge requests found
......@@ -235,20 +235,26 @@ class Circuit(object):
orig_digest = self.forward_digest.copy()
orig_key = copy.copy(self.forward_key)
# Digests and such are computed using the RELAY cell payload. This
# doesn't include the initial circuit id and cell type fields.
# Circuit ids vary in length depending on the protocol version.
header_size = 5 if self.relay.link_protocol > 3 else 3
try:
cell = stem.client.cell.RelayCell(self.id, command, data, 0, stream_id)
payload_without_digest = cell.pack(self.relay.link_protocol)[3:]
payload_without_digest = cell.pack(self.relay.link_protocol)[header_size:]
self.forward_digest.update(payload_without_digest)
cell = stem.client.cell.RelayCell(self.id, command, data, self.forward_digest, stream_id)
header, payload = split(cell.pack(self.relay.link_protocol), 3)
header, payload = split(cell.pack(self.relay.link_protocol), header_size)
encrypted_payload = header + self.forward_key.update(payload)
reply = []
self.relay._orport.send(encrypted_payload)
for cell in stem.client.cell.Cell.unpack(self.relay._orport.recv(), self.relay.link_protocol):
decrypted = self.backward_key.update(cell.pack(self.relay.link_protocol)[3:])
decrypted = self.backward_key.update(cell.pack(self.relay.link_protocol)[header_size:])
reply.append(stem.client.cell.RelayCell._unpack(decrypted, self.id, self.relay.link_protocol))
return reply
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment