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

Switch to use ssl.SSLContext in sync worker #2012

Closed
wants to merge 1 commit into from

Conversation

berkerpeksag
Copy link
Collaborator

Closes #1140

Copy link
Collaborator

@tilgovi tilgovi left a comment

Choose a reason for hiding this comment

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

Thanks for starting on this!

context.set_default_verify_paths()
ciphers = self.cfg.ssl_options['ciphers']
# set_ciphers() will raise an exception if we pass None (default value)
if ciphers is not None and isinstance(ciphers, str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

if isinstance(ciphers, str): should work, right?

>>> isinstance(None, str)
False

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point!

client = ssl.wrap_socket(client, server_side=True,
**self.cfg.ssl_options)
# TODO: Make this reusable by gthread worker. Move to BaseWorker?
context = ssl.SSLContext(self.cfg.ssl_options['ssl_version'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we can build this context once when we parse the config and store it on self.cfg.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, building and storing it on self.cfg is definitely better than this :) We can move this snippet to util.create_ssl_context()and call it there.

I'm also planning to separate Settings and validate_* functions in gunicorn/config.py.

@benoitc
Copy link
Owner

benoitc commented Apr 24, 2019

@berkerpeksag do you need any help or it? Let me know.

@benoitc
Copy link
Owner

benoitc commented Apr 29, 2019

bump

@berkerpeksag
Copy link
Collaborator Author

I will work on this tonight.

@benoitc
Copy link
Owner

benoitc commented May 3, 2019

@berkerpeksag bump again :) what's missing there? Anything I can help?

I think we need to make a release today. I willl take care of the 19. release right after.

Let me know

@berkerpeksag
Copy link
Collaborator Author

This is not ready yet and I probably won't have time to finish it until next weekend.

@benoitc
Copy link
Owner

benoitc commented May 6, 2019

ok I would then suggest to make a release of 20.0 today and release 20.1 when your code is out next week. What do you and others think about it?

as a side note i don't think we shouldn't takes that release number too much seriously until we keep the semantic versioning. Nothing stop us to make a release at any time IMO.

@benoitc
Copy link
Owner

benoitc commented Jun 17, 2019

@berkerpeksag �since i'm late in this release I wanted to finish this improvements before releasing it as it would be more than welcome. I can help on it. Others than @tilgovi comments, do you have others stuffs in mind you wanted to do on this. patch?

@benoitc
Copy link
Owner

benoitc commented Sep 5, 2019

bump @berkerpeksag , please let me know if you can do this , would be good to have this change so we can make a new stable release.

@berkerpeksag
Copy link
Collaborator Author

Apologies for my late response. The good thing is that I've been working with X.509 certificates at work lately and I think I have a much better understanding of the ssl module now. I'll try finish this up before the end of the month.

@johnthagen johnthagen mentioned this pull request Sep 7, 2019
@benoitc
Copy link
Owner

benoitc commented Sep 27, 2019

@berkerpeksag I propos to assign this to next release 20.1 to not wait more to release the 20.0. 20.1 can happen any time for me, even if it's mean 1 day after the 20.0 is out :)

Is this OK for you?

@benoitc
Copy link
Owner

benoitc commented Nov 22, 2019

bump.

@benoitc benoitc added this to the 20.1 milestone Nov 22, 2019
@berkerpeksag berkerpeksag marked this pull request as ready for review January 27, 2020 05:55
@berkerpeksag
Copy link
Collaborator Author

I'm testing my branch with a self-signed certificate at the moment. I will try to push my updated branch today or tomorrow.

print(exc)
raise exc
# TODO: OP_CIPHER_SERVER_PREFERENCE is set by default since Python 3.6+.
context.options |= ssl.OP_CIPHER_SERVER_PREFERENCE
Copy link

Choose a reason for hiding this comment

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

Any chance this can be exposed as a global configuration option? It would be very nice, particularly if you want to exclude specific protocol versions.
e.g.

ssl_options = ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | ssl.OP_NO_TLSv1_2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's definitely possible!

BTW, I think SSLContext in Python 3.6+ sets all of those options by default.

@benoitc
Copy link
Owner

benoitc commented Jan 5, 2021

@berkerpeksag i assume you're quite busy ... Can you let me know what still need to be done there to close the issue? I or maybe someone else can help :)

@berkerpeksag
Copy link
Collaborator Author

Yes, unfortunately I may not be able to get to this in near future. There is a chance that I can finish it next month when I'm on vacation, but I've already broken too much promises :) What's missing:

  • Address Randall's review comments
  • Deal with TODO comments
  • Test against a recent Python and OpenSSL version locally
  • Document changes

@benoitc benoitc removed this from the 20.1 milestone Jan 7, 2021
@tsaarni
Copy link
Contributor

tsaarni commented Sep 11, 2021

@berkerpeksag I have submitted another PR #2649 which proposes similar SSLContext update as your PR. I hope you do not mind!

@benoitc
Copy link
Owner

benoitc commented May 11, 2023

superseded by #2649 which have been merged. Thanks for the PR anyway.

@benoitc benoitc closed this May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to use SSLContext
5 participants