Cleanup SSL deprecation warnings under Python 3.10 and newer #706
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit python would produce these warnings when using kazoo with ssl:
The reason for this is that
ssl.PROTOCOL_SSLv23
is an alias forssl.PROTOCOL_TLS
andssl.PROTOCOL_TLS
is deprecated since Python 3.10.ssl.PROTOCOL_TLS
was replaced withssl.PROTOCOL_TLS_CLIENT
andssl.PROTOCOL_TLS_SERVER
. In kazoo's case we switch tossl.PROTOCOL_TLS_CLIENT
as kazoo is acting as an ssl client to zookeeper servers.There are a few things to note.
PROTOCOL_TLS_CLIENT
enablescontext.check_hostname
. We explicitly set this to False as this is required to setssl.CHECK_NONE
which kazoo supports, and not everyone may be using SSL certs with proper hostnames configured. For example if making connections to an IP address rather than a name and the certs don't have IP addrs in their altnames. This ensures backward compatibility with these use cases. Changing this should be done in a separate change and should likely be made configurable like verify_certs.Finally, while we are at it we replace
ssl.CERT_OPTIONAL
withssl.CERT_REQUIRED
as they are equivalent in a client context. This allows us to delete some code.Python documents all of these behaviors as being present since Python 3.6. Kazoo requires Python 3.7 or newer which should make this safe.
Why is this needed?
This change should avoid problems with future Python updates. It also cuts down on noise in things like test suites that use kazoo under python3.10 or newer which is nice for end users.
Proposed Changes
ssl.PROTOCOL_TLS_CLIENT
instead ofssl.PROTOCOL_SSLv23
ssl.CERT_OPTIONAL
withssl.CERT_REQUIRED
as they are equivalent in this context. Doing so allows us to delete some codeDoes this PR introduce any breaking change?
I've intentionally tried to make this backward compatible by setting context.check_hostname to False preserving old behavior. I think any changes to this behavior should happen in a separate change that can more fully understand the impacts.