aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2012-09-01 22:00:03 +0000
committerRob Austein <sra@hactrn.net>2012-09-01 22:00:03 +0000
commit64e71238a3a940a2c177d5d10423a7a1872b270e (patch)
tree44241d4ead267299e426193b464f437c6e1f7c8d
parent6c4ab62ea27c4f5ae7b17f57d1492f5476958194 (diff)
Clean up X509_object_helper_set_name() and teach it to deal with
numeric OIDs. svn path=/branches/tk274/; revision=4685
-rw-r--r--rpkid/ext/POW.c84
1 files changed, 34 insertions, 50 deletions
diff --git a/rpkid/ext/POW.c b/rpkid/ext/POW.c
index 70b504d6..a439bcd0 100644
--- a/rpkid/ext/POW.c
+++ b/rpkid/ext/POW.c
@@ -566,60 +566,47 @@ set_openssl_ssl_exception(const ssl_object *self, const int ret)
static PyObject *
X509_object_helper_set_name(X509_NAME *name, PyObject *name_sequence)
{
- PyObject *pair = NULL; PyObject *type = NULL; PyObject *value = NULL;
- int no_pairs = 0, i = 0, str_type = 0, nid;
- unsigned char *valueptr = NULL;
- char *typeptr = NULL;
+ PyObject *pair_obj = NULL;
+ PyObject *type_obj = NULL;
+ PyObject *value_obj = NULL;
+ char *type_str, *value_str;
+ int asn1_type, i;
- no_pairs = PySequence_Size(name_sequence);
- for (i = 0; i < no_pairs; i++) {
- if ((pair = PySequence_GetItem(name_sequence, i)) == NULL)
- return NULL;
+ for (i = 0; i < PySequence_Size(name_sequence); i++) {
- if (!PyTuple_Check(pair) && !PyList_Check(pair))
- lose_type_error("inapropriate type");
-
- if (PySequence_Size(pair) != 2)
- lose("each name entry must have 2 elements");
-
- if ((type = PySequence_GetItem(pair, 0)) == NULL)
- lose_type_error("could not get type string");
-
- if (!PyString_Check(type))
- lose_type_error("inapropriate type");
-
- if ((value = PySequence_GetItem(pair, 1)) == NULL)
- lose_type_error("could not get value string");
+ if ((pair_obj = PySequence_GetItem(name_sequence, i)) == NULL)
+ goto error;
- if (!PyString_Check(value))
- lose_type_error("inapropriate type");
+ if (!PySequence_Check(pair_obj) || PySequence_Size(pair_obj) != 2)
+ lose_type_error("each name entry must be a two-element sequence");
- typeptr = PyString_AsString(type);
- valueptr = (unsigned char *) PyString_AsString(value);
+ if ((type_obj = PySequence_GetItem(pair_obj, 0)) == NULL ||
+ (type_str = PyString_AsString(type_obj)) == NULL ||
+ (value_obj = PySequence_GetItem(pair_obj, 1)) == NULL ||
+ (value_str = PyString_AsString(value_obj)) == NULL)
+ goto error;
- str_type = ASN1_PRINTABLE_type(valueptr, -1);
- if ((nid = OBJ_ln2nid(typeptr)) == 0 &&
- (nid = OBJ_sn2nid(typeptr)) == 0)
- lose("unknown ASN1 object");
+ if ((asn1_type = ASN1_PRINTABLE_type(value_str, -1)) != V_ASN1_PRINTABLESTRING)
+ asn1_type = V_ASN1_UTF8STRING;
- if (!X509_NAME_add_entry_by_NID(name, nid, str_type, valueptr,
- strlen((char *) valueptr), -1, 0))
+ if (!X509_NAME_add_entry_by_txt(name, type_str, asn1_type,
+ value_str, strlen(value_str), -1, 0))
lose("unable to add name entry");
- Py_XDECREF(pair);
- Py_XDECREF(type);
- Py_XDECREF(value);
- pair = NULL;
- type = NULL;
- value = NULL;
+ Py_XDECREF(pair_obj);
+ Py_XDECREF(type_obj);
+ Py_XDECREF(value_obj);
+
+ pair_obj = type_obj = value_obj = NULL;
}
- return name_sequence;
+
+ Py_RETURN_NONE;
error:
- Py_XDECREF(pair);
- Py_XDECREF(type);
- Py_XDECREF(value);
+ Py_XDECREF(pair_obj);
+ Py_XDECREF(type_obj);
+ Py_XDECREF(value_obj);
return NULL;
}
@@ -1394,7 +1381,7 @@ X509_object_set_subject(x509_object *self, PyObject *args)
lose("could not allocate memory");
if (!X509_object_helper_set_name(name, name_sequence))
- lose("unable to set new name");
+ goto error;
if (!X509_set_subject_name(self->x509, name))
lose("unable to set name");
@@ -1404,7 +1391,8 @@ X509_object_set_subject(x509_object *self, PyObject *args)
Py_RETURN_NONE;
error:
-
+ if (name)
+ X509_NAME_free(name);
return NULL;
}
@@ -1441,7 +1429,7 @@ X509_object_set_issuer(x509_object *self, PyObject *args)
lose("could not allocate memory");
if (!X509_object_helper_set_name(name, name_sequence))
- lose("unable to set new name");
+ goto error;
if (!X509_set_issuer_name(self->x509,name))
lose("unable to set name");
@@ -1451,10 +1439,8 @@ X509_object_set_issuer(x509_object *self, PyObject *args)
Py_RETURN_NONE;
error:
-
if (name)
X509_NAME_free(name);
-
return NULL;
}
@@ -2539,7 +2525,7 @@ x509_crl_object_set_issuer(x509_crl_object *self, PyObject *args)
lose("could not allocate memory");
if (!X509_object_helper_set_name(name, name_sequence))
- lose("unable to set new name");
+ goto error;
if (!X509_NAME_set(&self->crl->crl->issuer, name))
lose("unable to set name");
@@ -2549,10 +2535,8 @@ x509_crl_object_set_issuer(x509_crl_object *self, PyObject *args)
Py_RETURN_NONE;
error:
-
if (name)
X509_NAME_free(name);
-
return NULL;
}