Skip to content

Commit

Permalink
updating ssl context codition
Browse files Browse the repository at this point in the history
  • Loading branch information
mdazam1942 committed Nov 21, 2023
1 parent d7310cb commit 1e9c0ae
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions stix_shifter_utils/stix_transmission/utils/RestApiClientAsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def __init__(self, host, port=None, headers={}, url_modifier_function=None, cert
# self signed cert provided
elif isinstance(cert_verify, str):
self.server_cert_file_content = cert_verify
self.ssl_context = True

if self.ssl_context:
self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS)
self.ssl_context.verify_mode = ssl.CERT_REQUIRED
self.ssl_context.check_hostname = True

self.headers = headers
self.url_modifier_function = url_modifier_function
Expand All @@ -86,16 +92,12 @@ async def call_api(self, endpoint, method, headers=None, cookies=None, data=None
f.write(self.server_cert_file_content)
except IOError:
self.logger.error('Failed to setup certificate')

self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS)

try:
self.ssl_context.load_verify_locations(self.server_cert_name)
except Exception as ex:
self.logger.debug('Unable to load the certificate for ssl context. Reasons: Connection does not require certifcate or unexpected exception while loading the certificate: ' + str(ex))

self.ssl_context.verify_mode = ssl.CERT_REQUIRED
self.ssl_context.check_hostname = True
if self.ssl_context and self.server_cert_file_content:
try:
self.ssl_context.load_verify_locations(self.server_cert_name)
except Exception as ex:
self.logger.debug('Unable to load the certificate for ssl context. Reasons: Connection does not require certificate or unexpected exception while loading the certificate: ' + str(ex))

url = None
actual_headers = self.headers.copy()
Expand Down

0 comments on commit 1e9c0ae

Please sign in to comment.