summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2005-03-19 19:52:24 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2005-03-19 19:52:24 +0000
commit3e56adee42b1b1d07b91dd2ea14978f599a04b06 (patch)
treea9111f1bcf16716b8eeb12a6a72c162e9e7e8114
parent2436218614096d677258e1f1df6d7c067a7f0b46 (diff)
downloadgnutls-3e56adee42b1b1d07b91dd2ea14978f599a04b06.tar.gz
corrected bug in gnutls_crq_get_attribute_by_oid()
-rw-r--r--lib/x509/common.c3
-rw-r--r--lib/x509/crq.c48
2 files changed, 32 insertions, 19 deletions
diff --git a/lib/x509/common.c b/lib/x509/common.c
index 37bd36f862..a31bd06367 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -74,6 +74,9 @@ static const oid2string _oid2str[] = {
{"0.9.2342.19200300.100.1.25", "DC", 0, 1},
{"0.9.2342.19200300.100.1.1", "UID", 0, 1},
+
+ /* PKCS #9
+ */
{"1.2.840.113549.1.9.1", "EMAIL", 0, 1},
{"1.2.840.113549.1.9.7", NULL, 1, 1},
diff --git a/lib/x509/crq.c b/lib/x509/crq.c
index 092d6863bf..af55d81dce 100644
--- a/lib/x509/crq.c
+++ b/lib/x509/crq.c
@@ -270,13 +270,13 @@ int gnutls_x509_crq_get_dn_oid(gnutls_x509_crq_t crq,
/* Parses an Attribute list in the asn1_struct, and searches for the
* given OID. The index indicates the attribute value to be returned.
*
- * Only printable data are returned, or GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE.
+ * If raw==0 only printable data are returned, or GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE.
*
* asn1_attr_name must be a string in the form "certificationRequestInfo.attributes"
*
*/
static int parse_attribute(ASN1_TYPE asn1_struct,
- const char *attr_name, const char *given_oid, int indx,
+ const char *attr_name, const char *given_oid, int indx, int raw,
char *buf, size_t * sizeof_buf)
{
int k1, result;
@@ -360,22 +360,32 @@ static int parse_attribute(ASN1_TYPE asn1_struct,
goto cleanup;
}
-
- printable = _gnutls_x509_oid_data_printable(oid);
-
- if (printable == 1) {
- if ((result =
- _gnutls_x509_oid_data2string
- (oid, value, len, buf, sizeof_buf)) < 0) {
+ if (raw==0) {
+ printable = _gnutls_x509_oid_data_printable(oid);
+ if (printable == 1) {
+ if ((result =
+ _gnutls_x509_oid_data2string
+ (oid, value, len, buf, sizeof_buf)) < 0) {
+ gnutls_assert();
+ goto cleanup;
+ }
+ return 0;
+ } else {
gnutls_assert();
- goto cleanup;
- }
-
- return 0;
- } else {
- gnutls_assert();
- return GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE;
- }
+ return GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE;
+ }
+ } else { /* raw!=0 */
+ if (*sizeof_buf > (size_t)len && buf!=NULL) {
+ *sizeof_buf = len;
+ memcpy( buf, value, len);
+
+ return 0;
+ } else {
+ *sizeof_buf = len;
+ gnutls_assert();
+ return GNUTLS_E_SHORT_MEMORY_BUFFER;
+ }
+ }
}
} while (1);
@@ -410,7 +420,7 @@ int gnutls_x509_crq_get_challenge_password(gnutls_x509_crq_t crq,
}
return parse_attribute(crq->crq, "certificationRequestInfo.attributes",
- "1.2.840.113549.1.9.7", 0, pass, sizeof_pass);
+ "1.2.840.113549.1.9.7", 0, 0, pass, sizeof_pass);
}
/**
@@ -483,7 +493,7 @@ int gnutls_x509_crq_get_attribute_by_oid(gnutls_x509_crq_t crq,
}
return parse_attribute(crq->crq, "certificationRequestInfo.attributes",
- oid, indx, buf, sizeof_buf);
+ oid, indx, 1, buf, sizeof_buf);
}
/**