|
|
f63228 |
|
|
|
f63228 |
# HG changeset patch
|
|
|
f63228 |
# User Benjamin Peterson <benjamin@python.org>
|
|
|
f63228 |
# Date 1409232801 14400
|
|
|
f63228 |
# Node ID 97081a80f487841d81aeed55d398a1dba1faca00
|
|
|
f63228 |
# Parent 3ae399c6ecf685086ebf07e17717955f21e14cb8
|
|
|
f63228 |
fix load_verify_locations on unicode paths (closes #22244)
|
|
|
f63228 |
|
|
|
f63228 |
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
|
|
|
f63228 |
--- a/Lib/test/test_ssl.py
|
|
|
f63228 |
+++ b/Lib/test/test_ssl.py
|
|
|
f63228 |
@@ -850,11 +850,14 @@ class ContextTests(unittest.TestCase):
|
|
|
f63228 |
ctx.load_verify_locations(cafile=CERTFILE, capath=None)
|
|
|
f63228 |
ctx.load_verify_locations(BYTES_CERTFILE)
|
|
|
f63228 |
ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
|
|
|
f63228 |
+ ctx.load_verify_locations(cafile=BYTES_CERTFILE.decode('utf-8'))
|
|
|
f63228 |
self.assertRaises(TypeError, ctx.load_verify_locations)
|
|
|
f63228 |
self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None)
|
|
|
f63228 |
with self.assertRaises(IOError) as cm:
|
|
|
f63228 |
ctx.load_verify_locations(WRONGCERT)
|
|
|
f63228 |
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
|
|
f63228 |
+ with self.assertRaises(IOError):
|
|
|
f63228 |
+ ctx.load_verify_locations(u'')
|
|
|
f63228 |
with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
|
|
|
f63228 |
ctx.load_verify_locations(BADCERT)
|
|
|
f63228 |
ctx.load_verify_locations(CERTFILE, CAPATH)
|
|
|
f63228 |
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
|
|
|
f63228 |
--- a/Modules/_ssl.c
|
|
|
f63228 |
+++ b/Modules/_ssl.c
|
|
|
f63228 |
@@ -2628,17 +2628,33 @@ load_verify_locations(PySSLContext *self
|
|
|
f63228 |
}
|
|
|
f63228 |
|
|
|
f63228 |
if (cafile) {
|
|
|
f63228 |
- cafile_bytes = PyString_AsEncodedObject(
|
|
|
f63228 |
- cafile, Py_FileSystemDefaultEncoding, "strict");
|
|
|
f63228 |
- if (!cafile_bytes) {
|
|
|
f63228 |
- goto error;
|
|
|
f63228 |
+ if (PyString_Check(cafile)) {
|
|
|
f63228 |
+ Py_INCREF(cafile);
|
|
|
f63228 |
+ cafile_bytes = cafile;
|
|
|
f63228 |
+ } else {
|
|
|
f63228 |
+ PyObject *u = PyUnicode_FromObject(cafile);
|
|
|
f63228 |
+ if (!u)
|
|
|
f63228 |
+ goto error;
|
|
|
f63228 |
+ cafile_bytes = PyUnicode_AsEncodedString(
|
|
|
f63228 |
+ u, Py_FileSystemDefaultEncoding, NULL);
|
|
|
f63228 |
+ Py_DECREF(u);
|
|
|
f63228 |
+ if (!cafile_bytes)
|
|
|
f63228 |
+ goto error;
|
|
|
f63228 |
}
|
|
|
f63228 |
}
|
|
|
f63228 |
if (capath) {
|
|
|
f63228 |
- capath_bytes = PyString_AsEncodedObject(
|
|
|
f63228 |
- capath, Py_FileSystemDefaultEncoding, "strict");
|
|
|
f63228 |
- if (!capath_bytes) {
|
|
|
f63228 |
- goto error;
|
|
|
f63228 |
+ if (PyString_Check(capath)) {
|
|
|
f63228 |
+ Py_INCREF(capath);
|
|
|
f63228 |
+ capath_bytes = capath;
|
|
|
f63228 |
+ } else {
|
|
|
f63228 |
+ PyObject *u = PyUnicode_FromObject(capath);
|
|
|
f63228 |
+ if (!u)
|
|
|
f63228 |
+ goto error;
|
|
|
f63228 |
+ capath_bytes = PyUnicode_AsEncodedString(
|
|
|
f63228 |
+ u, Py_FileSystemDefaultEncoding, NULL);
|
|
|
f63228 |
+ Py_DECREF(u);
|
|
|
f63228 |
+ if (!capath_bytes)
|
|
|
f63228 |
+ goto error;
|
|
|
f63228 |
}
|
|
|
f63228 |
}
|
|
|
f63228 |
|
|
|
f63228 |
|