-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Make cert_expiry work with self-signed / private CA signed certificates #137452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cromefire
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Hey there @jjlawren, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
So it doesn't seem like the async way can be used, because it just doesn't properly provide the peer certificate, so the stdlib way it is. Also also the docs on setting everything up properly seem to be somewhat trash, it seems to miss many of the packages required for some tests and so a bunch of tests just fail all the time. |
@@ -67,7 +66,7 @@ async def async_step_user( | |||
await self.async_set_unique_id(f"{host}:{port}") | |||
self._abort_if_unique_id_configured() | |||
|
|||
if await self._test_connection(user_input): | |||
if self._test_connection(user_input): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't just do sync operation in async context; this is blocking the loop now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only option I can think of is spawning a background thread and awaiting the result. IIRC from my python days many years ago there is a way in the multiprocessing module to do that with a thread pool of some sort. Would that be acceptable?
I don't suppose I've got any other options here, as the async way it was done before only seems to provide the parsed cert, which is only populated if certificate validation is disabled, which it has to be to fix the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a different comment with the hope of helping keep everything pure async (which would be my own preference), but the homeassistant-standard way of achieving this safely would be to follow this:
https://developers.home-assistant.io/docs/asyncio_working_with_async/#calling-sync-functions-from-async
example from linked page:
# hub.update() is a sync function.
result = await hass.async_add_executor_job(hub.update)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frenck I wrapped the socket call into hass.async_add_executor_job
now, is that acceptable? I will still have to retest, didn't get to that yet, but functionality should be the same.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Guys, while you are working on the PR, can you also change to : add 2 lines:
this will fix/close issue: |
No completely sure what you're trying to achieve, but the whole call has changed to: context = get_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
context.verify_flags = context.verify_flags | ssl.VERIFY_CRL_CHECK_CHAIN
conn = socket.create_connection((host, port), timeout=TIMEOUT)
sock = context.wrap_socket(conn, server_hostname=host) so I'd ask you to retest once this has landed and see if your issue persists at all. |
Not sure where the merging of this PR stands, but the code change request specifically targets the following:
change to
|
It does, otherwise self-signed certs don't work. I'm currently waiting on a review with the changes I made. |
Breaking change
Not 100% sure. If people relied on this for checking the cert chain it'd break, but that wasn't the mission of this extension, so IMO this should be fine.
Proposed change
Removes the validation of the certifivate
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: