bropat / eufy-security-ws

Small server wrapper around eufy-security-client library to access it via a WebSocket.
MIT License
178 stars 28 forks source link

Doorbell E340; start_lifestream throws Error "wrong final block length" #343

Closed mik55 closed 1 month ago

mik55 commented 3 months ago

Version

serverVersion 1.8.0 driverVersion 3.0.0

Node version

node -v v18.20.3; nodejs -v v20.14.0

Operating System type

Linux

Operating system version

Debian 12

Describe the bug

Hello, I have a Video Doorbell E340 (T8214; Battery Powered; with active power supply) and usually use IoBroker. Unfortunately, the lifestream didn't work with the adapter from the Develop branch (v 1.3.0). That's why I used the tools from eufy-security-ws to isolate the error. But the error “Provider routines::wrong final block length” from the crypto environment also occurs when starting the live stream. After the error, the live stream in the client is ended. The HW is a Tinkerboard, newly installed with Debian 12. All available crypto extensions are available as modules in the kernel.

To reproduce

Start server (/root/node_modules/eufy-security-ws/dist/bin/server.js -v -c /root/config.json) Server is connected to Eufy Cloud. Start client (/root/node_modules/eufy-security-ws/dist/bin/client.js -v -t 60) Client is connected to server and station (command: station.is_connected T821451012345678 -->connected: true) . If i start the command "device.start_livestream T821451012345678" --> throw the error in the server log.

Screenshots & Logfiles

server_log.txt Client Logfile start_lifestream.txt

Additional context

I think the same error is in the iobroker adapter and the HASS adapter.

mik55 commented 2 months ago

I now suspect that the error “wrong final block length” (see above) is a follow-up error to this one. When the server connects, the error "Error: Error during decryption (probably incorrect key). Original error: Error: Incorrect data or key'" is thrown by the node-rsa module. The RSA private key displayed in the logfile is error-free in OpenSSL as soon as I remove the formatting instructions. Fehlermeldung RSA Fehler.txt

Birdack commented 2 months ago

Any news or #348 ?

mik55 commented 2 months ago

@Birdack: No, unfortunately not.

bropat commented 1 month ago

I do not see any significant errors in any of the log files provided, except for some handled errors that are only visible in DEBUG mode.

For Example:

Expected fallback behaviour (Handle DATA CONTROL - CMD_GATEWAYINFO - set encryption level 1 (fallback)):

2024-06-18 16:22:29.170       DEBUG       eufy-security-ws:eufy-security-client     [p2p] Handle DATA CONTROL - CMD_GATEWAYINFO - set encryption level 1 (fallback) {
  error: {
    cause:  undefined ,
    message:  'Error: Error during decryption (probably incorrect key). Original error: Error: Incorrect data or key' ,
    context:  undefined ,
    stacktrace:  'Error: Error during decryption (probably incorrect key). Original error: Error: Incorrect data or key\n'  +
       '    at module.exports.NodeRSA.$$decryptKey (/root/node_modules/node-rsa/src/NodeRSA.js:301:19)\n'  +
       '    at module.exports.NodeRSA.decrypt (/root/node_modules/node-rsa/src/NodeRSA.js:249:21)\n'  +
       '    at /root/node_modules/eufy-security-client/build/p2p/session.js:2208:47\n'  +
       '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)' 
  },
  stationSN:  'T821451023xxxxxx' ,
  message: {
    seqNo:  0 ,
    channel:  255 ,
    commandType:  'CMD_GATEWAYINFO' ,
    signCode:  1 ,
    type:  0 ,
    dataType:  'CONTROL' ,
    data:  '03d84a254435f79d1029f5a289681152822547a075deea808e68c7e2754ac0a16cdad2f9eb830d64c44089f781ebe33d8a9582c9b68f1dc42d12bd45df90a37d1f4ac3a3483d94bad9babde6e83276a5e530d3de76dea8731b0485300cac850b5c1efa01ed57d5ee429dedbf53a12a005b04a08e169dd847883041dea533416461f713161adb5b2b7fe04ea575c3a580' 
  },
  key:  '<redacted>' 
}

Also:

