Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 77b0b95

Browse files
committed
Use async native way to get server certificate
1 parent 856239f commit 77b0b95

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • packages/jumpstarter/jumpstarter/common

packages/jumpstarter/jumpstarter/common/grpc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import base64
23
import os
34
import socket
@@ -8,7 +9,6 @@
89

910
import grpc
1011
from anyio import fail_after
11-
from anyio.to_thread import run_sync
1212

1313
from jumpstarter.common.exceptions import ConfigurationError, ConnectionError
1414

@@ -24,7 +24,13 @@ async def ssl_channel_credentials(target: str, tls_config, timeout=5):
2424

2525
try:
2626
with fail_after(timeout):
27-
root_certificates = await run_sync(ssl.get_server_certificate, (parsed.hostname, port))
27+
ssl_context = ssl.create_default_context()
28+
ssl_context.check_hostname = False
29+
ssl_context.verify_mode = ssl.CERT_NONE
30+
_, writer = await asyncio.open_connection(parsed.hostname, port, ssl=ssl_context)
31+
root_certificates = ""
32+
for cert in writer.get_extra_info("ssl_object")._sslobj.get_unverified_chain():
33+
root_certificates += cert.public_bytes()
2834
return grpc.ssl_channel_credentials(root_certificates=root_certificates.encode())
2935
except socket.gaierror as e:
3036
raise ConnectionError(f"Failed resolving {parsed.hostname}") from e

0 commit comments

Comments
 (0)