TuyaAPI / cli

🔧 A CLI for Tuya devices
MIT License
262 stars 44 forks source link

Wrong final block length #22

Closed mobamoba closed 5 years ago

mobamoba commented 5 years ago

I'm using most recent Master and am getting an the following error. My outlets are definitely 3.3 btw.

tuya-cli get --ip 192.168.x.x --id ID HERE --key KEY HERE --protocol-version 3.3 --all

gives:

internal/crypto/cipher.js:173 const ret = this[kHandle].final(); ^

Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length at Decipheriv.final (internal/crypto/cipher.js:173:29) at TuyaCipher.decrypt (C:\Users\Matt\AppData\Roaming\npm\node_modules\@tuyapi\cli\node_modules\t uyapi\lib\cipher.js:65:24) at Socket.client.on.data (C:\Users\Matt\AppData\Roaming\npm\node_modules\@tuyapi\cli\node_module s\tuyapi\index.js:345:39) at Socket.emit (events.js:193:13) at addChunk (_stream_readable.js:296:12) at readableAddChunk (_stream_readable.js:277:11) at Socket.Readable.push (_stream_readable.js:232:10) at TCP.onStreamRead (internal/stream_base_commons.js:150:17)

codetheweb commented 5 years ago

That looks like an error with TuyAPI; have you tried controlling your device directly with TuyAPI?

mobamoba commented 5 years ago

I don't really know how to do that, though I'm happy to try if you give me a command line example to use. The outlet throwing the error is a simple plug so there's really just the current state and then a toggle on or off if that matters.

codetheweb commented 5 years ago

Ok, can you please post the debug output? You can toggle debug output by running set DEBUG=* on Windows, then run the command you originally posted to get the state of the device.

mobamoba commented 5 years ago

I updated to 1.8 and now I'm just getting unhandled promise rejections every time I run it.

codetheweb commented 5 years ago

Ok, please follow my instructions in my previous message and post any output. If an error is thrown before anything is printed to the terminal, please post that.

mobamoba commented 5 years ago

Here you go. The last section (after the promise rejection) kept repeating and I eventually just terminated the job.

TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 192.168.1.33... +9ms TuyAPI Socket connected. +47ms TuyAPI GET Payload: +3ms TuyAPI { gwId: '41744580b4e62d1fde59', devId: '41744580b4e62d1fde59' } +0ms TuyAPI Received data: 000055aa000000010000000a0000002c00000001762a639710321dc9969b14c25f7a1c42253f ad952930fd47c58296afff1b0317961f03630000aa55 +41ms TuyAPI Parsed: +4ms TuyAPI { payload: TuyAPI 'v*c�\u00102\u001dɖ�\u0014�_z\u001cB%?��)0�Gł���\u001b\u0003\u0017', TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 } +0ms (node:11252) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of undefined at _send.then.data (C:\Users\Matt\AppData\Roaming\npm\node_modules\tuyapi\index.js:122:29) at processTicksAndRejections (internal/process/task_queues.js:86:5) (node:11252) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated ei ther by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:11252) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the futur e, promise rejections that are not handled will terminate the Node.js process with a non-zero exit c ode. TuyAPI Received data: 000055aa00000000000000080000006b00000000332e3300000000000905ed000000010028e5 80a1776ef2ab0344da043d6a526c6297d2467e5b81c07d618f1e81f8e566461ee1e3bef5c35933d9128ffe444bb724d9d7c8 03e841d2c9c053447ac9a9bdd70abc64a9b7250fd17f1f8f9b6d77b26367270000aa55 +9s TuyAPI Parsed: +1ms TuyAPI { payload: TuyAPI '3.3\u0000\u0000\u0000\u0000\u0000\t\u0005�\u0000\u0000\u0000\u0001\u0000(倡wn�\u0003D�\ u0004=jRlb��F~[��}a�\u001e���fF\u001e����Y3�\u0012��DK�$���\u0003�A���SDzɩ��\n�d��%\u000f�\u001f��m w', TuyAPI leftover: false, TuyAPI commandByte: 8, TuyAPI sequenceN: 0 } +0ms TuyAPI Pinging 192.168.1.33 +1s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +141ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 192.168.1.33 +1ms TuyAPI Pinging 192.168.1.33 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +6ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms

codetheweb commented 5 years ago

For further debugging I need the local key. You can either post it here or send it to me via one of the contact methods on my site.

mobamoba commented 5 years ago

Is there a security issue with posting the key publicly? Because if not happy to post here.

codetheweb commented 5 years ago

No, not really unless someone has access to your network.

mobamoba commented 5 years ago

That's what I figured. Here you go: 810a418850202763

codetheweb commented 5 years ago

From attempting to decode it, I think it's likely your localKey is incorrect. It changes every time the device is re-registered, can you try sniffing for the key again?

mobamoba commented 5 years ago

Didn't realize key could change. But yes that solved it - thanks.

codetheweb commented 5 years ago

👍