Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def data_file(*name):
EMPTYCERT = data_file("nullcert.pem")
BADCERT = data_file("badcert.pem")
NONEXISTINGCERT = data_file("XXXnonexisting.pem")
NONEXISTINGKEY = data_file("XXXnonexistingkey.pem")
BADKEY = data_file("badkey.pem")
NOKIACERT = data_file("nokia.pem")
NULLBYTECERT = data_file("nullbytecert.pem")
Expand Down Expand Up @@ -1229,6 +1230,11 @@ def test_load_cert_chain(self):
with self.assertRaises(OSError) as cm:
ctx.load_cert_chain(NONEXISTINGCERT)
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(cm.exception.filename, NONEXISTINGCERT)
with self.assertRaises(OSError) as cm:
Comment thread
picnixz marked this conversation as resolved.
ctx.load_cert_chain(CERTFILE, keyfile=NONEXISTINGKEY)
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(cm.exception.filename, NONEXISTINGKEY)
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
ctx.load_cert_chain(BADCERT)
with self.assertRaisesRegex(ssl.SSLError, "PEM (lib|routines)"):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add filename context to OSError exceptions raised by
Comment thread
romuald marked this conversation as resolved.
Outdated
:func:`ssl.SSLContext.load_cert_chain`, allowing users to have more context
Comment thread
romuald marked this conversation as resolved.
Outdated
6 changes: 4 additions & 2 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4517,7 +4517,8 @@ load_cert_chain_lock_held(PySSLContext *self, _PySSLPasswordInfo *pw_info,
/* the password callback has already set the error information */
}
else if (errno != 0) {
PyErr_SetFromErrno(PyExc_OSError);
PyErr_SetFromErrnoWithFilename(PyExc_OSError,
PyBytes_AS_STRING(certfile_bytes));
ERR_clear_error();
}
else {
Expand All @@ -4537,7 +4538,8 @@ load_cert_chain_lock_held(PySSLContext *self, _PySSLPasswordInfo *pw_info,
/* the password callback has already set the error information */
}
else if (errno != 0) {
PyErr_SetFromErrno(PyExc_OSError);
PyErr_SetFromErrnoWithFilename(PyExc_OSError,
PyBytes_AS_STRING(keyfile_bytes ? keyfile_bytes : certfile_bytes));
ERR_clear_error();
}
else {
Expand Down
Loading