runDMCA / home-assistant-mazda

Custom component for Home Assistant that adds integration for Mazda Connected Services
Apache License 2.0
64 stars 30 forks source link

Issue with HA 2024.7 #5

Open DiVrox opened 4 months ago

DiVrox commented 4 months ago

Thanks for you work! I really love this integration. No issues so far untill last night ... upgraded HA to 2024.7.0 and since then, the integration keeps initializing. Anyone else experiencing the same problem?

ilwalti commented 4 months ago

Same here. App on smartphone works fine.

I've got this debug log:

Traceback (most recent call last):
  File "/config/custom_components/mazda/__init__.py", line 154, in async_update_data
    vehicles = await with_timeout(mazda_client.get_vehicles())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/__init__.py", line 56, in with_timeout
    async with asyncio.timeout(timeout_seconds):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError
2024-07-04 11:31:41.672 ERROR (MainThread) [custom_components.mazda] Unknown error occurred during Mazda update request: 
Traceback (most recent call last):
  File "/config/custom_components/mazda/__init__.py", line 57, in with_timeout
    return await task
           ^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/client.py", line 30, in get_vehicles
    vec_base_infos_response = await self.controller.get_vec_base_infos()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/controller.py", line 30, in get_vec_base_infos
    return await self.connection.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 191, in api_request
    return await self.__api_request_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 221, in __api_request_retry
    return await self.__send_api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 329, in __send_api_request
    response = await self._session.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 608, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 976, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/streams.py", line 640, in read
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/mazda/__init__.py", line 154, in async_update_data
    vehicles = await with_timeout(mazda_client.get_vehicles())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/__init__.py", line 56, in with_timeout
    async with asyncio.timeout(timeout_seconds):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError
2024-07-04 11:32:39.381 INFO (MainThread) [custom_components.mazda.pymazda.connection] Logging in as MY_SECOND_DRIVER
2024-07-04 11:32:39.381 INFO (MainThread) [custom_components.mazda.pymazda.connection] Retrieving public key to encrypt password
2024-07-04 11:32:39.800 INFO (MainThread) [custom_components.mazda.pymazda.connection] Sending login request
2024-07-04 11:32:39.934 INFO (MainThread) [custom_components.mazda.pymazda.connection] Successfully logged in as MY_SECOND_DRIVER
2024-07-04 11:32:39.935 INFO (MainThread) [custom_components.mazda.pymazda.connection] Retrieving encryption keys
2024-07-04 11:32:39.935 DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to service/checkVersion
2024-07-04 11:32:40.297 INFO (MainThread) [custom_components.mazda.pymazda.connection] Successfully retrieved encryption keys
2024-07-04 11:32:40.297 DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to remoteServices/getVecBaseInfos/v4
2024-07-04 11:33:09.940 ERROR (MainThread) [custom_components.mazda] Unknown error occurred during Mazda update request: 
Traceback (most recent call last):
  File "/config/custom_components/mazda/__init__.py", line 57, in with_timeout
    return await task
           ^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/client.py", line 30, in get_vehicles
    vec_base_infos_response = await self.controller.get_vec_base_infos()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/controller.py", line 30, in get_vec_base_infos
    return await self.connection.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 191, in api_request
    return await self.__api_request_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 221, in __api_request_retry
    return await self.__send_api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/pymazda/connection.py", line 329, in __send_api_request
    response = await self._session.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 608, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 976, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/streams.py", line 640, in read
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/mazda/__init__.py", line 154, in async_update_data
    vehicles = await with_timeout(mazda_client.get_vehicles())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mazda/__init__.py", line 56, in with_timeout
    async with asyncio.timeout(timeout_seconds):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError
2024-07-04 11:33:09.943 DEBUG (MainThread) [custom_components.mazda] Finished fetching mazda data in 30.009 seconds (success: False)

I'm available for further debugging...

Grigorek commented 4 months ago

I can confirm, some logs like @ilwalti

Maggus574 commented 4 months ago

Hey!

Same problem here since Update to HA2024.7.

deherw commented 4 months ago

yep, me to.

ghammer80 commented 4 months ago

Same here.

oransterf commented 4 months ago

the irony that I had installed this only a few days ago and now it doesn't work anymore

doosterkamp commented 4 months ago

+1 Sam issue (and log entries) since 2024.7 over here also!

ilwalti commented 4 months ago

