Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded tlsv1 version in ssl.wrap_socket #223

Merged
merged 1 commit into from
Oct 20, 2018

Conversation

duczen
Copy link

@duczen duczen commented Oct 12, 2018

Removed the hard coded TLSv1 version in ssl.wrap_socket.

TLS options for a reader can be set with tls_options, however the ssl_version is already explicitly set which yields the following error when trying to set a different version:

TypeError: wrap_socket() got multiple values for keyword argument 'ssl_version'

This prevents me from using pynsq with -tls-min-version=tls1.2 set on my nsqds. Removing the hard coded version allows setting this value as/if needed. Running without the hardcoded value, nsq.Reader with tls_v1=True and omitting tls_options correctly uses the min tls version set by nsqd.

@ploxiln
Copy link
Member

ploxiln commented Oct 12, 2018

Hmm - yeah, TLSv1 is not great, it does not allow TLSv1.1 or TLSv1.2. The default ("SSLv23" in python2.7 and "TLS" in python3.5) theoretically allows SSLv3 or any version of TLS. I suppose we wanted to explicitly disallow SSLv3. But today the only thing that makes sense besides the default would be TLSv1.2.

I'm fine with the default. Alternatively, we may want to just add PROTOCOL_TLSv1_2 to opts just if ssl_version is not already present there. cc @mreiferson @jehiah

@mreiferson
Copy link
Member

I'm fine with the default. Alternatively, we may want to just add PROTOCOL_TLSv1_2 to opts just if ssl_version is not already present there.

This sounds reasonable, care to make this change @duczen?

Thanks for the PR!

@mreiferson mreiferson added the bug label Oct 16, 2018
nsq/conn.py Outdated
self.io_loop.remove_handler(self.socket.fileno())

opts = {
'cert_reqs': ssl.CERT_REQUIRED,
'ca_certs': default_ca_certs()
}
opts.update(options or {})
self.socket = ssl.wrap_socket(self.socket, ssl_version=ssl.PROTOCOL_TLSv1,
if not opts.get('ssl_version'):
opts['ssl_version'] = ssl.PROTOCOL_TLSv1_2
Copy link
Member

Choose a reason for hiding this comment

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

there's a slightly more elegant way to do this - if you include ssl_version in the opts dict initially (just above, next to ca_certs), then opts.update(options) can override it

(sorry for not seeing this earlier)

Copy link
Author

Choose a reason for hiding this comment

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

Ah, yes. I like that much better. I'll have that up in a sec.

@ploxiln
Copy link
Member

ploxiln commented Oct 16, 2018

Nice, thanks.

One last thing - can you squash your commits into one? (We prefer the commits to be manually squashed, and then we use the "Create a merge commit" option to record who merged.)

@duczen duczen force-pushed the remove-tls-hardcode branch from 206ad0c to 8cf3de1 Compare October 16, 2018 17:44
@ploxiln ploxiln merged commit 1afef71 into nsqio:master Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants