Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:mcepl:branches:devel:languages:python:Factory
python36
openssl-300-load_verify_locations-err-msg.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File openssl-300-load_verify_locations-err-msg.patch of Package python36
From 4fa04ed70b67e64cc405b5dbae54f081e8af4ea9 Mon Sep 17 00:00:00 2001 From: Christian Heimes <christian@python.org> Date: Fri, 23 Apr 2021 13:51:40 +0200 Subject: [PATCH] OpenSSL 3.0.0: Make load_verify_locations(cadata) error message consistent ssl.SSLContext.load_verify_locations now returns a consistent error message when cadata contains no valid certificate. (cherry picked from commit gh#python/cpython@be6a5a3494dc) Fixes: bpo#43920 From-PR: gh#python/cpython!25554 Patch: openssl-300-load_verify_locations-err-msg.patch Released-in: 3.8.10 Signed-off-by: Christian Heimes <christian@python.org> --- Lib/test/test_ssl.py | 11 ++++++--- .../2021-04-23-11-54-38.bpo-43920.cJMQ2D.rst | 2 ++ Modules/_ssl.c | 23 +++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-04-23-11-54-38.bpo-43920.cJMQ2D.rst diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 0d8e14e9a2b..b9f27afc272 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -1186,12 +1186,17 @@ class ContextTests(unittest.TestCase): ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) self.assertRaises(TypeError, ctx.load_verify_locations, cadata=object) - with self.assertRaisesRegex(ssl.SSLError, "no start line"): + with self.assertRaisesRegex( + ssl.SSLError, + "no start line: cadata does not contain a certificate" + ): ctx.load_verify_locations(cadata="broken") - with self.assertRaisesRegex(ssl.SSLError, "not enough data"): + with self.assertRaisesRegex( + ssl.SSLError, + "not enough data: cadata does not contain a certificate" + ): ctx.load_verify_locations(cadata=b"broken") - def test_load_dh_params(self): ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) ctx.load_dh_params(DHFILE) diff --git a/Misc/NEWS.d/next/Library/2021-04-23-11-54-38.bpo-43920.cJMQ2D.rst b/Misc/NEWS.d/next/Library/2021-04-23-11-54-38.bpo-43920.cJMQ2D.rst new file mode 100644 index 00000000000..28ff0fb3afa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-04-23-11-54-38.bpo-43920.cJMQ2D.rst @@ -0,0 +1,2 @@ +OpenSSL 3.0.0: :meth:`~ssl.SSLContext.load_verify_locations` now returns a +consistent error message when cadata contains no valid certificate. diff --git a/Modules/_ssl.c b/Modules/_ssl.c index ab8f00ee544..36d0706e8f0 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -3579,7 +3579,7 @@ _add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len, { BIO *biobuf = NULL; X509_STORE *store; - int retval = 0, err, loaded = 0; + int retval = -1, err, loaded = 0; assert(filetype == SSL_FILETYPE_ASN1 || filetype == SSL_FILETYPE_PEM); @@ -3633,23 +3633,32 @@ _add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len, } err = ERR_peek_last_error(); - if ((filetype == SSL_FILETYPE_ASN1) && - (loaded > 0) && - (ERR_GET_LIB(err) == ERR_LIB_ASN1) && - (ERR_GET_REASON(err) == ASN1_R_HEADER_TOO_LONG)) { + if (loaded == 0) { + const char *msg = NULL; + if (filetype == SSL_FILETYPE_PEM) { + msg = "no start line: cadata does not contain a certificate"; + } else { + msg = "not enough data: cadata does not contain a certificate"; + } + _setSSLError(msg, 0, __FILE__, __LINE__); + retval = -1; + } else if ((filetype == SSL_FILETYPE_ASN1) && + (ERR_GET_LIB(err) == ERR_LIB_ASN1) && + (ERR_GET_REASON(err) == ASN1_R_HEADER_TOO_LONG)) { /* EOF ASN1 file, not an error */ ERR_clear_error(); retval = 0; } else if ((filetype == SSL_FILETYPE_PEM) && - (loaded > 0) && (ERR_GET_LIB(err) == ERR_LIB_PEM) && (ERR_GET_REASON(err) == PEM_R_NO_START_LINE)) { /* EOF PEM file, not an error */ ERR_clear_error(); retval = 0; - } else { + } else if (err != 0) { _setSSLError(NULL, 0, __FILE__, __LINE__); retval = -1; + } else { + retval = 0; } BIO_free(biobuf); -- 2.46.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor