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

adding param of options to config of ssl_context #1692

Closed
wants to merge 6 commits into from

Conversation

aswanidutt87
Copy link

@aswanidutt87 aswanidutt87 commented Oct 4, 2022

This is related to issue #806 , we are required to resolve a vulnerability of DoS by adding the option of ssl.OP_NO_RENEGOTIATION to the ssl_context.
Currently there is no provision of adding any options to the config of ssl_context.
we have added the options list of ssl.Options type to the main.py and there by to the config.py.
Added unit tests - coverage - total as of this change - 97.69%, report attached, checks, lint ran fine.

@aswanidutt87
Copy link
Author

aswanidutt87 commented Oct 4, 2022

@aswanidutt87 aswanidutt87 mentioned this pull request Oct 4, 2022
2 tasks
@euri10
Copy link
Member

euri10 commented Oct 5, 2022

This is related to issue #806 , we are required to resolve a vulnerability of DoS by adding the option of ssl.OP_NO_RENEGOTIATION to the ssl_context. Currently there is no provision of adding any options to the config of ssl_context. we have added the options list of ssl.Options type to the main.py and there by to the config.py. Added unit tests - coverage - total as of this change - 97.69%, report attached, checks, lint ran fine.

what vulnerability

@Kludex
Copy link
Member

Kludex commented Oct 5, 2022

This is related to issue #806 , we are required to resolve a vulnerability of DoS by adding the option of ssl.OP_NO_RENEGOTIATION to the ssl_context. Currently there is no provision of adding any options to the config of ssl_context. we have added the options list of ssl.Options type to the main.py and there by to the config.py. Added unit tests - coverage - total as of this change - 97.69%, report attached, checks, lint ran fine.

what vulnerability

Check your mailbox. 🙏

I've forwarded your email @aswanidutt87 , jfyk.

Comment on lines +321 to +323
if config.ssl_options is not None:
assert ssl.OP_NO_RENEGOTIATION in config.ssl_options
assert ssl.OP_NO_TLSv1_2 in config.ssl_options
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if config.ssl_options is not None:
assert ssl.OP_NO_RENEGOTIATION in config.ssl_options
assert ssl.OP_NO_TLSv1_2 in config.ssl_options
assert ssl.OP_NO_RENEGOTIATION in config.ssl_options
assert ssl.OP_NO_TLSv1_2 in config.ssl_options

Copy link
Author

Choose a reason for hiding this comment

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

if I dont check for None on the Optional[ssl.Options], getting mypy errors like "unsupported right operand type for in optional" as by default they are Optional list of ssl.Options type

Comment on lines 327 to 331
config = Config(
app=asgi_app,
)
config.load()
assert not config.ssl_options
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we check the config.ssl created instead?

Suggested change
config = Config(
app=asgi_app,
)
config.load()
assert not config.ssl_options
config = Config(app=asgi_app)
config.load()
assert not config.ssl_options

Copy link
Author

Choose a reason for hiding this comment

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

agreed, removing this test as checking for config.ssl is True assertion test is already there- coverage is good.

Comment on lines 451 to 453
if self.ssl_options:
for each_option in self.ssl_options:
self.ssl.options |= each_option
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be inside the create_ssl_context function.

Copy link
Author

Choose a reason for hiding this comment

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

agreed moved to create_ssl_context.

Copy link

Choose a reason for hiding this comment

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

This is slightly out of date now in terms of some of the API calls, but I think it solves a similar issue: https://github.com/OpenCTI-Platform/client-python/blob/14cbac14afe76b3003baa5fff56c72af9eb17935/pycti/connector/opencti_connector_helper.py#L77

uvicorn/main.py Outdated
"--ssl-options",
type=list,
default=None,
help="Options to set on ssl context",
Copy link
Member

Choose a reason for hiding this comment

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

Those are integers, right? Can we point out the options available here as well?

Suggested change
help="Options to set on ssl context",
help="Options to set on ssl context.",

Copy link
Author

Choose a reason for hiding this comment

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

added the file and Enum class to look for

@aswanidutt87 aswanidutt87 requested a review from Kludex October 5, 2022 14:45
@aswanidutt87
Copy link
Author

@Kludex , please have a look at the changes made per your review comments, we need this change to resolve a Vulnerability

@Kludex Kludex requested a review from tomchristie October 19, 2022 15:13
@Kludex
Copy link
Member

Kludex commented Oct 19, 2022

I'll take time to review this. I need to study our options, because I know there's an issue open to add the SSL context via uvicorn.run.

we need this change to resolve a Vulnerability

I think it was explained on Gitter why this is not a vulnerability on our side, but it was also agreed this PR makes sense.

@Kludex
Copy link
Member

Kludex commented Oct 28, 2022

@aswanidutt87 What do you think about doing what #806 suggests instead? i.e. passing the SSL context via uvicorn programmatically.

@aswanidutt87
Copy link
Author

aswanidutt87 commented Oct 28, 2022

@aswanidutt87 What do you think about doing what #806 suggests instead? i.e. passing the SSL context via uvicorn programmatically.

@Kludex there is no option of adding ssl context to uvicorn as of now, both passing SSL context or SSL options works here, I would leave it to you which one you prefer to include. if we go with the route of adding SSL context then the usage of uvicorn should be as follows
uvicorn.run(
"web:app",
host="0.0.0.0",
port=int(port),
reload=True,
ssl_context=SSL_Context
)
if we go with adding just the ssl_options, run looks like this. and this is what we are doing currently in our case as interim fix.
uvicorn.run(
"web:app",
host="0.0.0.0",
port=int(port),
reload=True,
ssl_keyfile=tls_key,
ssl_certfile=tls_cert,
ssl_version=int(ssl.PROTOCOL_TLS),
ssl_ciphers=allowed_ciphers,
ssl_options=list_options
)

just to make it to work for every scenario in future adding a ssl_context looks more useful to be honest. we can use config.py to create our own ssl_context and we can pass it into uvicorn.run

@Kludex
Copy link
Member

Kludex commented Oct 29, 2022

PR welcome for what #806 suggests. 🙏

I'll be closing this, as the future solution that solves #806 will support this case as well.

@Kludex Kludex closed this Oct 29, 2022
@aswanidutt87
Copy link
Author

@Kludex, As we have tried the route with your suggestion couldnt get the custom ssl_context to pass into the server, we want to request you to kindly consider this adding of options to existing context.
another reason to support this is that we have already added everything that we can to context already with previous PRs, its just that the options are missing, if we can add this options to the default context getting created we should be all set.

@Kludex
Copy link
Member

Kludex commented Dec 20, 2022

@Kludex, As we have tried the route with your suggestion couldnt get the custom ssl_context to pass into the server, we want to request you to kindly consider this adding of options to existing context.

That's not how I see it. I've replied to your last message here, and you didn't reply.

Please, do not send me emails regarding issues or PRs. I read all comments on this repository.

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.

5 participants