python-otr/pure-python-otr

Traceback on unknown TLV

mathieui opened this issue · 5 comments

ChatSecure uses custom TLV values for their OTRDATA protocol, and it exposed a bug in potr:

   File "/usr/lib64/python3.4/site-packages/potr/context.py", line 225, in receiveMessage
     plaintext, tlvs = self.crypto.handleDataMessage(message)
   File "/usr/lib64/python3.4/site-packages/potr/crypt.py", line 192, in handleDataMessage
     tlvs = proto.TLV.parse(tlvData)
   File "/usr/lib64/python3.4/site-packages/potr/proto.py", line 319, in parse
     return [tlvClasses[typ].parsePayload(data[:length])] \
 KeyError: 256

potr should check if the received TLVs are known before trying to get the relevant class. (and maybe return a custom exception when it isn’t known?)

We should actually raise NotOTRMessage as it's used in the rest of the code.
I'm looking into why it's not the case here exactly, and fix this quickly :)

Possible fix to test: 1422de3

I basically just implemented a new exception (insead of reusing NotOTRMessage which I didn't find to fit the bill quite right), and added a check against registered values of implemented TLV in the tlvClasses dict.

Yes, looks good to me

Merged in staging, closing for now.