summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-02-20 20:42:31 (GMT)
committerGitHub <noreply@github.com>2022-02-20 20:42:31 (GMT)
commitbe095f6c32188bba02079d086ac8639ea37cec3c (patch)
tree002f005bff12da40c9c5efaeca830e8246fdfad6 /Modules/_ssl.c
parentb77158b4da449ec5b8f682816a79d004fd65ed07 (diff)
downloadcpython-be095f6c32188bba02079d086ac8639ea37cec3c.zip
cpython-be095f6c32188bba02079d086ac8639ea37cec3c.tar.gz
cpython-be095f6c32188bba02079d086ac8639ea37cec3c.tar.bz2
bpo-46232: Fix parsing of certs with bit string in DN (GH-30351)
Diffstat (limited to 'Modules/_ssl.c')
-rw-r--r--Modules/_ssl.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index d7e041f..312b2ea 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1053,17 +1053,29 @@ _create_tuple_for_attribute(_sslmodulestate *state,
ASN1_OBJECT *name, ASN1_STRING *value)
{
Py_ssize_t buflen;
- unsigned char *valuebuf = NULL;
- PyObject *attr;
+ PyObject *pyattr;
+ PyObject *pyname = _asn1obj2py(state, name, 0);
- buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
- if (buflen < 0) {
+ if (pyname == NULL) {
_setSSLError(state, NULL, 0, __FILE__, __LINE__);
return NULL;
}
- attr = Py_BuildValue("Ns#", _asn1obj2py(state, name, 0), valuebuf, buflen);
- OPENSSL_free(valuebuf);
- return attr;
+
+ if (ASN1_STRING_type(value) == V_ASN1_BIT_STRING) {
+ buflen = ASN1_STRING_length(value);
+ pyattr = Py_BuildValue("Ny#", pyname, ASN1_STRING_get0_data(value), buflen);
+ } else {
+ unsigned char *valuebuf = NULL;
+ buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
+ if (buflen < 0) {
+ _setSSLError(state, NULL, 0, __FILE__, __LINE__);
+ Py_DECREF(pyname);
+ return NULL;
+ }
+ pyattr = Py_BuildValue("Ns#", pyname, valuebuf, buflen);
+ OPENSSL_free(valuebuf);
+ }
+ return pyattr;
}
static PyObject *