Skip to content

Commit 462964a

Browse files
committed
Temporarily reverted the following commit which caused connection failure for some Docker containers when SSL was enabled: “refactor(Connection): explicitly use TLS protocol for underlying connection socket. previously TLS protocol was used by default. resolves deprecation warnings in Python 3.11"
1 parent 0cc68a9 commit 462964a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Diff for: redshift_connector/core.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ def get_calling_module() -> str:
563563

564564
if credentials_provider.split(".")[-1] in ("IdpTokenAuthPlugin",):
565565
redshift_native_auth = True
566-
self.set_idc_plugins_params(init_params, credentials_provider, identity_namespace, token_type)
566+
self.set_idc_plugins_params(
567+
init_params, credentials_provider, identity_namespace, token_type
568+
)
567569

568570
if redshift_native_auth and provider_name:
569571
init_params["provider_name"] = provider_name
@@ -633,16 +635,18 @@ def get_calling_module() -> str:
633635
# create ssl connection with Redshift CA certificates and check the hostname
634636
if ssl is True:
635637
try:
636-
from ssl import PROTOCOL_TLS_CLIENT, SSLContext
638+
from ssl import CERT_REQUIRED, SSLContext
639+
640+
# ssl_context = ssl.create_default_context()
637641

638642
path = os.path.abspath(__file__)
639643
if os.name == "nt":
640644
path = "\\".join(path.split("\\")[:-1]) + "\\files\\redshift-ca-bundle.crt"
641645
else:
642646
path = "/".join(path.split("/")[:-1]) + "/files/redshift-ca-bundle.crt"
643647

644-
# The protocol enables CERT_REQUIRED and check_hostname by default.
645-
ssl_context: SSLContext = SSLContext(protocol=PROTOCOL_TLS_CLIENT)
648+
ssl_context: SSLContext = SSLContext()
649+
ssl_context.verify_mode = CERT_REQUIRED
646650
ssl_context.load_default_certs()
647651
_logger.debug("try to load Redshift CA certs from location %s", path)
648652
ssl_context.load_verify_locations(path)
@@ -658,13 +662,12 @@ def get_calling_module() -> str:
658662

659663
if sslmode == "verify-ca":
660664
_logger.debug("applying sslmode=%s to socket", sslmode)
661-
ssl_context.check_hostname = False
662665
self._usock = ssl_context.wrap_socket(self._usock)
663666
elif sslmode == "verify-full":
664667
_logger.debug("applying sslmode=%s to socket and force check_hostname", sslmode)
668+
ssl_context.check_hostname = True
665669
self._usock = ssl_context.wrap_socket(self._usock, server_hostname=host)
666670
else:
667-
ssl_context.check_hostname = False
668671
_logger.debug("unknown sslmode=%s is ignored", sslmode)
669672
_logger.debug("Socket SSL details: %s", self._usock.cipher()) # type: ignore
670673

Diff for: test/integration/auth/test_iam_auth.py

Whitespace-only changes.

0 commit comments

Comments
 (0)