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

bpo-33062: Add SSL renegotiation and key update #8620

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fantix
Copy link
Contributor

@fantix fantix commented Aug 2, 2018

@1st1 This PR is for testing new asyncio/sslproto.py.

TODOs:

  • News
  • Test renegotiation
  • Test key update
  • Test errors

https://bugs.python.org/issue33062

Lib/ssl.py Outdated
class SSLObject:
class _KeyUpdateMixin:
if HAS_TLSv1_3:
def key_update(self, updatetype):
Copy link
Member

Choose a reason for hiding this comment

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

Do we want an else branch with these methods raising a NotImplementedError?

Modules/_ssl.c Outdated
@@ -1050,6 +1050,107 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self)
return NULL;
}

#if defined(TLS1_3_VERSION) && !defined(OPENSSL_NO_TLS1_3)
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to provide alternative implementations of these functions raising NotImplementedError for the #else branch (otherwise this might not compile at all).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense, will do.

Copy link
Member

Choose a reason for hiding this comment

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

Actually the #if should be inside the function, otherwise argument clinic will have hard time figuring out what you are doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it'll be safer that way, will do (currently it seems clinic is clever enough to copy the ifdef to .h file, and make it an empty METHODDEF macro if false, so that the same ifdef won't be necessary when using the METHODDEF).

Copy link
Member

@1st1 1st1 Aug 3, 2018

Choose a reason for hiding this comment

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

currently it seems clinic is clever enough to copy the ifdef to .h file, and make it an empty METHODDEF macro if false, so that the same ifdef won't be necessary when using the METHODDEF

That's cool, I didn't know it's that smart :) Then feel free to keep your code as is.

Modules/_ssl.c Outdated
_PySSL_UPDATE_ERRNO_IF(ret == 0, self, ret);
PySSL_END_ALLOW_THREADS

if (PyErr_CheckSignals())
Copy link
Member

Choose a reason for hiding this comment

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

Use { even for single statement ifs (as per updated PEP 7)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK! Thanks for the comments.

@1st1 1st1 self-assigned this Aug 2, 2018
@1st1 1st1 requested a review from tiran August 2, 2018 17:47
@1st1
Copy link
Member

1st1 commented Aug 2, 2018

@tiran Christian, this is a WIP, but would be great to get a green light from you in general.

@tiran
Copy link
Member

tiran commented Aug 9, 2018

Hi @fantix

thanks for your patch! It's a promising start. I'm currently travelling and will look into your PR next week.

@fantix
Copy link
Contributor Author

fantix commented Aug 9, 2018

Thanks @tiran Christian! In the meanwhile I'll get the remaining TODOs done.

@fantix fantix force-pushed the bpo-33062/ssl-renegotiation branch from bbf733e to 45a906a Compare August 13, 2018 10:51
@fantix fantix changed the title bpo-33062: Add SSL renegotiation and key update (WIP) bpo-33062: Add SSL renegotiation and key update Aug 13, 2018
@1st1
Copy link
Member

1st1 commented Oct 1, 2018

@tiran a gentle friendly ping :)

@fantix
Copy link
Contributor Author

fantix commented Oct 1, 2018

Thanks! I’m working on a rebase and update here, shall commit in 18 hours.

@fantix fantix force-pushed the bpo-33062/ssl-renegotiation branch from 45a906a to 1f6d47b Compare October 2, 2018 10:31
@tiran
Copy link
Member

tiran commented Oct 2, 2018

I'm not a fan of mixin classes... The functions don't do much work, so it should be easy to move the common code to C.

@fantix
Copy link
Contributor Author

fantix commented Oct 3, 2018

Ah yes, that looks a bit duplicate, will fix, thanks!

@fantix fantix force-pushed the bpo-33062/ssl-renegotiation branch from 1f6d47b to 6bc07a9 Compare October 12, 2018 07:21
@fantix fantix force-pushed the bpo-33062/ssl-renegotiation branch from 6bc07a9 to a953365 Compare October 13, 2018 03:13
@fantix
Copy link
Contributor Author

fantix commented Oct 19, 2018

@tiran any other comments please?

Raises NotImplementedError if the TLS implementation doesn't support
TLS 1.3.)

:param updatetype: KeyUpdateTypes
Copy link
Contributor

Choose a reason for hiding this comment

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

In Python we don't use sphinx markup in docstrings, documentation is not authogenerated but written manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for this one! I'll update docs too.

Copy link
Member

Choose a reason for hiding this comment

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

This approach looks strange and uncommon to me. I opened #9972, which I believe is a better approach to handle common doc strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is! I'll rebase up to #9972 once it is merged. Thanks!

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

Please document the new methods and constants in the module documentation. The doc strings are less relevant and should be shorter. You can also inlcude a whatsnew

Raises NotImplementedError if the TLS implementation doesn't support
TLS 1.3.)

:param updatetype: KeyUpdateTypes
Copy link
Member

Choose a reason for hiding this comment

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

This approach looks strange and uncommon to me. I opened #9972, which I believe is a better approach to handle common doc strings.

@@ -780,6 +785,23 @@ def version(self):
def verify_client_post_handshake(self):
return self._sslobj.verify_client_post_handshake()

def key_update(self, updatetype):
Copy link
Member

Choose a reason for hiding this comment

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

With TLS 1.3, you can also force an immediate rekey. From the documentation, https://www.openssl.org/docs/man1.1.1/man3/SSL_key_update.html

Alternatively SSL_do_handshake() can be called to force the update to take place immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I also found that during writing docs,

Alternatively do_handshake() can be called to force the update to take place immediately.

Do you think it a better approach to wrap OpenSSL API into high level API like this:

    def key_update(self, updatetype, *, deferred=False):
        self._sslobj.key_update(updatetype)
        if not deferred:
            self._sslobj.do_handshake()

Or stay with OpenSSL-style API and document the details? Now I prefer the high-level one, leaving the low-level API with the _ssl module.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella
Copy link
Contributor

@fantix, please resolve the merge conflict. Thanks!

@fantix
Copy link
Contributor Author

fantix commented May 31, 2019

@csabella oh right, yes will do!

@csabella
Copy link
Contributor

@fantix, please resolve the merge conflict. Thanks!

@jdevries3133
Copy link
Contributor

jdevries3133 commented Jul 23, 2021

@csabella @fantix I went ahead and resolved the merge conflicts. The conflicts were only in auto-generated files, so I just regenerated them and also fixed one test that had broken in the interim since these changes were made. You can see the diff here, although I didn't open a new PR; I'm not sure whether I should, or what I should do next, for that matter:

main...jdevries3133:[bpo-33063](https://bugs.python.org/issue33063)-ssl-renegotiation

I did have a few notes about how I fixed a broken test, including a question:

In one of the new tests, there was a check that the OpenSSL version is 1.1.
I believe that python must be built againt OpenSSL 1.1 now, right? I removed
the check because it was using a variable which is now undefined. Presumably
it was exported from SSL when the test was originally written.

In any case, if we do need to check the version, I can just use
ssl.OPENSSL_VERSION_INFO, but if I understand correctly, the check is not
necessary. If that's not right, just let me know!

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.

None yet

9 participants