Commit 22f21358 authored by Benjamin Peterson's avatar Benjamin Peterson

fix load_verify_locations on unicode paths (closes #22244)

parent c2d86044
...@@ -850,11 +850,14 @@ class ContextTests(unittest.TestCase): ...@@ -850,11 +850,14 @@ class ContextTests(unittest.TestCase):
ctx.load_verify_locations(cafile=CERTFILE, capath=None) ctx.load_verify_locations(cafile=CERTFILE, capath=None)
ctx.load_verify_locations(BYTES_CERTFILE) ctx.load_verify_locations(BYTES_CERTFILE)
ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None) ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
ctx.load_verify_locations(cafile=BYTES_CERTFILE.decode('utf-8'))
self.assertRaises(TypeError, ctx.load_verify_locations) self.assertRaises(TypeError, ctx.load_verify_locations)
self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None) self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None)
with self.assertRaises(IOError) as cm: with self.assertRaises(IOError) as cm:
ctx.load_verify_locations(WRONGCERT) ctx.load_verify_locations(WRONGCERT)
self.assertEqual(cm.exception.errno, errno.ENOENT) self.assertEqual(cm.exception.errno, errno.ENOENT)
with self.assertRaises(IOError):
ctx.load_verify_locations(u'')
with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"): with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
ctx.load_verify_locations(BADCERT) ctx.load_verify_locations(BADCERT)
ctx.load_verify_locations(CERTFILE, CAPATH) ctx.load_verify_locations(CERTFILE, CAPATH)
......
...@@ -2628,17 +2628,33 @@ load_verify_locations(PySSLContext *self, PyObject *args, PyObject *kwds) ...@@ -2628,17 +2628,33 @@ load_verify_locations(PySSLContext *self, PyObject *args, PyObject *kwds)
} }
if (cafile) { if (cafile) {
cafile_bytes = PyString_AsEncodedObject( if (PyString_Check(cafile)) {
cafile, Py_FileSystemDefaultEncoding, "strict"); Py_INCREF(cafile);
if (!cafile_bytes) { cafile_bytes = cafile;
goto error; } else {
PyObject *u = PyUnicode_FromObject(cafile);
if (!u)
goto error;
cafile_bytes = PyUnicode_AsEncodedString(
u, Py_FileSystemDefaultEncoding, NULL);
Py_DECREF(u);
if (!cafile_bytes)
goto error;
} }
} }
if (capath) { if (capath) {
capath_bytes = PyString_AsEncodedObject( if (PyString_Check(capath)) {
capath, Py_FileSystemDefaultEncoding, "strict"); Py_INCREF(capath);
if (!capath_bytes) { capath_bytes = capath;
goto error; } else {
PyObject *u = PyUnicode_FromObject(capath);
if (!u)
goto error;
capath_bytes = PyUnicode_AsEncodedString(
u, Py_FileSystemDefaultEncoding, NULL);
Py_DECREF(u);
if (!capath_bytes)
goto error;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment