|
77 | 77 |
|
78 | 78 | SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION = False
|
79 | 79 |
|
80 |
| -NO_SSL_VALIDATION = False |
81 |
| -""" |
82 |
| -Turns off hostname matching validation for SSL certificates |
83 |
| -
|
84 |
| -Sometimes there are cases where certificate validation should be disabled. For example, if you |
85 |
| -have a self-signed internal certificate that isn't included in our certificate bundle, you may |
86 |
| -not require the added security provided by enforcing this. |
87 |
| -""" |
88 | 80 |
|
89 | 81 | # ----------------------------------------------------------------------------
|
90 | 82 | # Version
|
@@ -350,12 +342,11 @@ def __init__(self):
|
350 | 342 |
|
351 | 343 | self.py_version = ".".join(str(x) for x in sys.version_info[:2])
|
352 | 344 |
|
353 |
| - # extract the OpenSSL version if we can. The version is only available in Python 2.7 and |
354 |
| - # only if we successfully imported ssl |
| 345 | + # extract the OpenSSL version if we can. |
355 | 346 | self.ssl_version = "unknown"
|
356 | 347 | try:
|
357 | 348 | self.ssl_version = ssl.OPENSSL_VERSION
|
358 |
| - except (AttributeError, NameError): |
| 349 | + except AttributeError: |
359 | 350 | pass
|
360 | 351 |
|
361 | 352 | def __str__(self):
|
@@ -424,7 +415,6 @@ def __init__(self, sg):
|
424 | 415 | self.proxy_pass = None
|
425 | 416 | self.session_token = None
|
426 | 417 | self.authorization = None
|
427 |
| - self.no_ssl_validation = False |
428 | 418 | self.localized = False
|
429 | 419 |
|
430 | 420 | def set_server_params(self, base_url):
|
@@ -633,7 +623,6 @@ def __init__(
|
633 | 623 | self.config.session_token = session_token
|
634 | 624 | self.config.sudo_as_login = sudo_as_login
|
635 | 625 | self.config.convert_datetimes_to_utc = convert_datetimes_to_utc
|
636 |
| - self.config.no_ssl_validation = NO_SSL_VALIDATION |
637 | 626 | self.config.raw_http_proxy = http_proxy
|
638 | 627 |
|
639 | 628 | try:
|
@@ -2281,14 +2270,10 @@ def reset_user_agent(self):
|
2281 | 2270 | ua_platform = self.client_caps.platform.capitalize()
|
2282 | 2271 |
|
2283 | 2272 | # create ssl validation string based on settings
|
2284 |
| - validation_str = "validate" |
2285 |
| - if self.config.no_ssl_validation: |
2286 |
| - validation_str = "no-validate" |
2287 |
| - |
2288 | 2273 | self._user_agents = [
|
2289 |
| - "shotgun-json (%s)" % __version__, |
2290 |
| - "Python %s (%s)" % (self.client_caps.py_version, ua_platform), |
2291 |
| - "ssl %s (%s)" % (self.client_caps.ssl_version, validation_str), |
| 2274 | + f"shotgun-json ({__version__})", |
| 2275 | + f"Python {self.client_caps.py_version} ({ua_platform})", |
| 2276 | + f"ssl {self.client_caps.ssl_version}", |
2292 | 2277 | ]
|
2293 | 2278 |
|
2294 | 2279 | def set_session_uuid(self, session_uuid):
|
@@ -3560,8 +3545,14 @@ def _build_opener(self, handler):
|
3560 | 3545 | Build urllib2 opener with appropriate proxy handler.
|
3561 | 3546 | """
|
3562 | 3547 | handlers = []
|
3563 |
| - if self.__ca_certs and not NO_SSL_VALIDATION: |
3564 |
| - handlers.append(CACertsHTTPSHandler(self.__ca_certs)) |
| 3548 | + if self.__ca_certs: |
| 3549 | + handlers.append( |
| 3550 | + urllib.request.HTTPSHandler( |
| 3551 | + context=ssl.create_default_context( |
| 3552 | + cafile=self.__ca_certs, |
| 3553 | + ), |
| 3554 | + ), |
| 3555 | + ) |
3565 | 3556 |
|
3566 | 3557 | if self.config.proxy_handler:
|
3567 | 3558 | handlers.append(self.config.proxy_handler)
|
@@ -3630,23 +3621,6 @@ def _get_certs_file(cls, ca_certs):
|
3630 | 3621 | cert_file = os.path.join(cur_dir, "lib", "certifi", "cacert.pem")
|
3631 | 3622 | return cert_file
|
3632 | 3623 |
|
3633 |
| - def _turn_off_ssl_validation(self): |
3634 |
| - """ |
3635 |
| - Turn off SSL certificate validation. |
3636 |
| - """ |
3637 |
| - global NO_SSL_VALIDATION |
3638 |
| - self.config.no_ssl_validation = True |
3639 |
| - NO_SSL_VALIDATION = True |
3640 |
| - # reset ssl-validation in user-agents |
3641 |
| - self._user_agents = [ |
3642 |
| - ( |
3643 |
| - "ssl %s (no-validate)" % self.client_caps.ssl_version |
3644 |
| - if ua.startswith("ssl ") |
3645 |
| - else ua |
3646 |
| - ) |
3647 |
| - for ua in self._user_agents |
3648 |
| - ] |
3649 |
| - |
3650 | 3624 | # Deprecated methods from old wrapper
|
3651 | 3625 | def schema(self, entity_type):
|
3652 | 3626 | """
|
@@ -3849,59 +3823,6 @@ def _make_call(self, verb, path, body, headers):
|
3849 | 3823 | attempt += 1
|
3850 | 3824 | try:
|
3851 | 3825 | return self._http_request(verb, path, body, req_headers)
|
3852 |
| - except ssl.SSLEOFError as e: |
3853 |
| - # SG-34910 - EOF occurred in violation of protocol (_ssl.c:2426) |
3854 |
| - # This issue seems to be related to proxy and keep alive. |
3855 |
| - # It looks like, sometimes, the proxy drops the connection on |
3856 |
| - # the TCP/TLS level despites the keep-alive. So we need to close |
3857 |
| - # the connection and make a new attempt. |
3858 |
| - LOG.debug("SSLEOFError: {}".format(e)) |
3859 |
| - self._close_connection() |
3860 |
| - if attempt == max_rpc_attempts: |
3861 |
| - LOG.debug("Request failed. Giving up after %d attempts." % attempt) |
3862 |
| - raise |
3863 |
| - # This is the exact same block as the "except Exception" bellow. |
3864 |
| - # We need to do it here because the next except will match it |
3865 |
| - # otherwise and will not re-attempt. |
3866 |
| - # When we drop support of Python 2 and we will probably drop the |
3867 |
| - # next except, we might want to remove this except too. |
3868 |
| - except ssl_error_classes as e: |
3869 |
| - # Test whether the exception is due to the fact that this is an older version of |
3870 |
| - # Python that cannot validate certificates encrypted with SHA-2. If it is, then |
3871 |
| - # fall back on disabling the certificate validation and try again - unless the |
3872 |
| - # SHOTGUN_FORCE_CERTIFICATE_VALIDATION environment variable has been set by the |
3873 |
| - # user. In that case we simply raise the exception. Any other exceptions simply |
3874 |
| - # get raised as well. |
3875 |
| - # |
3876 |
| - # For more info see: |
3877 |
| - # https://www.shotgridsoftware.com/blog/important-ssl-certificate-renewal-and-sha-2/ |
3878 |
| - # |
3879 |
| - # SHA-2 errors look like this: |
3880 |
| - # [Errno 1] _ssl.c:480: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify: |
3881 |
| - # unknown message digest algorithm |
3882 |
| - # |
3883 |
| - # Any other exceptions simply get raised. |
3884 |
| - if ( |
3885 |
| - "unknown message digest algorithm" not in str(e) |
3886 |
| - or "SHOTGUN_FORCE_CERTIFICATE_VALIDATION" in os.environ |
3887 |
| - ): |
3888 |
| - raise |
3889 |
| - |
3890 |
| - if self.config.no_ssl_validation is False: |
3891 |
| - LOG.warning( |
3892 |
| - "SSL Error: this Python installation is incompatible with " |
3893 |
| - "certificates signed with SHA-2. Disabling certificate validation. " |
3894 |
| - "For more information, see https://www.shotgridsoftware.com/blog/" |
3895 |
| - "important-ssl-certificate-renewal-and-sha-2/" |
3896 |
| - ) |
3897 |
| - self._turn_off_ssl_validation() |
3898 |
| - # reload user agent to reflect that we have turned off ssl validation |
3899 |
| - req_headers["user-agent"] = "; ".join(self._user_agents) |
3900 |
| - |
3901 |
| - self._close_connection() |
3902 |
| - if attempt == max_rpc_attempts: |
3903 |
| - LOG.debug("Request failed. Giving up after %d attempts." % attempt) |
3904 |
| - raise |
3905 | 3826 | except Exception:
|
3906 | 3827 | self._close_connection()
|
3907 | 3828 | if attempt == max_rpc_attempts:
|
@@ -4160,14 +4081,12 @@ def _get_connection(self):
|
4160 | 4081 | timeout=self.config.timeout_secs,
|
4161 | 4082 | ca_certs=self.__ca_certs,
|
4162 | 4083 | proxy_info=pi,
|
4163 |
| - disable_ssl_certificate_validation=self.config.no_ssl_validation, |
4164 | 4084 | )
|
4165 | 4085 | else:
|
4166 | 4086 | self._connection = Http(
|
4167 | 4087 | timeout=self.config.timeout_secs,
|
4168 | 4088 | ca_certs=self.__ca_certs,
|
4169 | 4089 | proxy_info=None,
|
4170 |
| - disable_ssl_certificate_validation=self.config.no_ssl_validation, |
4171 | 4090 | )
|
4172 | 4091 |
|
4173 | 4092 | return self._connection
|
|
0 commit comments