JanLoebel / eufy-node-client

Experiment to talk to eufy security
43 stars 6 forks source link

Experiencing issues in homebridge #21

Closed birkir closed 3 years ago

birkir commented 3 years ago

Hey, great work!

I am using this library in a plug-in for Homebridge, a proxy for HomeKit, and have some issues that people have been reporting and was wondering if you may have some insight into them.

https://github.com/birkir/homebridge-plugin-eufy-security/issues/4

Stichoza commented 3 years ago

I get lots of warnings due to unhandled promise rejections, but there is one error that's bugging me:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Hash.update (internal/crypto/hash.js:84:11)
    at Object.generate (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/uuid.ts:9:11)
    at PushClient.callback (/usr/lib/node_modules/homebridge-plugin-eufy-security/src/platform.ts:111:46)
    at PushClient.handleParsedMessage (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client.service.js:206:26)
    at PushClientParser.<anonymous> (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client.service.js:103:63)
    at PushClientParser.emit (events.js:315:20)
    at PushClientParser.onGotMessageBytes (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client-parser.service.js:150:14)
    at PushClientParser.handleFullMessage (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client-parser.service.js:79:22)
    at PushClientParser.waitForData (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client-parser.service.js:64:18)
    at PushClientParser.onGotMessageSize (/usr/lib/node_modules/homebridge-plugin-eufy-security/node_modules/eufy-node-client/build/push/push-client-parser.service.js:124:18)
JanLoebel commented 3 years ago

@birkir That are too many posts to read through. Please tell me what the exact problem is and a stacktrace therefore. If there are login errors please find a participant which will invite me as a test person to their eufy security account and then I can start debugging it.

@Stichoza the latest two lines of your stacktrace are from the library "homebridge-plugin-eufy-security" so that is a problem in that library not in my client. Please open a bug report there.

birkir commented 3 years ago

Okay, I think I’ve broken it down mainly into these two things

  1. People are getting locked out from their account. Maybe fault of pushTokenCheck on 30s interval? Too many logins?
  2. Some get “401 Unauthorised” on register push token, even though the credentials work fine on the app and web portal. Some are getting timeout at register push token.
JanLoebel commented 3 years ago

I've read some user messages in your project but there is nothing helpful. Please checkout https://github.com/bropat/ioBroker.eufy-security he has implemented the 2FA authentication.

moshed commented 3 years ago

@birkir That are too many posts to read through. Please tell me what the exact problem is and a stacktrace therefore. If there are login errors please find a participant which will invite me as a test person to their eufy security account and then I can start debugging it.

@Stichoza the latest two lines of your stacktrace are from the library "homebridge-plugin-eufy-security" so that is a problem in that library not in my client. Please open a bug report there.

@JanLoebel I would love to help you out and invite you as a test user on my account to try and get this working. @birkir do you still need volunteers?

JanLoebel commented 3 years ago

@moshed great, so you have the problem that @birkir referenced, that you can't get a push token? Do you have any node.js / typescript experience?

moshed commented 3 years ago

yes I have the same problem that @birkir referenced although I have no node.js experience. I am comfortable with the command line so I can maybe help you if im guided through, but im definitely not capable of troubleshooting and/or solving on my own.

if you need anything from me let me know!

bropat commented 3 years ago

Okay, I think I’ve broken it down mainly into these two things

  1. People are getting locked out from their account. Maybe fault of pushTokenCheck on 30s interval? Too many logins?
  2. Some get “401 Unauthorised” on register push token, even though the credentials work fine on the app and web portal. Some are getting timeout at register push token.
  1. I think too many logins in too short a time was the cause of the lockout. That was fixed by this pull request #24.
  2. I think that the cause here is still point 1. Each http request generated a new token due to a bug (#24) until Eufy blocked the account for too many new token requests. After that you got no more tokens and the further queries generated the 401 error.

@birkir Why do you do the following every 30 seconds? It is not necessary. This only caused the faster luring of the account due to the bug.

setInterval(async () => {
      try {
        await this.httpService.pushTokenCheck();
      } catch (err) {
        this.log.warn('failed to confirm push token');
      }
    }, 30 * 1000);

@JanLoebel The solution could be to release a new version with the latest fixes :)

birkir commented 3 years ago

Well, I copied this from one of the example repository, as the library doesn't have any documentation.

I figured this was used to regenerate the push token (somehow, like JWT etc)

https://github.com/JanLoebel/eufy-node-client-examples/blob/02c8d3e0ef77edaa387c4c59596db433425fa4af/examples/push-logging/index.js#L48

Not needed? Even better!

