question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Message parser fails to parse UDP message when using find()

See original GitHub issue

Describe the bug The find() function fails when the decipher functions does not trigger “catch”, i.e. decipher thinks it was able to decrypt the data when in fact it was not.

To Reproduce I have a protocol 3.3 device and when I attempt to use find(), it fails but only when I use the “proper” device key. If I use the wrong device key (even just change one number) then find() works. Digging through this, the issue seems to be in the decrypt data function. The code attempts to decrypt the data with the device.key, and, for some reason, with this device and this specific key, it thinks decryption was successful and returns back to to the find() function the improperly decrypted message instead of falling through to the catch block and attempting to decrypt with the UDP_KEY.

Expected behavior The decrypt with the device.key should fail, and the catch block should execute the decrypt with the hardcoded UDP_KEY.

Debug Output The problem happens with tuya-mqtt, but I’ve reproduced with tuya-cli, exactly the same. Here’s an example of the UDP debug when the issue occurs:

  TuyAPI UDP data: +9ms
  TuyAPI {
  TuyAPI   payload: '4h}��\u0005�:-���^�/]5��ԝqI��4�\u0017���.\u000e\u0001�A߯X��)�DU��UP��lf�9\\�p�\u0003�D�-��\u0017��y�\u0010г�Ϫf;zc\u0019\u001c��\u0001iKTv\u0003�gN\u0007��P�c�"$�\t���\u0013�\n' +
  TuyAPI     `�A4?#�g/�q\u0019\u0013�\u0004\u0000;'wK"��׹8.�J� ������}��\u0002ؤ`,
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +0ms

Additional context As a hackish workaround, I just change decrypt function to attempt UDP_KEY prior to device.key, and things work, however, I don’t like this as it means that for “non-find” operations every packet fails decryption first.

I can probably work around this in my app by simply temporarily using the hard coded key for the find() function and, only after the device is found, creating the “real” device, but it seems like a better option is preferred, I’m just not sure what that would be.

I can think of several possible ways to fix this, but none seem particularly clean. A simple flag passed to message parser is probably one of the easiest, that way decrypt can explicitly know to use UDP_KEY instead of rely on decryption failing. I’m hoping someone a little closer to the code has a better idea.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tsightlercommented, Sep 21, 2020

Yep, works great, and much cleaner than my client side workaround that I implemented last night.

0reactions
tsightlercommented, Sep 21, 2020

Awesome, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to parse the entire UDP message at client side [closed]
Unable to parse the entire UDP message at client side. You are parsing more than the entire UDP message:
Read more >
Unable to parse DNS layer for TCP traffic · Issue #583 - GitHub
I am reading pcap data and parsing its content, i was not able to parse DNS layer for TCP traffic. No issue for...
Read more >
syslog-ng Open Source Edition 3.30 - Administration Guide
The syslog-parser does not discard messages: the message cannot be parsed as a syslog message, the entire message (including its header) is stored...
Read more >
GELF via UDP - Graylog
Hint: Currently, the server implementation of GELF in Graylog does not support boolean values. Boolean values will be dropped on ingest (for reference...
Read more >
tshark(1) Manual Page - Wireshark
It lets you capture packet data from a live network, or read packets from a ... Use the output of "tshark -G protocols"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found