Skip to content

replace ssl.wrap_socket with context.wrap_socket - #23

Open
joga84 wants to merge 1 commit into
cloudregistry:masterfrom
joga84:master
Open

replace ssl.wrap_socket with context.wrap_socket#23
joga84 wants to merge 1 commit into
cloudregistry:masterfrom
joga84:master

Conversation

@joga84

@joga84 joga84 commented Jun 17, 2026

Copy link
Copy Markdown

python 3.12 and later no longer have ssl.wrap_socket, create ssl.create_default_context and use context.wrap_socket instead.

python 3.12 and later no longer have ssl.wrap_socket, create ssl.create_default_context and use context.wrap_socket instead.

@wil wil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joga84, some comments for you to consider.

Comment thread eppy/client.py
Comment on lines +80 to +81
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.load_verify_locations will raise a TypeError if self.cacerts is None.
Also, we should still set ciphers if requested:

Suggested change
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)
context = ssl.create_default_context(cafile=self.cacerts)
if self.ssl_ciphers:
context.set_ciphers(self.ssl_ciphers)

Comment thread eppy/client.py
ca_certs=self.cacerts)
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)
context.load_cert_chain(self.certfile, self.keyfile)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.load_cert_chain will raise a TypeError if self.certfile is None. Add guard:

Suggested change
context.load_cert_chain(self.certfile, self.keyfile)
if self.certfile or self.keyfile:
context.load_cert_chain(self.certfile, self.keyfile)

Comment thread eppy/client.py
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)
context.load_cert_chain(self.certfile, self.keyfile)
context.check_hostname = self.validate_hostname

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting check_hostname here and calling wrap_socket with server_hostname=host is great! It does mean that the if_validate_hostname block that calls match_hostname is redundant (and is probably unreachable if validation fails.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants