@@ -14,22 +14,40 @@ def expand_path(path):
1414 return path
1515
1616
17- def create_ssl_context ():
18- # Try truststore first (system certificates)
17+ def get_ca_bundle_path () -> str | None :
18+ """Resolve CA bundle path from environment variables.
19+
20+ Returns None if SSL verification is disabled via UIPATH_DISABLE_SSL_VERIFY.
21+ Otherwise returns the CA bundle path with priority:
22+ SSL_CERT_FILE > REQUESTS_CA_BUNDLE > certifi default.
23+ """
24+ disable_ssl_env = os .environ .get ("UIPATH_DISABLE_SSL_VERIFY" , "" ).lower ()
25+ if disable_ssl_env in ("1" , "true" , "yes" , "on" ):
26+ return None
27+
28+ import certifi
29+
30+ ssl_cert_file = expand_path (os .environ .get ("SSL_CERT_FILE" ))
31+ requests_ca_bundle = expand_path (os .environ .get ("REQUESTS_CA_BUNDLE" ))
32+
33+ return ssl_cert_file or requests_ca_bundle or certifi .where ()
34+
35+
36+ def create_ssl_context (cafile : str ):
37+ """Create an SSL context for httpx clients.
38+
39+ Args:
40+ cafile: Path to the CA bundle file.
41+ """
1942 try :
2043 import truststore
2144
2245 return truststore .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
2346 except ImportError :
24- # Fallback to manual certificate configuration
25- import certifi
26-
27- ssl_cert_file = expand_path (os .environ .get ("SSL_CERT_FILE" ))
28- requests_ca_bundle = expand_path (os .environ .get ("REQUESTS_CA_BUNDLE" ))
2947 ssl_cert_dir = expand_path (os .environ .get ("SSL_CERT_DIR" ))
3048
3149 return ssl .create_default_context (
32- cafile = ssl_cert_file or requests_ca_bundle or certifi . where () ,
50+ cafile = cafile ,
3351 capath = ssl_cert_dir ,
3452 )
3553
@@ -44,13 +62,9 @@ def get_httpx_client_kwargs(
4462 Caller headers take priority on key conflicts.
4563 """
4664 client_kwargs : Dict [str , Any ] = {"follow_redirects" : True , "timeout" : 30.0 }
47- disable_ssl_env = os .environ .get ("UIPATH_DISABLE_SSL_VERIFY" , "" ).lower ()
48- disable_ssl_from_env = disable_ssl_env in ("1" , "true" , "yes" , "on" )
4965
50- if disable_ssl_from_env :
51- client_kwargs ["verify" ] = False
52- else :
53- client_kwargs ["verify" ] = create_ssl_context ()
66+ ca_bundle = get_ca_bundle_path ()
67+ client_kwargs ["verify" ] = create_ssl_context (ca_bundle ) if ca_bundle else False
5468
5569 from ._config import UiPathConfig
5670 from .constants import HEADER_LICENSING_CONTEXT
0 commit comments