bropat / eufy-security-client

This shared library allows to control Eufy security devices by connecting to the Eufy cloud servers and local/remote stations over p2p.
MIT License
467 stars 67 forks source link

Eufy API is returning 204 errors causing the library to fail #67

Closed SerialVelocity closed 2 years ago

SerialVelocity commented 2 years ago

Describe the bug
Calls seem to be randomly failing and returning 204 errors

To Reproduce
Steps to reproduce the behavior:

  1. Use code:

    const eufy: EufySecurity = new EufySecurity(config, logger);
    if (!await eufy.connect()) {
        console.log("Couldn't connect");
    }
    
    await eufy.refreshCloudData();
  2. View logs

Expected behavior
Calls to not fail.

Screenshots & Logfiles
If applicable, add screenshots and logfiles to help explain your problem. Without debug logging:

> tsc -p .

2021-11-18 23:15:33.860  ERROR Status return code not 200
{
  status: 204,
  statusText: 'No Content'
}
2021-11-18 23:15:34.391  ERROR Station <REDACTED> - Status return code not 200
{
  status: 204,
  statusText: 'No Content'
}

With debug logging:

2021-11-18 23:31:17.342  DEBUG [HTTPApi.request] Request:
{
  method: 'post',
  endpoint: 'app/get_hub_list',
  baseUrl: 'https://security-app-eu.eufylife.com/v1',
  token: '<REDACTED>',
  data: undefined,
  headers: {
    app_version: 'v2.8.0_887',
    os_type: 'android',
    os_version: '30',
    phone_model: 'EUFYCLIENT',
    country: 'GB',
    language: 'en',
    openudid: '<REDACTED>',
    uid: '',
    net_type: 'wifi',
    mnc: '02',
    mcc: '262',
    sn: '<REDACTED>',
    Model_type: 'PHONE',
    timezone: 'GMT+00:00'
  }
}
2021-11-18 23:31:17.498  DEBUG [HTTPApi.updateDeviceInfo] Stations - Response:
2021-11-18 23:31:17.498  ERROR [HTTPApi.updateDeviceInfo] Status return code not 200
{
  status: 204,
  statusText: 'No Content'
}

Versions:

Additional context
The calls don't always fail. For example, two calls right after each other:

2021-11-18 21:11:52.841  DEBUG [HTTPApi.request] Request:
{
  method: 'post',
  endpoint: 'app/cipher/get_ciphers',
  baseUrl: 'https://security-app-eu.eufylife.com/v1',
  token: '<REDACTED>',
  data: {
    cipher_ids: [
      16
    ],
    user_id: '<REDACTED>',
    transaction: '1637269912840'
  },
  headers: {
    app_version: 'v2.8.0_887',
    os_type: 'android',
    os_version: '30',
    phone_model: 'EUFYCLIENT',
    country: 'GB',
    language: 'en',
    openudid: '<REDACTED>',
    uid: '',
    net_type: 'wifi',
    mnc: '02',
    mcc: '262',
    sn: '<REDACTED>',
    Model_type: 'PHONE',
    timezone: 'GMT+00:00'
  }
}
2021-11-18 21:11:52.986  DEBUG [HTTPApi.getCiphers] Response:
{
  code: 0,
  msg: 'Succeed.',
  data: [
    {
      cipher_id: 16,
      user_id: '<REDACTED>',
      private_key: '-----BEGIN RSA PRIVATE KEY-----\n' +
        '<REDACTED>' +
        '-----END RSA PRIVATE KEY-----\n'
    }
  ]
}
2021-11-18 21:11:52.987  DEBUG [HTTPApi.request] Request:
{
  method: 'post',
  endpoint: 'app/cipher/get_ciphers',
  baseUrl: 'https://security-app-eu.eufylife.com/v1',
  token: '<REDACTED>',
  data: {
    cipher_ids: [
      16
    ],
    user_id: '<REDACTED>',
    transaction: '1637269912987'
  },
  headers: {
    app_version: 'v2.8.0_887',
    os_type: 'android',
    os_version: '30',
    phone_model: 'EUFYCLIENT',
    country: 'GB',
    language: 'en',
    openudid: '<REDACTED>',
    uid: '',
    net_type: 'wifi',
    mnc: '02',
    mcc: '262',
    sn: '<REDACTED>',
    Model_type: 'PHONE',
    timezone: 'GMT+00:00'
  }
}
2021-11-18 21:11:53.106  DEBUG [HTTPApi.getCiphers] Response:
2021-11-18 21:11:53.106  ERROR [HTTPApi.getCiphers] Status return code not 200
{
  status: 204,
  statusText: 'No Content'
}
Malnes commented 2 years ago

I believe the EU endpoint (ot at least the one for norway) is wrong.

This is just a guess as I don't know what I'm doing, but it seems like it tries to retrieve the token from https://security-app-eu.eufylife.com/v1. I am able to retrieve token when using this endpoint: https://mysecurity.eufylife.com/api/v1/passport/login

I have the following error:

2021-11-19 23:02:52.162 INFO Authentication properties changed, invalidate saved cloud token. 2021-11-19 23:02:52.218 INFO Eufy Security server listening on port 3000 2021-11-19 23:02:53.443 INFO Switching to another API_BASE (https://security-app-eu.eufylife.com/v1) and get new token. 2021-11-19 23:02:53.644 ERROR Status return code not 200 { status: 204, statusText: 'No Content' } 2021-11-19 23:02:53.658 ERROR Token error

bropat commented 2 years ago

Eufy has made some changes to its site, which now often results in HTTP errors (204). I have seen that the entry endpoint in the Eufy app has changed. I am trying to understand what has changed and how to get everything working again.

That is the disadvantage of no open API... :(

danstreeter commented 2 years ago

Anything I can do to help @bropat.

I'm a software engineer (however no experience in typescript) but happy to help if I can.

Let me know if there are any mitm tests I can run as I'm UK based so will get an EU API endpoint.

Hillariously just bought the Eufy2k Wireless Doorbell with hopes/guides on getting it setup in Home Assistant, so keen to get it working! =)

bropat commented 2 years ago

@danstreeter Thank you for the offer, but I think I have solved the problem. I am currently testing the solution. It looks like Eufy is now using HTTP/2 and the library I used does not support it yet.

danstreeter commented 2 years ago

Ah awesome nice one. Let me know if you need any testing doing. I’m running docker so presumably if I can build the image locally I can test that way if needed.