-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30008: OpenSSL 1.1 compatibility without using deprecated API #3943
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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5aed182
bpo-30008: OpenSSL 1.1 compatibility without using deprecated API
markwright 4809f4c
Replace OpenSSL 1.1.0 deprecated RAND_pseudo_bytes with _PyOS_URandom
markwright 82d3a39
Revert calling OPENSSL_init_ssl(), tiran advises: No need
markwright 8b5d5c2
Add a news file with blurb for removing OpenSSL 1.1 deprecated API
markwright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2017-11-05-17-06-44.bpo-30008.kUgT8v.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OpenSSL 1.1 compatility: Remove use of deprecated API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ static PySocketModule_APIObject PySocketModule; | |
#include "openssl/err.h" | ||
#include "openssl/rand.h" | ||
#include "openssl/bio.h" | ||
#include "openssl/dh.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is dh.h required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fix thie compiler error that occurs building Python 3.7.0a2 with openssl 1.1.0g built with disable-deprecated:
|
||
|
||
/* SSL error object */ | ||
static PyObject *PySSLErrorObject; | ||
|
@@ -162,9 +163,17 @@ static void _PySSLFixErrno(void) { | |
#else /* OpenSSL < 1.1.0 */ | ||
#define HAVE_OPENSSL_CRYPTO_LOCK | ||
|
||
#ifndef OPENSSL_VERSION_1_1 | ||
#define TLS_method SSLv23_method | ||
#define TLS_client_method SSLv23_client_method | ||
#define TLS_server_method SSLv23_server_method | ||
#define X509_get0_notBefore X509_get_notBefore | ||
#define X509_get0_notAfter X509_get_notAfter | ||
#define ASN1_STRING_get0_data ASN1_STRING_data | ||
#define OpenSSL_version_num SSLeay | ||
#define OpenSSL_version SSLeay_version | ||
#define OPENSSL_VERSION SSLEAY_VERSION | ||
#endif | ||
|
||
static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) | ||
{ | ||
|
@@ -1123,7 +1132,7 @@ _get_peer_alt_names (X509 *certificate) { | |
goto fail; | ||
} | ||
PyTuple_SET_ITEM(t, 0, v); | ||
v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as), | ||
v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_get0_data(as), | ||
ASN1_STRING_length(as)); | ||
if (v == NULL) { | ||
Py_DECREF(t); | ||
|
@@ -1426,7 +1435,7 @@ _decode_certificate(X509 *certificate) { | |
Py_DECREF(sn_obj); | ||
|
||
(void) BIO_reset(biobuf); | ||
notBefore = X509_get_notBefore(certificate); | ||
notBefore = X509_get0_notBefore(certificate); | ||
ASN1_TIME_print(biobuf, notBefore); | ||
len = BIO_gets(biobuf, buf, sizeof(buf)-1); | ||
if (len < 0) { | ||
|
@@ -1443,7 +1452,7 @@ _decode_certificate(X509 *certificate) { | |
Py_DECREF(pnotBefore); | ||
|
||
(void) BIO_reset(biobuf); | ||
notAfter = X509_get_notAfter(certificate); | ||
notAfter = X509_get0_notAfter(certificate); | ||
ASN1_TIME_print(biobuf, notAfter); | ||
len = BIO_gets(biobuf, buf, sizeof(buf)-1); | ||
if (len < 0) { | ||
|
@@ -2822,7 +2831,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version) | |
conservative and assume it wasn't fixed until release. We do this check | ||
at runtime to avoid problems from the dynamic linker. | ||
See #25672 for more on this. */ | ||
libver = SSLeay(); | ||
libver = OpenSSL_version_num(); | ||
if (!(libver >= 0x10001000UL && libver < 0x1000108fUL) && | ||
!(libver >= 0x10000000UL && libver < 0x100000dfUL)) { | ||
SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS); | ||
|
@@ -4625,7 +4634,11 @@ PySSL_RAND(int len, int pseudo) | |
if (bytes == NULL) | ||
return NULL; | ||
if (pseudo) { | ||
#ifdef OPENSSL_VERSION_1_1 | ||
ok = (_PyOS_URandom((unsigned char*)PyBytes_AS_STRING(bytes), len) == 0 ? 1 : 0); | ||
#else | ||
ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); | ||
#endif | ||
if (ok == 0 || ok == 1) | ||
return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False); | ||
} | ||
|
@@ -5573,10 +5586,10 @@ PyInit__ssl(void) | |
return NULL; | ||
|
||
/* OpenSSL version */ | ||
/* SSLeay() gives us the version of the library linked against, | ||
/* OpenSSL_version_num() gives us the version of the library linked against, | ||
which could be different from the headers version. | ||
*/ | ||
libver = SSLeay(); | ||
libver = OpenSSL_version_num(); | ||
r = PyLong_FromUnsignedLong(libver); | ||
if (r == NULL) | ||
return NULL; | ||
|
@@ -5586,7 +5599,7 @@ PyInit__ssl(void) | |
r = Py_BuildValue("IIIII", major, minor, fix, patch, status); | ||
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) | ||
return NULL; | ||
r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION)); | ||
r = PyUnicode_FromString(OpenSSL_version(OPENSSL_VERSION)); | ||
if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) | ||
return NULL; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Good catch, but this is an unrelated fix and should be tracked in a separate issue.
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.
Thanks, however it was the compiler that told me I needed to make this change
to correct this compiler error that occurs building Python 3.7.0a2 with openssl
1.1.0g built with disable-deprecated: