Skip to content

Commit 65318c5

Browse files
committed
Add a timeout
1 parent 51a5b1c commit 65318c5

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

nanokvm/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def obfuscate_password(password: str) -> str:
5656
return urllib.parse.quote(base64.b64encode(password_enc).decode("utf-8"), safe="")
5757

5858

59-
async def async_fetch_remote_fingerprint(url: str) -> str:
59+
async def async_fetch_remote_fingerprint(
60+
url: str, *, timeout: float | None = 10.0
61+
) -> str:
6062
"""Retrieve the SHA-256 fingerprint of the remote server's TLS certificate.
6163
6264
Connects to the server with verification disabled to grab the raw certificate,
@@ -73,7 +75,8 @@ async def async_fetch_remote_fingerprint(url: str) -> str:
7375
ssl_ctx.check_hostname = False
7476
ssl_ctx.verify_mode = ssl.CERT_NONE
7577

76-
reader, writer = await asyncio.open_connection(hostname, port, ssl=ssl_ctx)
78+
async with asyncio.timeout(timeout):
79+
reader, writer = await asyncio.open_connection(hostname, port, ssl=ssl_ctx)
7780

7881
try:
7982
ssl_obj = writer.get_extra_info("ssl_object")

0 commit comments

Comments
 (0)