Skip to content

Commit

Permalink
[3.8] gh-107077: Raise SSLCertVerificationError even if the error is …
Browse files Browse the repository at this point in the history
…set via SSL_ERROR_SYSCALL (GH-107586) (GH-107591)

(cherry picked from commit 77e0919)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Co-authored-by: T. Wouters <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
5 people authored Feb 21, 2024
1 parent 8c6f277 commit 4d58a1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,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;
Expand Down

0 comments on commit 4d58a1d

Please sign in to comment.