Skip to content

Commit e2d9cc4

Browse files
committed
fix: validate CA certificate file exists before SSL context creation
Add file existence check for CA certificate before passing to ssl.create_default_context(). This prevents runtime errors when the CA cert file is missing or path is incorrect. Addresses Copilot suggestion. Signed-off-by: Scott R. Shinn <scott@atomicorp.com>
1 parent 63d5657 commit e2d9cc4

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tools/chelon_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ def _make_request(self, endpoint: str, data: Dict[str, Any]) -> Dict[str, Any]:
9191

9292
# Setup SSL context
9393
if self.verify_ssl:
94-
# When verifying SSL, use the provided CA certificate file
95-
ssl_context = ssl.create_default_context(cafile=str(self.ca_cert))
94+
# When verifying SSL, ensure the provided CA certificate file exists before using it
95+
ca_cert_path = Path(self.ca_cert) if not isinstance(self.ca_cert, Path) else self.ca_cert
96+
if not ca_cert_path.is_file():
97+
raise ChelonClientError(f"CA certificate file not found: {ca_cert_path}")
98+
ssl_context = ssl.create_default_context(cafile=str(ca_cert_path))
9699
else:
97100
# When not verifying SSL, do not load a CA file
98101
ssl_context = ssl.create_default_context()

0 commit comments

Comments
 (0)