bropat commented 3 years ago

You are right there is not much documentation yet. This library is still under development. You are welcome to contribute ;)

Stichoza commented 3 years ago

Sometimes I just sit and wonder what the earth would be like without open source community, you guys rock! 🤘

JanLoebel commented 3 years ago

I've released the version 0.4.0 and adapted the examples. So the login problem should be gone :)

@moshed could you follow the instructions from: https://github.com/JanLoebel/eufy-node-client-examples and try to run the push-logging example. Then please send me the log output. But assure to mask private data.

moshed commented 3 years ago
(node:45338) UnhandledPromiseRejectionWarning: Error: Request failed: https://mysecurity.eufylife.com/api/v1/passport/login -> 100028 - Failed to request.
    at /Users/moshe/eufy-node-client-examples/node_modules/eufy-node-client/build/http/http.utils.js:24:15
    at Generator.next (<anonymous>)
    at fulfilled (/Users/moshe/eufy-node-client-examples/node_modules/eufy-node-client/build/http/http.utils.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:45338) Error: Request failed: https://mysecurity.eufylife.com/api/v1/passport/login -> 100028 - Failed to request.
    at /Users/moshe/eufy-node-client-examples/node_modules/eufy-node-client/build/http/http.utils.js:24:15
    at Generator.next (<anonymous>)
    at fulfilled (/Users/moshe/eufy-node-client-examples/node_modules/eufy-node-client/build/http/http.utils.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:45338) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at emitDeprecationWarning (internal/process/promises.js:180:11)
    at processPromiseRejections (internal/process/promises.js:249:13)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

there doesn't appear to be any sensitive information here so not sure I did this right... but anyway the above is with node --stack-trace

it appears I am now locked out of my account (I made a dummy account and shared my devices just in case this happened so no worries) if you would like me to add my devices to an account to give you access let me know

moshed commented 3 years ago

I think I got it!

Starting...
Credentials found -> reusing them...
handleParsedMessage: Login response: GCM -> logged in -> waiting for push messages!
handleParsedMessage: IqStanza: Not implemented! - message:  {"tag":7,"object":{"type":"SET","id":"","extension":{"id":12,"data":{"type":"Buffer","data":[]}}}}
url: https://mysecurity.eufylife.com/api/v1/passport/login -> body: {"code":0,"msg":"ok","data":{"user_id":"1ae88b44f1e7cac5849527def3f5594b5615d969","email":"moshedancykierguest2@gmail.com","nick_name":"Guest 2","auth_token":"[redacted]","token_expires_at":1611293201,"avatar":"","invitation_code":"318fa471894a3f321004","inviter_code":"","verify_code_url":"","mac_addr":"","domain":"security-app.eufylife.com","ab_code":"US","geo_key":"AIzaSyAq0l7djwj_R4Kx0a6ggpafRiTg2mxjLJQ","privilege":0,"phone":"","phone_code":"","params":null,"trust_list":[]}}
url: https://security-app.eufylife.com/v1/passport/login -> body: {"code":0,"msg":"ok","data":{"user_id":"1ae88b44f1e7cac5849527def3f5594b5615d969","email":"moshedancykierguest2@gmail.com","nick_name":"Guest 2","auth_token":"[redacted]","token_expires_at":1611293201,"avatar":"","invitation_code":"318fa471894a3f321004","inviter_code":"","verify_code_url":"","mac_addr":"","domain":"security-app.eufylife.com","ab_code":"US","geo_key":"AIzaSyAq0l7djwj_R4Kx0a6ggpafRiTg2mxjLJQ","privilege":0,"phone":"","phone_code":"","params":null,"trust_list":[]}}
url: https://security-app.eufylife.com/v1/apppush/register_push_token -> body: {"code":0,"msg":"Succeed."}
Registered at eufy with: cqLztavuQXyTO6jkpolvFj:APA91bHpmVqdTI02d0UpOrrU8DylvKr_mPnuXrYZfMvm42sIvR209nwVI4tYqoNK6B4lnol2_3K7YZTkpcvEHDG5LhjU2d8qEPd08iitIgS-_svMBMaS-SpkuHDXoRo4VKof4_tJAxqa
url: https://security-app.eufylife.com/v1/app/review/app_push_check -> body: {"code":0,"msg":"Erfolgreich."}

I've redacted the auth token here, not sure if anything else needs to be redacted but this looks like a successful token authorization to me!

JanLoebel commented 3 years ago

@moshed great! So that should work!

@birkir Could you also upgrade to the latest version of the client?

JanLoebel commented 3 years ago

Will close it for now, if there is more, please open a specific ticket.