]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] gh-107077: Raise SSLCertVerificationError even if the error is set via SSL_ERRO...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 21 Feb 2024 16:02:34 +0000 (17:02 +0100)
committerGitHub <noreply@github.com>
Wed, 21 Feb 2024 16:02:34 +0000 (17:02 +0100)
(cherry picked from commit 77e09192b5f1caf14cd5f92ccb53a4592e83e8bc)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Misc/NEWS.d/next/Library/2023-08-03-12-52-19.gh-issue-107077.-pzHD6.rst [new file with mode: 0644]
Modules/_ssl.c

diff --git a/Misc/NEWS.d/next/Library/2023-08-03-12-52-19.gh-issue-107077.-pzHD6.rst b/Misc/NEWS.d/next/Library/2023-08-03-12-52-19.gh-issue-107077.-pzHD6.rst
new file mode 100644 (file)
index 0000000..ecaf437
--- /dev/null
@@ -0,0 +1,6 @@
+Seems that in some conditions, OpenSSL will return ``SSL_ERROR_SYSCALL``
+instead of ``SSL_ERROR_SSL`` when a certification verification has failed,
+but the error parameters will still contain ``ERR_LIB_SSL`` and
+``SSL_R_CERTIFICATE_VERIFY_FAILED``. We are now detecting this situation and
+raising the appropiate ``ssl.SSLCertVerificationError``. Patch by Pablo
+Galindo
index 0498c153caaf263f601583094cdda3dd802aa935..3f95d3e10374d8e5016af7daed41439e119c313d 100644 (file)
@@ -817,6 +817,10 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno)
                     errstr = "Some I/O error occurred";
                 }
             } else {
+                if (ERR_GET_LIB(e) == ERR_LIB_SSL &&
+                        ERR_GET_REASON(e) == SSL_R_CERTIFICATE_VERIFY_FAILED) {
+                    type = PySSLCertVerificationErrorObject;
+                }
                 p = PY_SSL_ERROR_SYSCALL;
             }
             break;