Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add an ssl.OP_ENABLE_KTLS option for enabling the use of the kernel TLS #96828

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

Closed
illia-v opened this issue Sep 14, 2022 · 0 comments · Fixed by #96830
Closed

Add an ssl.OP_ENABLE_KTLS option for enabling the use of the kernel TLS #96828

illia-v opened this issue Sep 14, 2022 · 0 comments · Fixed by #96830
Labels
topic-SSL type-feature A feature request or enhancement

Comments

@illia-v
Copy link
Contributor

illia-v commented Sep 14, 2022

Feature or enhancement

A new ssl.OP_ENABLE_KTLS option for enabling the use of the kernel TLS.

Pitch

Kernel Transport Layer Security (kTLS) can improve performance of programs using TLS by reducing the number of switches between the user space and the kernel space. kTLS allows using the sendfile system call for sending data using TLS. Also, it may offload TLS to network interface controllers.

kTLS is not enabled by default for various reasons which you can find in openssl/openssl#13794. Even if a system supports the feature and OpenSSL was compiled with support for it, Python still has to set an OpenSSL's option SSL_OP_ENABLE_KTLS to use it.

In theory, it is possible to enable the kernel TLS in any Python compiled against OpenSSL 3 using this following code. If all other requirements are met, Python should start writing to and reading from a secure socket using the kernel TLS.

import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.options |= 8  # SSL_OP_ENABLE_KTLS

Since Python's ssl module defines a few constants similar to SSL_OP_ENABLE_KTLS, it should provide an ssl.OP_ENABLE_KTLS option.

Previous discussion

I created https://discuss.python.org/t/sslsocket-sendfile-and-kernel-tls/18886 previously to discuss benefiting from the OpenSSL's SSL_sendfile function. An option for enabling kTLS is a base for the work.

@illia-v illia-v added the type-feature A feature request or enhancement label Sep 14, 2022
illia-v added a commit to illia-v/cpython that referenced this issue Sep 14, 2022
gpshead pushed a commit that referenced this issue Nov 24, 2022
Expose the constant when OpenSSL defines it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-SSL type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants