You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2014/10/28 17:17:48 UTC
svn commit: r1634906 - in /subversion/branches/svn-auth-x509/subversion:
include/svn_x509.h libsvn_subr/x509.h libsvn_subr/x509info.c
libsvn_subr/x509parse.c svn/auth-cmd.c tests/libsvn_subr/x509-test.c
Author: breser
Date: Tue Oct 28 16:17:47 2014
New Revision: 1634906
URL: http://svn.apache.org/r1634906
Log:
On the svn-auth-x509 branch: Preserve all the issuer and subject attributes not
just the ones we know about.
Attributes are then accessible based on the string representation of their OIDs
(dotted decimal format) as keys to a hash. An array of OIDs exists to preserve
the ordering of the OIDs in the certificate. Well known OIDs are defined as
constants.
* subversion/include/svn_x509.h
(SVN_X509_OID_COMMON_NAME, SVN_X509_OID_COUNTRY, SVN_X509_OID_LOCALITY,
SVN_X509_OID_STATE, SVN_X509_OID_ORGANIZATION, SVN_X509_OID_ORG_UNIT,
SVN_X509_OID_EMAIL): New constants.
(svn_x509_certinfo_get_subject, svn_x509_certinfo_get_issuer): Add pool.
(svn_x509_certinfo_get_subject_cn): Removed.
(svn_x509_certinfo_get_subject_oids, svn_x509_certinfo_get_subject_attr):
New functions.
* subversion/libsvn_subr/x509.h
(asn1_oid): New private struct to store info about OIDs.
(asn1_oids): Static list of asn1_oid entries for well known OIDs.
(OID_X520, OID_PKCS9): Removed.
(svn_x509_certinfo_t): Changed the issuer and subject from being
stored as strings to stored as an array and hash pair.
* subversion/libsvn_subr/x509info.c
(deep_copy_array, deep_copy_hash, oid_string_to_asn1_oid,
oid_string_to_best_label, get_dn, svn_x509_certinfo_get_subject_oids,
svn_x509_certinfo_get_subject_attr, svn_x509_certinfo_get_issuer_oids,
svn_x509_certinfo_get_issuer_attr): New functions.
(svn_x509_certinfo_dup): Update to copy the issuer and subject that are
stored as a array and hash pair with the deep_copy_*().
(svn_x509_certinfo_get_subject, svn_x509_certinfo_get_issuer): Update
to use get_dn() instead of retrieving already calculated string.
(svn_x509_certinfo_get_subject_cn): Removed.
* subversion/libsvn_subr/x509parse.c
(starts_with, x509_dn_gets): Removed.
(asn1_oid_to_string, x509_name_to_certinfo): New function.
(is_hostname): Adjust to work on C strings instead of svn_string_t.
(x509parse_get_hostnames): Rework to use the new storage for the subject.
(svn_x509_parse_cert): Adjust to use new storage and functions.
* subversion/libsvn_subr/auth-cmd.c
(show_cert): Pass pool to svn_x509_certinfo_get_subject() and
svn_x509_certinfo_get_issuer().
* subversion/tests/libsvn_subr/x509-test.c
(x509_test, cert_tests): Add list of OIDS to test struct.
(compare_oids): New function.
(compare_results): Update to pass pools to svn_x509_certinfo_get_subject() and
svn_x509_certinfo_get_issuer() and check the OID list.
Modified:
subversion/branches/svn-auth-x509/subversion/include/svn_x509.h
subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509.h
subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c
subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c
subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c
subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c
Modified: subversion/branches/svn-auth-x509/subversion/include/svn_x509.h
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/include/svn_x509.h?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/include/svn_x509.h (original)
+++ subversion/branches/svn-auth-x509/subversion/include/svn_x509.h Tue Oct 28 16:17:47 2014
@@ -38,6 +38,14 @@
extern "C" {
#endif
+#define SVN_X509_OID_COMMON_NAME "2.5.4.3"
+#define SVN_X509_OID_COUNTRY "2.5.4.6"
+#define SVN_X509_OID_LOCALITY "2.5.4.7"
+#define SVN_X509_OID_STATE "2.5.4.8"
+#define SVN_X509_OID_ORGANIZATION "2.5.4.10"
+#define SVN_X509_OID_ORG_UNIT "2.5.4.11"
+#define SVN_X509_OID_EMAIL "1.2.840.113549.1.9.1"
+
/**
* Representation of parsed certificate info.
*
@@ -83,21 +91,58 @@ svn_x509_certinfo_dup(const svn_x509_cer
* @since New in 1.9.
*/
const char *
-svn_x509_certinfo_get_subject(const svn_x509_certinfo_t *certinfo);
+svn_x509_certinfo_get_subject(const svn_x509_certinfo_t *certinfo,
+ apr_pool_t *result_pool);
+
+/**
+ * Returns a list of the the object IDs of the attributes available
+ * for the subject in the @a certinfo. The oids in the list are C
+ * strings with dot separated integers.
+ *
+ * @since New in 1.9.
+ */
+const apr_array_header_t *
+svn_x509_certinfo_get_subject_oids(const svn_x509_certinfo_t *certinfo);
/**
- * Returns the subject CN from @a certinfo.
+ * Returns the value of the attribute with the object ID specified in
+ * @a oid of the subject from @a certinfo. @a oid is a string of dot
+ * separated integers.
+ *
* @since New in 1.9.
*/
const char *
-svn_x509_certinfo_get_subject_cn(const svn_x509_certinfo_t *certinfo);
+svn_x509_certinfo_get_subject_attr(const svn_x509_certinfo_t *certinfo,
+ const char *oid);
/**
* Returns the cerficiate issuer DN from @a certinfo.
* @since New in 1.9.
*/
const char *
-svn_x509_certinfo_get_issuer(const svn_x509_certinfo_t *certinfo);
+svn_x509_certinfo_get_issuer(const svn_x509_certinfo_t *certinfo,
+ apr_pool_t *result_pool);
+
+/**
+ * Returns a list of the the object IDs of the attributes available
+ * for the issuer in the @a certinfo. The oids in the list are C
+ * strings with dot separated integers.
+ *
+ * @since New in 1.9.
+ */
+const apr_array_header_t *
+svn_x509_certinfo_get_issuer_oids(const svn_x509_certinfo_t *certinfo);
+
+/**
+ * Returns the value of the attribute with the object ID specified in
+ * @a oid of the issuer from @a certinfo. @a oid is a string of dot
+ * separated integers.
+ *
+ * @since New in 1.9.
+ */
+const char *
+svn_x509_certinfo_get_issuer_attr(const svn_x509_certinfo_t *certinfo,
+ const char *oid);
/**
* Returns the start of the certificate validity period from @a certinfo.
Modified: subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509.h
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509.h?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509.h (original)
+++ subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509.h Tue Oct 28 16:17:47 2014
@@ -38,6 +38,8 @@
#include <stddef.h>
#include <apr_time.h>
+#include "svn_x509.h"
+
/*
* DER constants
*/
@@ -64,16 +66,23 @@
/*
* various object identifiers
*/
-#define X520_COMMON_NAME 3
-#define X520_COUNTRY 6
-#define X520_LOCALITY 7
-#define X520_STATE 8
-#define X520_ORGANIZATION 10
-#define X520_ORG_UNIT 11
-#define PKCS9_EMAIL 1
+typedef struct asn1_oid {
+ const char *oid_string;
+ const char *short_label;
+ const char *long_label;
+} asn1_oid;
+
+static asn1_oid asn1_oids[] = {
+ { SVN_X509_OID_COMMON_NAME, "CN", "commonName" },
+ { SVN_X509_OID_COUNTRY, "C", "countryName" },
+ { SVN_X509_OID_LOCALITY, "L", "localityName" },
+ { SVN_X509_OID_STATE, "ST", "stateOrProvinceName" },
+ { SVN_X509_OID_ORGANIZATION, "O", "organizationName" },
+ { SVN_X509_OID_ORG_UNIT, "OU", "organizationalUnitName"},
+ { SVN_X509_OID_EMAIL, NULL, "emailAddress" },
+ { NULL },
+};
-#define OID_X520 "\x55\x04"
-#define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09"
#define OID_SUBJECT_ALT_NAME "\x55\x1D\x11"
#ifdef __cplusplus
@@ -121,9 +130,10 @@ typedef struct _x509_cert {
*/
struct svn_x509_certinfo_t
{
- const char *subject;
- const char *subject_cn;
- const char *issuer;
+ apr_array_header_t *issuer_oids;
+ apr_hash_t *issuer;
+ apr_array_header_t *subject_oids;
+ apr_hash_t *subject;
apr_time_t valid_from;
apr_time_t valid_to;
svn_checksum_t *digest;
Modified: subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c (original)
+++ subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509info.c Tue Oct 28 16:17:47 2014
@@ -28,57 +28,174 @@
#include <apr_pools.h>
#include <apr_tables.h>
-#include "svn_x509.h"
+#include "svn_string.h"
+#include "svn_hash.h"
#include "x509.h"
+static apr_array_header_t *
+deep_copy_array(apr_array_header_t *s, apr_pool_t *result_pool)
+{
+ int i;
+ apr_array_header_t *d;
+
+ if (!s)
+ return NULL;
+
+ d = apr_array_copy(result_pool, s);
+
+ /* Make a deep copy of the strings in the array. */
+ for (i = 0; i < s->nelts; ++i)
+ APR_ARRAY_IDX(d, i, const char *) =
+ apr_pstrdup(result_pool,
+ APR_ARRAY_IDX(s, i, const char *));
+
+ return d;
+}
+
+static apr_hash_t *deep_copy_hash(apr_hash_t *s,
+ apr_pool_t *scratch_pool,
+ apr_pool_t *result_pool)
+{
+ apr_hash_t *d;
+ apr_hash_index_t *i;
+
+ if (!s)
+ return NULL;
+
+ d = apr_hash_make(result_pool);
+ i = apr_hash_first(scratch_pool, s);
+
+ /* Make a deep copy of the hash keys and values. */
+ while (i)
+ {
+ const void *key;
+ void *val;
+ apr_ssize_t klen;
+
+ apr_hash_this(i, &key, &klen, &val);
+ apr_hash_set(d, apr_pstrndup(result_pool, key, klen), klen,
+ apr_pstrdup(result_pool, val));
+ i = apr_hash_next(i);
+ }
+
+ return d;
+}
+
svn_x509_certinfo_t *
svn_x509_certinfo_dup(const svn_x509_certinfo_t *certinfo,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
svn_x509_certinfo_t *result = apr_palloc(result_pool, sizeof(*result));
- result->subject = apr_pstrdup(result_pool, certinfo->subject);
- result->subject_cn = apr_pstrdup(result_pool, certinfo->subject_cn);
- result->issuer = apr_pstrdup(result_pool, certinfo->issuer);
+ result->subject_oids = deep_copy_array(certinfo->subject_oids, result_pool);
+ result->subject = deep_copy_hash(certinfo->subject, scratch_pool, result_pool);
+ result->issuer_oids = deep_copy_array(certinfo->issuer_oids, result_pool);
+ result->issuer = deep_copy_hash(certinfo->issuer, scratch_pool, result_pool);
result->valid_from = certinfo->valid_from;
result->valid_to = certinfo->valid_to;
result->digest = svn_checksum_dup(certinfo->digest, result_pool);
+ result->hostnames = deep_copy_array(certinfo->hostnames, result_pool);
+
+ return result;
+}
+
+static const asn1_oid *oid_string_to_asn1_oid(const char *oid_string)
+{
+ const asn1_oid *oid;
- if (!certinfo->hostnames)
- result->hostnames = NULL;
- else
+ for (oid = asn1_oids; oid->oid_string; oid++)
{
- int i;
- result->hostnames = apr_array_copy(result_pool, certinfo->hostnames);
+ if (strcmp(oid_string, oid->oid_string) == 0)
+ return oid;
+ }
- /* Make a deep copy of the strings in the array. */
- for (i = 0; i < result->hostnames->nelts; ++i)
- APR_ARRAY_IDX(result->hostnames, i, const char*) =
- apr_pstrdup(result_pool,
- APR_ARRAY_IDX(result->hostnames, i, const char*));
+ return NULL;
+}
+
+static const char *oid_string_to_best_label(const char *oid_string)
+{
+ const asn1_oid *oid = oid_string_to_asn1_oid(oid_string);
+
+ if (oid)
+ {
+ if (oid->short_label)
+ return oid->short_label;
+
+ if (oid->long_label)
+ return oid->long_label;
}
- return result;
+ return oid_string;
+}
+
+/*
+ * Store the name from dn in printable form into buf,
+ * using scratch_pool for any temporary allocations.
+ * If CN is not NULL, return any common name in CN
+ */
+static const char *
+get_dn(apr_array_header_t *oids,
+ apr_hash_t *hash,
+ apr_pool_t *result_pool)
+{
+ svn_stringbuf_t *buf = svn_stringbuf_create_empty(result_pool);
+ int n;
+
+ for (n = 0; n < oids->nelts; n++)
+ {
+ const char *field = APR_ARRAY_IDX(oids, n, const char *);
+
+ if (n > 0)
+ svn_stringbuf_appendcstr(buf, ", ");
+
+ svn_stringbuf_appendcstr(buf, oid_string_to_best_label(field));
+ svn_stringbuf_appendbyte(buf, '=');
+ svn_stringbuf_appendcstr(buf, svn_hash_gets(hash, field));
+ }
+
+ return buf->data;
+}
+
+const char *
+svn_x509_certinfo_get_subject(const svn_x509_certinfo_t *certinfo,
+ apr_pool_t *result_pool)
+{
+ return get_dn(certinfo->subject_oids, certinfo->subject, result_pool);
+}
+
+const apr_array_header_t *
+svn_x509_certinfo_get_subject_oids(const svn_x509_certinfo_t *certinfo)
+{
+ return certinfo->subject_oids;
}
const char *
-svn_x509_certinfo_get_subject(const svn_x509_certinfo_t *certinfo)
+svn_x509_certinfo_get_subject_attr(const svn_x509_certinfo_t *certinfo,
+ const char *oid)
{
- return certinfo->subject;
+ return svn_hash_gets(certinfo->subject, oid);
}
const char *
-svn_x509_certinfo_get_subject_cn(const svn_x509_certinfo_t *certinfo)
+svn_x509_certinfo_get_issuer(const svn_x509_certinfo_t *certinfo,
+ apr_pool_t *result_pool)
+{
+ return get_dn(certinfo->issuer_oids, certinfo->issuer, result_pool);
+}
+
+const apr_array_header_t *
+svn_x509_certinfo_get_issuer_oids(const svn_x509_certinfo_t *certinfo)
{
- return certinfo->subject_cn;
+ return certinfo->issuer_oids;
}
const char *
-svn_x509_certinfo_get_issuer(const svn_x509_certinfo_t *certinfo)
+svn_x509_certinfo_get_issuer_attr(const svn_x509_certinfo_t *certinfo,
+ const char *oid)
{
- return certinfo->issuer;
+ return svn_hash_gets(certinfo->issuer, oid);
}
apr_time_t
Modified: subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c (original)
+++ subversion/branches/svn-auth-x509/subversion/libsvn_subr/x509parse.c Tue Oct 28 16:17:47 2014
@@ -53,7 +53,6 @@
#include "svn_checksum.h"
#include "svn_utf.h"
#include "svn_ctype.h"
-#include "svn_x509.h"
#include "private/svn_utf_private.h"
#include "private/svn_string_private.h"
@@ -159,17 +158,6 @@ oids_equal(x509_buf *left, x509_buf *rig
right->p, right->len);
}
-static svn_boolean_t
-starts_with(const x509_buf *buf,
- const char *sw_buf,
- apr_size_t sw_len)
-{
- if (buf->len < sw_len)
- return FALSE;
-
- return memcmp((const char *)buf->p, sw_buf, sw_len) == 0;
-}
-
/*
* Version ::= INTEGER { v1(0), v2(1), v3(2) }
*/
@@ -887,108 +875,112 @@ x509name_to_utf8_string(const x509_name
return nul_escape(utf8_string, result_pool);
}
-/*
- * Store the name from dn in printable form into buf,
- * using scratch_pool for any temporary allocations.
- * If CN is not NULL, return any common name in CN
- */
-static void
-x509parse_dn_gets(svn_stringbuf_t *buf, svn_stringbuf_t *cn,
- const x509_name * dn, apr_pool_t *scratch_pool)
+/* Given an OID return a string representation in RESULT.
+ * For example an OID with the bytes "\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01"
+ * would be converted to the string "1.2.840.113549.1.9.1". */
+static svn_error_t *
+asn1_oid_to_string(svn_stringbuf_t **result, const x509_buf *oid,
+ apr_pool_t *scratch_pool, apr_pool_t *result_pool)
{
- const x509_name *name;
+ svn_stringbuf_t *out = svn_stringbuf_create_empty(result_pool);
+ const unsigned char *p = oid->p;
+ const unsigned char *end = p + oid->len;
const char *temp;
- name = dn;
+ *result = NULL;
- while (name != NULL) {
- const svn_string_t *utf8_value;
- svn_boolean_t return_cn = FALSE;
+ if (oid->tag != ASN1_OID)
+ return svn_error_create(SVN_ERR_ASN1_UNEXPECTED_TAG, NULL, NULL);
- if (name != dn)
- svn_stringbuf_appendcstr(buf, ", ");
+ if (oid->len <= 0)
+ return svn_error_create(SVN_ERR_ASN1_OUT_OF_DATA, NULL, NULL);
- if (starts_with(&name->oid, OID_X520, sizeof(OID_X520) - 1))
+ while (p != end) {
+ if (p == oid->p)
{
- switch (name->oid.p[2]) {
- case X520_COMMON_NAME:
- svn_stringbuf_appendcstr(buf, "CN=");
- if (cn)
- return_cn = TRUE;
- break;
-
- case X520_COUNTRY:
- svn_stringbuf_appendcstr(buf, "C=");
- break;
-
- case X520_LOCALITY:
- svn_stringbuf_appendcstr(buf, "L=");
- break;
-
- case X520_STATE:
- svn_stringbuf_appendcstr(buf, "ST=");
- break;
-
- case X520_ORGANIZATION:
- svn_stringbuf_appendcstr(buf, "O=");
- break;
-
- case X520_ORG_UNIT:
- svn_stringbuf_appendcstr(buf, "OU=");
- break;
-
- default:
- temp = apr_psprintf(scratch_pool, "0x%02X=", name->oid.p[2]);
- svn_stringbuf_appendcstr(buf, temp);
- break;
- }
+ /* Handle decoding the first two values of the OID. These values
+ * are encoded by taking the first value and adding 40 to it and
+ * adding the result to the second value, then placing this single
+ * value in the first byte of the output. This is unambiguous since
+ * the first value is apparently limited to 0, 1 or 2 and the second
+ * is limited to 0 to 39. */
+ temp = apr_psprintf(scratch_pool, "%d.%d", *p / 40, *p % 40);
+ p++;
}
- else if (starts_with(&name->oid, OID_PKCS9, sizeof(OID_PKCS9) - 1))
+ else if (*p < 128)
{
- switch (name->oid.p[8]) {
- case PKCS9_EMAIL:
- svn_stringbuf_appendcstr(buf, "emailAddress=");
- break;
-
- default:
- temp = apr_psprintf(scratch_pool, "0x%02X=", name->oid.p[8]);
- svn_stringbuf_appendcstr(buf, temp);
- break;
- }
+ /* The remaining values if they're less than 128 are just
+ * the number one to one encoded */
+ temp = apr_psprintf(scratch_pool, ".%d", *p);
+ p++;
}
else
- svn_stringbuf_appendcstr(buf, "\?\?=");
-
- utf8_value = x509name_to_utf8_string(name, scratch_pool);
- if (utf8_value)
{
- svn_stringbuf_appendbytes(buf, utf8_value->data, utf8_value->len);
- if (return_cn)
- svn_stringbuf_appendbytes(cn, utf8_value->data, utf8_value->len);
+ /* Values greater than 128 are encoded as a series of 7 bit values
+ * with the left most bit set to indicate this encoding with the
+ * last octet missing the left most bit to finish out the series.. */
+ int collector = 0;
+
+ do {
+ collector = collector << 7 | (*(p++) & 0x7f);
+ } while (p != end && *p > 127);
+ collector = collector << 7 | *(p++);
+ temp = apr_psprintf(scratch_pool, ".%d", collector);
}
+ svn_stringbuf_appendcstr(out, temp);
+ }
+
+ *result = out;
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+x509_name_to_certinfo(apr_array_header_t **oids,
+ apr_hash_t **hash,
+ const x509_name *dn,
+ apr_pool_t *scratch_pool,
+ apr_pool_t *result_pool)
+{
+ const x509_name *name = dn;
+
+ *oids = apr_array_make(result_pool, 6, sizeof(const char *));
+ *hash = apr_hash_make(result_pool);
+
+ while (name != NULL) {
+ svn_stringbuf_t *oid_string;
+ const svn_string_t *utf8_value;
+
+ SVN_ERR(asn1_oid_to_string(&oid_string, &name->oid,
+ scratch_pool, result_pool));
+ APR_ARRAY_PUSH(*oids, const char *) = oid_string->data;
+ utf8_value = x509name_to_utf8_string(name, result_pool);
+ if (utf8_value)
+ svn_hash_sets(*hash, oid_string->data, utf8_value->data);
else
/* this should never happen */
- svn_stringbuf_appendfill(buf, '?', 2);
+ svn_hash_sets(*hash, oid_string->data, "??");
name = name->next;
}
+
+ return SVN_NO_ERROR;
}
static svn_boolean_t
-is_hostname(const svn_string_t *str)
+is_hostname(const char *str)
{
- apr_size_t i;
+ apr_size_t i, len = strlen(str);
- for (i = 0; i < str->len; i++)
+ for (i = 0; i < len; i++)
{
- char c = str->data[i];
+ char c = str[i];
/* '-' is only legal when not at the start or end of a label */
if (c == '-')
{
- if (i + 1 != str->len)
+ if (i + 1 != len)
{
- if (str->data[i + 1] == '.')
+ if (str[i + 1] == '.')
return FALSE; /* '-' preceeds a '.' */
}
else
@@ -998,7 +990,7 @@ is_hostname(const svn_string_t *str)
if (i == 0)
return FALSE; /* '-' is at start of string */
else
- if (str->data[i - 1] == '.')
+ if (str[i - 1] == '.')
return FALSE; /* '-' follows a '.' */
}
else if (c != '*' && c != '.' && !svn_ctype_isalnum(c))
@@ -1009,15 +1001,17 @@ is_hostname(const svn_string_t *str)
}
static void
-x509parse_get_hostnames(apr_array_header_t **names, x509_cert *crt,
+x509parse_get_hostnames(svn_x509_certinfo_t *ci, x509_cert *crt,
apr_pool_t *result_pool, apr_pool_t *scratch_pool)
{
+ ci->hostnames = NULL;
+
if (crt->dnsnames && crt->dnsnames->nelts > 0)
{
int i;
- *names = apr_array_make(result_pool, crt->dnsnames->nelts,
- sizeof(const char*));
+ ci->hostnames = apr_array_make(result_pool, crt->dnsnames->nelts,
+ sizeof(const char*));
/* Subject Alt Names take priority */
for (i = 0; i < crt->dnsnames->nelts; i++)
@@ -1028,35 +1022,21 @@ x509parse_get_hostnames(apr_array_header
scratch_pool);
temp = fuzzy_escape(temp, result_pool);
- APR_ARRAY_PUSH(*names, const char*) = temp->data;
+ APR_ARRAY_PUSH(ci->hostnames, const char*) = temp->data;
}
}
else
{
- const x509_name *name = &crt->subject;
- const svn_string_t *utf8_value = NULL;
-
/* no SAN then get the hostname from the CommonName on the cert */
- while (name != NULL)
- {
- if (starts_with(&name->oid, OID_X520, sizeof(OID_X520) - 1))
- {
- if (name->oid.p[2] == X520_COMMON_NAME)
- {
- utf8_value = x509name_to_utf8_string(name, scratch_pool);
- if (is_hostname(utf8_value))
- break;
- else
- utf8_value = NULL;
- }
- }
- name = name->next;
- }
+ const char *utf8_value;
+
+ utf8_value = svn_x509_certinfo_get_subject_attr(ci,
+ SVN_X509_OID_COMMON_NAME);
- if (utf8_value)
+ if (utf8_value && is_hostname(utf8_value))
{
- *names = apr_array_make(result_pool, 1, sizeof(const char*));
- APR_ARRAY_PUSH(*names, const char*) = utf8_value->data;
+ ci->hostnames = apr_array_make(result_pool, 1, sizeof(const char*));
+ APR_ARRAY_PUSH(ci->hostnames, const char*) = utf8_value;
}
}
}
@@ -1077,8 +1057,6 @@ svn_x509_parse_cert(svn_x509_certinfo_t
const unsigned char *end;
x509_cert *crt;
svn_x509_certinfo_t *ci;
- svn_stringbuf_t *namebuf;
- svn_stringbuf_t *cnbuf;
crt = apr_pcalloc(scratch_pool, sizeof(*crt));
p = (const unsigned char *)buf;
@@ -1213,16 +1191,12 @@ svn_x509_parse_cert(svn_x509_certinfo_t
ci = apr_pcalloc(result_pool, sizeof(*ci));
/* Get the subject name */
- namebuf = svn_stringbuf_create_empty(result_pool);
- cnbuf = svn_stringbuf_create_empty(result_pool);
- x509parse_dn_gets(namebuf, cnbuf, &crt->subject, scratch_pool);
- ci->subject = namebuf->data;
- ci->subject_cn = (svn_stringbuf_isempty(cnbuf) ? NULL : cnbuf->data);
+ SVN_ERR(x509_name_to_certinfo(&ci->subject_oids, &ci->subject, &crt->subject,
+ scratch_pool, result_pool));
/* Get the issuer name */
- namebuf = svn_stringbuf_create_empty(result_pool);
- x509parse_dn_gets(namebuf, NULL, &crt->issuer, scratch_pool);
- ci->issuer = namebuf->data;
+ SVN_ERR(x509_name_to_certinfo(&ci->issuer_oids, &ci->issuer, &crt->issuer,
+ scratch_pool, result_pool));
/* Copy the validity range */
ci->valid_from = crt->valid_from;
@@ -1234,7 +1208,7 @@ svn_x509_parse_cert(svn_x509_certinfo_t
result_pool));
/* Construct the array of host names */
- x509parse_get_hostnames(&ci->hostnames, crt, result_pool, scratch_pool);
+ x509parse_get_hostnames(ci, crt, result_pool, scratch_pool);
*certinfo = ci;
return SVN_NO_ERROR;
Modified: subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c (original)
+++ subversion/branches/svn-auth-x509/subversion/svn/auth-cmd.c Tue Oct 28 16:17:47 2014
@@ -189,7 +189,7 @@ show_cert(const svn_string_t *pem_cert,
}
SVN_ERR(svn_cmdline_printf(scratch_pool, _("Subject: %s\n"),
- svn_x509_certinfo_get_subject(certinfo)));
+ svn_x509_certinfo_get_subject(certinfo, scratch_pool)));
SVN_ERR(svn_cmdline_printf(scratch_pool, _("Valid from: %s\n"),
svn_time_to_human_cstring(
svn_x509_certinfo_get_valid_from(certinfo),
@@ -199,7 +199,7 @@ show_cert(const svn_string_t *pem_cert,
svn_x509_certinfo_get_valid_to(certinfo),
scratch_pool)));
SVN_ERR(svn_cmdline_printf(scratch_pool, _("Issuer: %s\n"),
- svn_x509_certinfo_get_issuer(certinfo)));
+ svn_x509_certinfo_get_issuer(certinfo, scratch_pool)));
SVN_ERR(svn_cmdline_printf(scratch_pool, _("Fingerprint: %s\n"),
svn_checksum_to_cstring_display(
svn_x509_certinfo_get_digest(certinfo),
Modified: subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c?rev=1634906&r1=1634905&r2=1634906&view=diff
==============================================================================
--- subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c (original)
+++ subversion/branches/svn-auth-x509/subversion/tests/libsvn_subr/x509-test.c Tue Oct 28 16:17:47 2014
@@ -32,8 +32,10 @@
struct x509_test {
const char *base64_cert; /* Base64 encoded DER X.509 cert */
- const char *subject; /* Subject in the format that the parser returns */
- const char *issuer; /* Issuer in the format that the parser returns */
+ const char *subject; /* Subject Distinguished Name */
+ const char *subject_oids; /* Space separated list of oids in Subject */
+ const char *issuer; /* Issuer Distinguished Name */
+ const char *issuer_oids; /* Space separated list of oids in Issuer */
/* These timesamps are in the format that svn_time_to_cstring() produces.
* This is not the same string as the parser returns since it returns
@@ -75,7 +77,9 @@ static struct x509_test cert_tests[] = {
"hI5FdJWUWVSgnSw=",
"C=US, ST=Maryland, L=Forest Hill, O=Apache Software Foundation, "
"OU=Infrastructure, CN=*.apache.org",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.11 2.5.4.3",
"C=US, O=Thawte, Inc., CN=Thawte SSL CA",
+ "2.5.4.6 2.5.4.10 2.5.4.3",
"2014-04-11T00:00:00.000000Z",
"2016-04-07T23:59:59.000000Z",
"*.apache.org",
@@ -105,7 +109,9 @@ static struct x509_test cert_tests[] = {
"/rgsCJgFsBDPBYR3ju0Ahqg7v6kwg9O2PJzyb4ljsw8oI0sCwHTZW5I5FMq2D9g6"
"hj80N2fhS9QWoLyeKoMTNB2Do6VaNrLrCJiscZWrsnM1f+XBqV8hMuHX8A==",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-06-27T17:31:51.000000Z",
"2114-06-03T17:31:51.000000Z",
NULL,
@@ -136,7 +142,9 @@ static struct x509_test cert_tests[] = {
"L=\xce\x91\xce\xb8\xce\xae\xce\xbd\xce\xb1, "
"O=\xcf\x80\xce\xb1\xcf\x81\xce\xac\xce\xb4\xce\xb5\xce\xb9\xce\xb3"
"\xce\xbc\xce\xb1, CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-07-02T18:36:10.000000Z",
"2015-07-02T18:36:10.000000Z",
"www.example.com",
@@ -185,7 +193,9 @@ static struct x509_test cert_tests[] = {
"\xf0\x9d\x9f\xba\xf0\x9d\x9f\xbb\xf0\x9d\x9f\xbc\xf0\x9d\x9f\xbd"
"\xf0\x9d\x9f\xbe\xf0\x9d\x9f\xbf, "
"CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.11 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-07-22T22:37:30.000000Z",
"2015-07-22T22:37:30.000000Z",
"www.example.com",
@@ -219,7 +229,9 @@ static struct x509_test cert_tests[] = {
"L=\xce\x91\xce\xb8\xce\xae\xce\xbd\xce\xb1, "
"O=\xcf\x80\xce\xb1\xcf\x81\xce\xac\xce\xb4\xce\xb5\xce\xb9\xce\xb3"
"\xce\xbc\xce\xb1, CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-07-22T23:02:09.000000Z",
"2015-07-22T23:02:09.000000Z",
"www.example.com",
@@ -255,7 +267,9 @@ static struct x509_test cert_tests[] = {
"Bcwx241dxeGSYFHerqrTJIU=",
"C=NO, ST=M\xc3\xb8re og Romsdal, L=\xc3\x85lesund, O=d\xc3\xb8me, "
"CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-07-22T23:44:18.000000Z",
"2015-07-22T23:44:18.000000Z",
"www.example.com",
@@ -290,7 +304,9 @@ static struct x509_test cert_tests[] = {
"GSq5Dk8dnTdL2otToll+r4IqFLlp",
"C=US, ST=Washington, L=North Bend, O=Internet Widgits Pty Ltd, "
"CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=Internet Widgits CA",
+ "2.5.4.6 2.5.4.8 2.5.4.10 2.5.4.3",
"2014-07-25T17:41:04.000000Z",
"2015-07-25T17:41:04.000000Z",
"*.example.com, *.foo.example.com, *.bar.example.com, zig-zag.example.com",
@@ -321,7 +337,9 @@ static struct x509_test cert_tests[] = {
"+Glctn9tyke4b1VZ2Yr+R4OktrId44ZQcRD44+88v5ThP8DQsvkXcjREMFAIPkvG"
"CEDOIem4l9KFfnsHn8/4KvoBRkmCkGaSwOwUdUG+jIjBpY/82kM=",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=Internet Widgits CA",
+ "2.5.4.6 2.5.4.8 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=Internet Widgits CA",
+ "2.5.4.6 2.5.4.8 2.5.4.10 2.5.4.3",
"2014-07-25T17:41:03.000000Z",
"2024-07-22T17:41:03.000000Z",
NULL,
@@ -353,7 +371,9 @@ static struct x509_test cert_tests[] = {
"BKe64WsF6ZxTq3zLVGy5I8LpbtlvSmAaBp4=",
"C=US, ST=Washington, L=North Bend, O=Internet Widgits Pty Ltd, "
"CN=ip.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.10 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=Internet Widgits CA",
+ "2.5.4.6 2.5.4.8 2.5.4.10 2.5.4.3",
"2014-07-25T18:43:28.000000Z",
"2015-07-25T18:43:28.000000Z",
"*.example.com, *.foo.example.com, *.bar.example.com, zig-zag.example.com",
@@ -382,7 +402,9 @@ static struct x509_test cert_tests[] = {
"NpUcv4H9Tgdl6KgrfsbQtAeouWCgoiNzrul8FOaQTdJLZfCsjuE+IkGpM+DX8PiF"
"5M41EqkSKia8sChFIln+lkRY41OWP9uQ1VXCfdRIzOnXWh9U",
"C=UK, ST=England, L=Sheffield, CN=www.example.com",
+ "2.5.4.6 2.5.4.8 2.5.4.7 2.5.4.3",
"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
+ "2.5.4.6 2.5.4.8 2.5.4.10",
"2014-08-18T09:59:45.000000Z",
"2015-08-18T09:59:45.000000Z",
"www.example.com",
@@ -460,13 +482,51 @@ compare_hostnames(const char *expected,
}
static svn_error_t *
+compare_oids(const char *expected,
+ const apr_array_header_t *actual,
+ const char *subject,
+ apr_pool_t *pool)
+{
+ int i;
+ svn_stringbuf_t *buf;
+
+ if (!actual)
+ {
+ if (expected)
+ return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+ "The oids didn't match expected '%s',"
+ " got NULL for cert '%s'",
+ expected, subject);
+ return SVN_NO_ERROR;
+ }
+
+ buf = svn_stringbuf_create_empty(pool);
+ for (i = 0; i < actual->nelts; ++i)
+ {
+ const char *oid = APR_ARRAY_IDX(actual, i, const char*);
+ if (i > 0)
+ svn_stringbuf_appendbyte(buf, ' ');
+ svn_stringbuf_appendcstr(buf, oid);
+ }
+
+ if (strcmp(expected, buf->data))
+ return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+ "The oids didn't match expected '%s',"
+ " got '%s' for cert '%s'",
+ expected, buf->data, subject);
+ return SVN_NO_ERROR;
+
+}
+
+
+static svn_error_t *
compare_results(struct x509_test *xt,
svn_x509_certinfo_t *certinfo,
apr_pool_t *pool)
{
const char *v;
- v = svn_x509_certinfo_get_subject(certinfo);
+ v = svn_x509_certinfo_get_subject(certinfo, pool);
if (!v)
return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
"No subject for cert '%s'", xt->subject);
@@ -476,7 +536,10 @@ compare_results(struct x509_test *xt,
"expected '%s', got '%s'", xt->subject,
xt->subject, v);
- v = svn_x509_certinfo_get_issuer(certinfo);
+ SVN_ERR(compare_oids(xt->subject_oids, svn_x509_certinfo_get_subject_oids(certinfo),
+ xt->subject, pool));
+
+ v = svn_x509_certinfo_get_issuer(certinfo, pool);
if (!v)
return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
"No issuer for cert '%s'", xt->subject);
@@ -486,6 +549,9 @@ compare_results(struct x509_test *xt,
"expected '%s', got '%s'", xt->subject,
xt->issuer, v);
+ SVN_ERR(compare_oids(xt->issuer_oids, svn_x509_certinfo_get_issuer_oids(certinfo),
+ xt->subject, pool));
+
SVN_ERR(compare_dates(xt->valid_from,
svn_x509_certinfo_get_valid_from(certinfo),
"valid-from",
Re: svn commit: r1634906 - in /subversion/branches/svn-auth-x509/subversion:
include/svn_x509.h libsvn_subr/x509.h libsvn_subr/x509info.c libsvn_subr/x509parse.c
svn/auth-cmd.c tests/libsvn_subr/x509-test.c
Posted by Branko Čibej <br...@wandisco.com>.
On 30.10.2014 02:00, Ben Reser wrote:
> On 10/28/14 9:26 AM, Branko Čibej wrote:
>> Indentation is wrong.
> Whoops, somehow my code style setting got disabled when I wrote this and didn't
> notice it. Fixed in r1635359.
>
>> And I suggest using svn_iter_apr_array here.
>> ... and svn_iter_apr_hash here.
> Unless it's a big deal to you I'm not inclined to use those here. They feel
> very clunky for this use. For one thing I need to add another function for the
> callback that have only one line. For another I have to pass the pool into the
> callback baton since they both pass only a scratch pool.
I agree they're somewhat cluncky (but that's fixable). However, at least
svn_iter_apr_hash is faster (with a new-enough APR) than the most
obvious hash iteration loop.
C needs lambdas and closures ...
-- Brane
Re: svn commit: r1634906 - in
/subversion/branches/svn-auth-x509/subversion: include/svn_x509.h
libsvn_subr/x509.h libsvn_subr/x509info.c libsvn_subr/x509parse.c
svn/auth-cmd.c tests/libsvn_subr/x509-test.c
Posted by Ben Reser <be...@reser.org>.
On 10/28/14 9:26 AM, Branko Čibej wrote:
> Indentation is wrong.
Whoops, somehow my code style setting got disabled when I wrote this and didn't
notice it. Fixed in r1635359.
> And I suggest using svn_iter_apr_array here.
> ... and svn_iter_apr_hash here.
Unless it's a big deal to you I'm not inclined to use those here. They feel
very clunky for this use. For one thing I need to add another function for the
callback that have only one line. For another I have to pass the pool into the
callback baton since they both pass only a scratch pool.
Re: svn commit: r1634906 - in /subversion/branches/svn-auth-x509/subversion:
include/svn_x509.h libsvn_subr/x509.h libsvn_subr/x509info.c libsvn_subr/x509parse.c
svn/auth-cmd.c tests/libsvn_subr/x509-test.c
Posted by Branko Čibej <br...@wandisco.com>.
On 28.10.2014 17:17, breser@apache.org wrote:
> Author: breser
> Date: Tue Oct 28 16:17:47 2014
> New Revision: 1634906
[...]
> +static apr_array_header_t *
> +deep_copy_array(apr_array_header_t *s, apr_pool_t *result_pool)
> +{
> + int i;
> + apr_array_header_t *d;
> +
> + if (!s)
> + return NULL;
> +
> + d = apr_array_copy(result_pool, s);
> +
> + /* Make a deep copy of the strings in the array. */
> + for (i = 0; i < s->nelts; ++i)
> + APR_ARRAY_IDX(d, i, const char *) =
> + apr_pstrdup(result_pool,
> + APR_ARRAY_IDX(s, i, const char *));
> +
> + return d;
> +}
Indentation is wrong. And I suggest using svn_iter_apr_array here.
> +
> +static apr_hash_t *deep_copy_hash(apr_hash_t *s,
> + apr_pool_t *scratch_pool,
> + apr_pool_t *result_pool)
> +{
> + apr_hash_t *d;
> + apr_hash_index_t *i;
> +
> + if (!s)
> + return NULL;
> +
> + d = apr_hash_make(result_pool);
> + i = apr_hash_first(scratch_pool, s);
> +
> + /* Make a deep copy of the hash keys and values. */
> + while (i)
> + {
> + const void *key;
> + void *val;
> + apr_ssize_t klen;
> +
> + apr_hash_this(i, &key, &klen, &val);
> + apr_hash_set(d, apr_pstrndup(result_pool, key, klen), klen,
> + apr_pstrdup(result_pool, val));
> + i = apr_hash_next(i);
> + }
> +
> + return d;
> +}
... and svn_iter_apr_hash here.
-- Brane