-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-106687: _ssl: use uint64_t for SSL options #106700
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
Conversation
Hum, tests fail on Windows. I modified set_options() to use Example of failure:
|
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | | ||
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 | ||
); | ||
|
||
if (!PyArg_Parse(arg, "l", &new_opts)) | ||
if (!PyArg_Parse(arg, "O!", &PyLong_Type, &new_opts_obj)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try the "K"
conversion code for unsigned long long
similar to the old "l"
code, instead of "O!"
with a type. No overflow checking that way, but the previous code had no overflow checking either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A modern alternative would be to convert this to use argument clinic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring overflow sounds like a bad idea for a security module.
the weird things there are numerous... "C unsigned long" is not a type this PR should be dealing with. and that constant... /usr/include/openssl/ssl.h:# define SSL_OP_NO_SSLv2 0x0 |
so yeah I really don't understand how that error would be the direct fault of what I see in this PR. |
On the updated PR, the error is now:
|
About the surprising NO SSL2 error: test is like |
On Windows, this PR changes the value of SSLContext.options: it returns a big integer, instead of returning a negative number! I propose to use unsigned integers in Python 3.13, but solve the warning differently on older Python versions: without changing the value. test_options() fails because ssl.OP_ALL is a negative value instead of a positive value. We should either use signed integers everywhere, or unsigned integers everywhere, and it comes to "options" (and associated SSL constants). |
Ahha, no wonder. I believe Windows is a platform with I agree, use unsigned for the options (effectively bit field flags) on 3.13. If done before rc1 this feels reasonable to do for 3.12 as it may prevent some future headaches. |
SSL_CTX_get_options() uses uint64_t for options: https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html Fix this compiler warning on Windows with MSC: conversion from 'uint64_t' to 'long', possible loss of data
This PR can change ssl.OP_ALL value on Windows: it may be surprising to backport it to Python 3.11 which may need a different fix? |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
GH-106827 is a backport of this pull request to the 3.12 branch. |
SSL_CTX_get_options() uses uint64_t for options: https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html Fix this compiler warning on Windows with MSC: conversion from 'uint64_t' to 'long', possible loss of data (cherry picked from commit ad95c72) Co-authored-by: Victor Stinner <[email protected]>
What makes the problem worse is that the old OpenSSL API (ex: OpenSSL 1.0.2) uses signed long for options! See: https://www.openssl.org/docs/man1.0.2/man3/SSL_CTX_get_options.html Maybe it only became a problem in OpenSSL 3 which got more options which don't git into a 32-bit signed integer? Or at least, that some options see their value becoming negative as 32-bit signed integer? |
On a recent 3.11 GHA job, I see that the Windows x64 job uses OpenSSL 1.1.1u 30 May 2023 and has a negative value for ssl.OP_ALL: https://github.com/python/cpython/actions/runs/5559894464/jobs/10156437844
But there is no compiler warnings:
OpenSSL versions depending on the Python branch:
I'm not sure if my change works on OpenSSL 1.1 and 3.0: I didn't check if it does emit compiler warnings with OpenSSL 1.1 (which uses long for options, not uint64_t). |
Python 3.11 doesn't seem to emit a compiler warning. So I prefer to leave it unchanged for now, but only change the code if it starts to emit a warning: see #99079 which suggests upgrading OpenSSL from 1.1 to 3.0. |
…6827) gh-106687: _ssl: use uint64_t for SSL options (GH-106700) SSL_CTX_get_options() uses uint64_t for options: https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html Fix this compiler warning on Windows with MSC: conversion from 'uint64_t' to 'long', possible loss of data (cherry picked from commit ad95c72) Co-authored-by: Victor Stinner <[email protected]>
GH-116665 is a backport of this pull request to the 3.11 branch. |
gh-106687: _ssl: use uint64_t for SSL options (#106700) SSL_CTX_get_options() uses uint64_t for options: https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html Fix this compiler warning on Windows with MSC: conversion from 'uint64_t' to 'long', possible loss of data (cherry picked from commit ad95c72)
SSL_CTX_get_options() uses uint64_t for options:
https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html
Fix this compiler warning on Windows with MSC:
ssl.c
: conversion from 'uint64_t' to 'long', possible loss of data #106687