An update, but I don't know if it is somewhat related tho this issue... today I've received on the official app an advice that says that Mymazda app isn't reachable july 9, between 0100 and 0700 CEST, due to a programmed mainteance. Maybe they're doing something on the users' database

Bye

ctml91 commented 4 months ago

Same. Downgraded to 2024.6 docker.io/homeassistant/home-assistant:2024.6 and all working again. Will wait for someone to figure out a fix to upgrade HA :)

DiVrox commented 4 months ago

I can confirm core 2024.7.1 doesn't work either. Same error.

Downgraded to core 2024.6.4 and everything works fine again.

If I can be of any help testing something, let me know

formiification commented 4 months ago

shit... same story here; probably this project is not supported anymore, so downgrade to 2024.6 is not an option for longer time

deltamikeromeo commented 4 months ago

Same issue for me.

townsmcp commented 4 months ago

Same issue for me. I’m not a dev but it seems like HA apis have changed. For example the following API calls exist in the code found here https://developers.home-assistant.io/blog/2024/04/13/deprecate_async_track_state_change/. Also calls exist for async_forward_entry_setups. Are there any devs here that know about the deprecated calls and how to get round them?

ilwalti commented 4 months ago

Same issue for me. I’m not a dev but it seems like HA apis have changed.

This is for sure. At the moment, I can't find what is changed, unfortunately... @runDMCA , are you still on this project?

doosterkamp commented 4 months ago

Funny thing is that the first API requests are successful, but theres a time-out when sending a POST request to remoteServices/getVecBaseInfos/v4