2024-06-18 16:22:29.304       DEBUG       eufy-security-ws:eufy-security-client     [p2p] [P2PClientProtocol.handleData] Handle DATA DATA - Decrypt Error {
  error: {
    cause:  undefined ,
    message:  'Error: error:1C80006B:Provider routines::wrong final block length' ,
    context:  undefined ,
    stacktrace:  'Error: error:1C80006B:Provider routines::wrong final block length\n'  +
       '    at Decipheriv.final (node:internal/crypto/cipher:199:29)\n'  +
       '    at decryptP2PData (/root/node_modules/eufy-security-client/build/p2p/utils.js:102:18)\n'  +
       '    at P2PClientProtocol.handleData (/root/node_modules/eufy-security-client/build/p2p/session.js:1175:71)\n'  +
       '    at P2PClientProtocol.parseDataMessage (/root/node_modules/eufy-security-client/build/p2p/session.js:1152:26)\n'  +
       '    at P2PClientProtocol.handleMsg (/root/node_modules/eufy-security-client/build/p2p/session.js:986:26)\n'  +
       '    at Socket.<anonymous> (/root/node_modules/eufy-security-client/build/p2p/session.js:118:56)\n'  +
       '    at Socket.emit (node:events:517:28)\n'  +
       '    at Socket.emit (node:domain:489:12)\n'  +
       '    at UDP.onMessage [as onmessage] (node:dgram:942:8)' 
  },
  stationSN:  'T821451023xxxxxx' ,
  message: {
    seqNo:  0 ,
    channel:  0 ,
    commandType:  'CMD_SET_PAYLOAD' ,
    signCode:  1 ,
    type:  1 ,
    dataType:  'DATA' ,
    data:  '000000000000000000000000000000000000000000000000000000000000000000000000' 
  }
}

2024-06-18 16:22:29.307       DEBUG       eufy-security-ws:eufy-security-client     [p2p] [P2PClientProtocol.handleData] Handle DATA DATA - Received data {
  stationSN:  'T821451023xxxxxx' ,
  seqNo:  0 ,
  commandIdName:  'CMD_SET_PAYLOAD' ,
  commandId:  1350 ,
  resultCodeName:  'ERROR_PPCS_SUCCESSFUL' ,
  resultCode:  0 ,
  resultData:  '0000000000000000000000000000000000000000000000000000000000000000' ,
  data:  '000000000000000000000000000000000000000000000000000000000000000000000000' ,
  seqNumber:  3 ,
  p2pDataSeqNumber:  1 ,
  offsetDataSeqNumber:  0 
}

2024-06-18 16:22:29.310       DEBUG       eufy-security-ws:eufy-security-client     [p2p] [P2PClientProtocol.handleData] Handle DATA DATA - Result data for command received {
  stationSN:  'T821451023xxxxxx' ,
  message: {
    sequence:  1 ,
    commandType:  1350 ,
    nestedCommandType:  1003 ,
    channel:  0 ,
    acknowledged:  true ,
    retries:  0 ,
    returnCode:  0 ,
    data: <Buffer d1 00 00 01 58 5a 59 48 46 05 90 01 00 00 01 00 00 01 00 00 f8 86 3e a7 bc 27 47 0d 1e 93 96 95 99 54 b3 0d 67 0a 7a 3b 2b 4b 63 7b 3e 4d 35 bd 16 62 ... 370 more bytes>,
    customData: {
      command: {
        name:  'deviceStartLivestream' ,
        value:  0 
      }
    }
  },
  resultCodeName:  'ERROR_PPCS_SUCCESSFUL' ,
  resultCode:  0 
}

The only effective error I find in his log is the following:

2024-06-18 16:22:34.323       INFO        eufy-security-ws:eufy-security-client     [p2p] [Timeout._onTimeout] Stopping the station stream for the device T821451023xxxxxx, because we haven't received any data for 5000 mseconds

This error means that no streaming data has been received for 5 seconds since the device confirmed the ‘Start Stream Command’. Another confirmation is that there are no CMD_VIDEO_FRAME entries in the debug log.

Long story short, I don't see anything that suggests a bug, so I'm closing this issue.