Skip to content

Commit e149699

Browse files
committed
feat(#92): load CA certificate directly from memory instead of temp file
Refactor SSL context creation to use in-memory certificate loading via cadata parameter instead of writing to a temporary file. This simplifies the code by removing file I/O operations and temporary file cleanup, improving performance and reducing potential issues with file system access.
1 parent d0a8948 commit e149699

File tree

1 file changed

+2
-9
lines changed
  • python/dify_plugin/core/utils

1 file changed

+2
-9
lines changed

python/dify_plugin/core/utils/ssl.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,8 @@ def _create_ssl_context(config: DifyPluginEnv) -> ssl.SSLContext | bool:
7171
if has_ca_cert:
7272
ca_cert_data = _decode_base64_cert(config.HTTP_REQUEST_NODE_SSL_CERT_DATA)
7373
if ca_cert_data:
74-
# Write CA cert to temporary file and load it
75-
with tempfile.NamedTemporaryFile(mode="wb", suffix=".pem", delete=False) as ca_file:
76-
ca_file.write(ca_cert_data)
77-
ca_cert_path = ca_file.name
78-
try:
79-
ssl_context.load_verify_locations(cafile=ca_cert_path)
80-
finally:
81-
# Clean up temporary file
82-
Path(ca_cert_path).unlink(missing_ok=True)
74+
# Load CA cert data directly from memory to avoid writing to a temporary file.
75+
ssl_context.load_verify_locations(cadata=ca_cert_data.decode("utf-8"))
8376

8477
# Load client certificate and key for mutual TLS if provided
8578
if has_client_cert and has_client_key:

0 commit comments

Comments
 (0)