INFO (MainThread)  [custom_components.mazda.pymazda.connection] Logging in as XXXXXX@XXXXXXXXXX.XXX
INFO (MainThread)  [custom_components.mazda.pymazda.connection] Retrieving public key to encrypt password
INFO (MainThread)  [custom_components.mazda.pymazda.connection] Sending login request
INFO (MainThread)  [custom_components.mazda.pymazda.connection] Successfully logged in as XXXXXX@XXXXXXXXXX.XXX
INFO (MainThread)  [custom_components.mazda.pymazda.connection] Retrieving encryption keys
DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to service/checkVersion
INFO (MainThread)  [custom_components.mazda.pymazda.connection] Successfully retrieved encryption keys
DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to remoteServices/getVecBaseInfos/v4
ERROR (MainThread) [custom_components.mazda] Unknown error occurred during Mazda update request: 
                      Traceback (most recent call last):
                        File "/config/custom_components/mazda/__init__.py", line 57, in with_timeout
                          return await task
                                ^^^^^^^^^^
                        File "/config/custom_components/mazda/pymazda/client.py", line 30, in get_vehicles
                          vec_base_infos_response = await self.controller.get_vec_base_infos()
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/config/custom_components/mazda/pymazda/controller.py", line 30, in get_vec_base_infos
                          return await self.connection.api_request(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/config/custom_components/mazda/pymazda/connection.py", line 191, in api_request
                          return await self.__api_request_retry(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/config/custom_components/mazda/pymazda/connection.py", line 221, in __api_request_retry
                          return await self.__send_api_request(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/config/custom_components/mazda/pymazda/connection.py", line 329, in __send_api_request
                          response = await self._session.request(
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 608, in _request
                          await resp.start(conn)
                        File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 976, in start
                          message, payload = await protocol.read()  # type: ignore[union-attr]
                                            ^^^^^^^^^^^^^^^^^^^^^
                        File "/usr/local/lib/python3.12/site-packages/aiohttp/streams.py", line 640, in read
                          await self._waiter
                      asyncio.exceptions.CancelledError
                      The above exception was the direct cause of the following exception:
                      Traceback (most recent call last):
                        File "/config/custom_components/mazda/__init__.py", line 154, in async_update_data
                          vehicles = await with_timeout(mazda_client.get_vehicles())
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        File "/config/custom_components/mazda/__init__.py", line 56, in with_timeout
                          async with asyncio.timeout(timeout_seconds):
                        File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
                          raise TimeoutError from exc_val
                      TimeoutError
DEBUG (MainThread) [custom_components.mazda] Finished fetching mazda data in 120.005 seconds (success: False)
townsmcp commented 4 months ago

I did try upping line 57 of file init.py timeout from 30 seconds to 60 seconds and reboot HA but it still didn’t pull in anything on 2024.07

ilwalti commented 4 months ago

I did try upping line 57 of file init.py timeout from 30 seconds to 60 seconds and reboot HA but it still didn’t pull in anything on 2024.07

Did the same, no joy...

guba91 commented 4 months ago

same problem here.. tryied to find the function that throw the error but my limited programming skill are a problem lol

doosterkamp commented 4 months ago

Found the cause of the issue !!! Just not sure how to fix it, yet ...

In 2024.7.x the aiohttp-fast-zlib package was updated from 0.1.0 to 0.1.1. After manually reverting to 0.1.0 (in a HA development container) and restarting HA the integration works again.

Now searching for a solution ...

bdraco commented 4 months ago

https://github.com/runDMCA/home-assistant-mazda/blob/a9fd47f59825070118c4dda59a0e707ad0c0e707/custom_components/mazda/__init__.py#L54 is wrapping all the aiohttp calls with yet another timeout.

Use the built-in timeout with aiohttp instead by setting timeout= on the request so if the timeout hits it doesn't propagate cancellation to aiohttp which may get things in a bad state. https://github.com/runDMCA/home-assistant-mazda/blob/a9fd47f59825070118c4dda59a0e707ad0c0e707/custom_components/mazda/pymazda/connection.py#L329

https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientTimeout

eliogrin commented 4 months ago

https://github.com/runDMCA/home-assistant-mazda/blob/a9fd47f59825070118c4dda59a0e707ad0c0e707/custom_components/mazda/__init__.py#L54

is wrapping all the aiohttp calls with yet another timeout. Use the built-in timeout with aiohttp instead by setting timeout= on the request so if the timeout hits it doesn't propagate cancellation to aiohttp which may get things in a bad state.

https://github.com/runDMCA/home-assistant-mazda/blob/a9fd47f59825070118c4dda59a0e707ad0c0e707/custom_components/mazda/pymazda/connection.py#L329

https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientTimeout

Thanks for suggestions. I tried to did what you mentioned, but seems it doesn't help, maybe you have any other ideas?

What I did:

  1. Removed withTimeout method, and update it to do direct call, like: vehicles = await mazda_client.get_vehicles() instead of: vehicles = await with_timeout(mazda_client.get_vehicles())
  2. Update request initialization with built-in timeout of aiohttp:

        clientTimeout = ClientTimeout(total=TIMEOUT)
    
        async with self._session.request(
            method,
            self.base_url + uri,
            headers=headers,
            data=encrypted_body_Str,
            ssl=ssl_context,
            timeout=clientTimeout,
        ) as response:
            response_json = await response.json()

But still getting error:

2024-07-11 17:24:37.593 ERROR (MainThread) [custom_components.mazda] Unknown error occurred during Mazda update request:
Traceback (most recent call last):
File "/config/custom_components/mazda/__init__.py", line 147, in async_update_data
vehicles = await mazda_client.get_vehicles()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mazda/pymazda/client.py", line 30, in get_vehicles
vec_base_infos_response = await self.controller.get_vec_base_infos()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mazda/pymazda/controller.py", line 30, in get_vec_base_infos
return await self.connection.api_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mazda/pymazda/connection.py", line 193, in api_request
return await self.__api_request_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mazda/pymazda/connection.py", line 223, in __api_request_retry
return await self.__send_api_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mazda/pymazda/connection.py", line 333, in __send_api_request
async with self._session.request(
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__
self._resp = await self._coro
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 608, in _request
await resp.start(conn)
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 971, in start
with self._timer:
File "/usr/local/lib/python3.12/site-packages/aiohttp/helpers.py", line 735, in __exit__
raise asyncio.TimeoutError from None
TimeoutError
formiification commented 4 months ago

Anyone able to fork this project and fix the code?

SethCalkins commented 4 months ago

Sorry guys, I have limited knowledge here but looks like possibly the API calls have changed -- I probably spent 4 hours last night working on this --- debug showed it was failing on this

controller.py

    async def get_vec_base_infos(self):  # noqa: D102
        return await self.connection.api_request(
            "POST",
            "remoteServices/getVecBaseInfos/v4",
            body_dict={"internaluserid": "__INTERNAL_ID__"},
            needs_keys=True,
            needs_auth=True,
        )

Logs:

INFO:pymazda.connection:Retrieving encryption keys
DEBUG:pymazda.connection:Sending POST request to service/checkVersion
INFO:pymazda.connection:Successfully retrieved encryption keys
INFO:pymazda.connection:No access token present. Logging in.
INFO:pymazda.connection:Logging in as myemail@bla.com
INFO:pymazda.connection:Retrieving public key to encrypt password
INFO:pymazda.connection:Sending login request
INFO:pymazda.connection:Successfully logged in as sethcalkins@icloud.com
DEBUG:pymazda.connection:Sending POST request to remoteServices/getVecBaseInfos/v4
townsmcp commented 4 months ago

@SethCalkins if the API calls have changed I wouldnt expect previous HA version to still work? Thank you for your effort though, it is appreciated

DiVrox commented 4 months ago

Anyone tried this with the 2024.7.3 release?

Valdorama commented 4 months ago

Anyone tried this with the 2024.7.3 release?

Yes, still doesn't work. Based on the comments in here, it looks like there is a potential fix but it needs to be merged and released.

townsmcp commented 4 months ago

@Valdorama if you are on 2024.7.3 you can try the fix documented at https://github.com/runDMCA/home-assistant-mazda/compare/main...SethCalkins:home-assistant-mazda:main. Just update the code in the file in your instance, reboot HA and see what happens

Valdorama commented 4 months ago

@townsmcp Didn't seem to work:

Traceback (most recent call last): File "/config/custom_components/mazda/__init__.py", line 155, in async_update_data vehicles = await with_timeout(mazda_client.get_vehicles()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/mazda/__init__.py", line 58, in with_timeout return await asyncio.wait_for(task, timeout_seconds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for async with timeouts.timeout(timeout): File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__ raise TimeoutError from exc_val TimeoutError

Note that this is with a separate login (via the 'Secondary Driver' feature in the Mazda app), though that has been working fine up till these recent isuse.

townsmcp commented 4 months ago

@Valdorama damn. That’s a shame. Thank you for trying. Might be time to roll back to previous backup before 2024.7?

DiVrox commented 4 months ago

So it seems we have to accept (for now) we're gonna loose the Mazda Connect Integration? :-(

crash0verride11 commented 4 months ago

Until I found this issue, I've been operating under the idea that the 2024.7 update changed something to cause Mazda to more aggressively TLS fingerprint, which is an issue with the underlying pymazda code: ungineer/pymazda#warning---tls-fingerprinting. None of my work arounds have been able to help, but maybe this gives someone else some more ideas.

DMCAMazda commented 4 months ago

Until I found this issue, I've been operating under the idea that the 2024.7 update changed something to cause Mazda to more aggressively TLS fingerprint, which is an issue with the underlying pymazda code: ungineer/pymazda#warning---tls-fingerprinting. None of my work arounds have been able to help, but maybe this gives someone else some more ideas.

maybe this will help someone ? https://github.com/DMCAMazda/node-mymazda

ilwalti commented 4 months ago

Yes, it will, but... how install it on HA?

crash0verride11 commented 4 months ago

Yes, it will, but... how install it on HA?

pymazda and node-mymazda are just the parts of the code making the calls to Mazda. The integration would need to be rewritten to make calls using node-mymazda instead of pymazda. Wonder if there was already a branch in progress before the takedown?

ilwalti commented 4 months ago

All the forks seem to be involved in takedown... https://github.com/github/dmca/blob/master/2023/10/2023-10-10-mazda.md

SethCalkins commented 4 months ago

Until I found this issue, I've been operating under the idea that the 2024.7 update changed something to cause Mazda to more aggressively TLS fingerprint, which is an issue with the underlying pymazda code: ungineer/pymazda#warning---tls-fingerprinting. None of my work arounds have been able to help, but maybe this gives someone else some more ideas.

https://github.com/home-assistant/core/issues/77214#issuecomment-1224717412

Changing Ciphers on this might help?

townsmcp commented 4 months ago

Can someone who is running 2024.7.x please find out what version of Python their HA has installed? Looking for a HAOS Supervised install. My instance running 2024.6.4 is on python 3.12.3. I have a hunch that 2024.7.x has a higher version of Python which is what could be breaking the integration - if that is the case, next steps are how to add a line to the manifest.json as a requirement: Screen Shot 2024-07-26 at 15 46 22 To find the Python version, load the addon Advanced SSH & Web Terminal, and at the CLI type python3 --version

SethCalkins commented 4 months ago

Can someone who is running 2024.7.x please find out what version of Python their HA has installed? Looking for a HAOS Supervised install. My instance running 2024.6.4 is on python 3.12.3. I have a hunch that 2024.7.x has a higher version of Python which is what could be breaking the integration - if that is the case, next steps are how to add a line to the manifest.json as a requirement: Screen Shot 2024-07-26 at 15 46 22 To find the Python version, load the addon Advanced SSH & Web Terminal, and at the CLI type python3 --version

I'm running 3.12.3

ilwalti commented 4 months ago

3.12.3 is the current one.

townsmcp commented 4 months ago

Damn. Thats a shame. I could be completely off track with the next one, but I have been looking at some past recent errors with other integrations and it seems like something called mashumaro version was updated late 2024.6/2024.7 and it broke an awful lot, specifically integrations were timing out. I wonder in Mazda integration uses that? And if so, if we can somehow pin the old version? In the full changelog there is a line that states Revert “Temporary pin CI to Python 3.12.3” ([@epenet](https://github.com/epenet) - [#119454](https://github.com/home-assistant/core/pull/119454)) and when you look in to that thread, you can see Nest and other integrations were impacted in preparation for Python 3.12.4

SethCalkins commented 4 months ago

Damn. Thats a shame.

I could be completely off track with the next one, but I have been looking at some past recent errors with other integrations and it seems like something called mashumaro version was updated late 2024.6/2024.7 and it broke an awful lot, specifically integrations were timing out. I wonder in Mazda integration uses that? And if so, if we can somehow pin the old version? In the full changelog there is a line that states Revert “Temporary pin CI to Python 3.12.3” ([@epenet](https://github.com/epenet) - [#119454](https://github.com/home-assistant/core/pull/119454)) and when you look in to that thread, you can see Nest and other integrations were impacted in preparation for Python 3.12.4

I'm trying to tackle it from the SSL cert side

Valdorama commented 4 months ago

I'm on 3.12.4, running HA Container

holysoles commented 4 months ago

I have been hitting this for my virtualized HAOS install so tried setting up a HA dev container on the latest version of dev to try to be able to attach a debugger for more context when we hit the timeout, and using the same account information, it retrieves data just fine from the Mazda API.

I grabbed some packet captures to compare the two clients and didn't see any real difference between the requests they were sending (same cipher suite list+order during TLS handshake, etc) . If anyone else has suggestions on comparisons to run, I'm happy to do more testing.

I also compared the results of pip list from both setups and while the dev container had a couple packages on higher versions, reviewing release notes for those didnt yield anything that I would consider proof that a fix was released for a dependency.

MartinAirN commented 4 months ago

I have been hitting this for my virtualized HAOS install so tried setting up a HA dev container on the latest version of dev to try to be able to attach a debugger for more context when we hit the timeout, and using the same account information, it retrieves data just fine from the Mazda API.

I grabbed some packet captures to compare the two clients and didn't see any real difference between the requests they were sending (same cipher suite list+order during TLS handshake, etc) . If anyone else has suggestions on comparisons to run, I'm happy to do more testing.

I also compared the results of pip list from both setups and while the dev container had a couple packages on higher versions, reviewing release notes for those didnt yield anything that I would consider proof that a fix was released for a dependency.

Do you also see the same cyphers used between HA 2024.6 (or earlier) and 2024.7? It could of course be they added specific cypher checking only to the data retrieval, and not the login. And if HA changed the default cyphers used that would also affect PyMazda.

Pointing to:


ssl_context.load_default_certs()
ssl_context.set_ciphers(
    "DEFAULT:!aNULL:!eNULL:!MD5:!3DES:!DES:!RC4:!IDEA:!SEED:!aDSS:!SRP:!PSK"
)```
SethCalkins commented 4 months ago

I have been hitting this for my virtualized HAOS install so tried setting up a HA dev container on the latest version of dev to try to be able to attach a debugger for more context when we hit the timeout, and using the same account information, it retrieves data just fine from the Mazda API. I grabbed some packet captures to compare the two clients and didn't see any real difference between the requests they were sending (same cipher suite list+order during TLS handshake, etc) . If anyone else has suggestions on comparisons to run, I'm happy to do more testing. I also compared the results of pip list from both setups and while the dev container had a couple packages on higher versions, reviewing release notes for those didnt yield anything that I would consider proof that a fix was released for a dependency.

Do you also see the same cyphers used between HA 2024.6 (or earlier) and 2024.7? It could of course be they added specific cypher checking only to the data retrieval, and not the login. And if HA changed the default cyphers used that would also affect PyMazda.

Pointing to:

ssl_context.load_default_certs()
ssl_context.set_ciphers(
    "DEFAULT:!aNULL:!eNULL:!MD5:!3DES:!DES:!RC4:!IDEA:!SEED:!aDSS:!SRP:!PSK"
)```

Checking tcpdump on my mazda app from phone and showing the folliowing cipher was used for this request https://0cxo7m58.mazda.com/prod/remoteServices/getVecBaseInfos/v4

TLSv1.2 (TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384)

holysoles commented 4 months ago

my most recent backup is on 2024.5.5, i restored to that and its working again. Took another pcap for that. On the left is the 2024.7 non-working client, the reverted client is on the right

Looks like the same cipher that @SethCalkins shared is being used in both cases for both TLS connections that get established ( 0cxo7m58.mazda.com and ptznwbh8.mazda.com)

image

I looked through the client hello packets for any differences, this is what i found:

  1. the signature_algorithms extension in the tls information is different

image

particularly these 3 are present in the capture from 2024.7

Signature Algorithm: Unknown Unknown (0x081a)
Signature Algorithm: Unknown Unknown (0x081b)
Signature Algorithm: Unknown Unknown (0x081c)
  1. there are a couple bytes difference of padding but pretty sure thats by virtue of the signature_algorithms extension being a different byte size

image

The more i look at the packet captures though the more it seems like this might be an client side application level issue rather than tls profiling, etc. In the capture, there are two long pauses of ~15 seconds, that are client side, from what I can tell all client side requests have been acknowledged by the server. that said, all this is hard to tell whats going on since i cant actually inspect the request/response contents

image

Heres the end to another pcap of it not working, similar client delay

image

I'll get some debug logs alongside a packet capture later and see what i can find through correlating those

holysoles commented 4 months ago

These probably have a small amount of time skew between them, I'm taking the packet captures on my FW.

HA debug logs:

2024-07-29 13:15:55.739 INFO (MainThread) [custom_components.mazda.pymazda.connection] Logging in as <user>
2024-07-29 13:15:55.739 INFO (MainThread) [custom_components.mazda.pymazda.connection] Retrieving public key to encrypt password
2024-07-29 13:15:56.157 INFO (MainThread) [custom_components.mazda.pymazda.connection] Sending login request
2024-07-29 13:15:56.567 INFO (MainThread) [custom_components.mazda.pymazda.connection] Successfully logged in as <user>
2024-07-29 13:15:56.568 INFO (MainThread) [custom_components.mazda.pymazda.connection] Retrieving encryption keys
2024-07-29 13:15:56.568 DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to service/checkVersion
2024-07-29 13:15:56.967 INFO (MainThread) [custom_components.mazda.pymazda.connection] Successfully retrieved encryption keys
2024-07-29 13:15:56.967 DEBUG (MainThread) [custom_components.mazda.pymazda.connection] Sending POST request to remoteServices/getVecBaseInfos/v4
2024-07-29 13:16:26.569 ERROR (MainThread) [custom_components.mazda] Unknown error occurred during Mazda update request: 

<timeout stack trace, not gonna include it yet again>

2024-07-29 13:16:26.569 DEBUG (MainThread) [custom_components.mazda] Finished fetching mazda data in 30.002 seconds (success: False)
2024-07-29 13:16:31.863 INFO (MainThread) [custom_components.mazda.pymazda.connection] Logging in as <user>

<continues to repeat successful login and hit another timeout>

packet capture image

I'm not too sure what to make of this, but might be notable that the server doesnt seem to send HTTP responses to the packets that are 259 and 152 bytes, just ACKs.

ilwalti commented 4 months ago

Just for fun, 2024.7.4 doesn't change the scenario...

SethCalkins commented 4 months ago

Maybe we need to take a step back here, remove HA from the equation --- has anyone been able to successfully return data using the pymazda module independently of home assistant?

SethCalkins commented 4 months ago

Maybe we need to take a step back here, remove HA from the equation --- has anyone been able to successfully return data using the pymazda module independently of home assistant?

The pymazda code is working --- this looks to be a HA issue ?