renamed known_oid() to asn1_known_oid() and defined asn1_get_oid()
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 15 Apr 2009 18:37:17 +0000 (18:37 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 15 Apr 2009 18:37:17 +0000 (18:37 -0000)
src/pluto/ac.c
src/pluto/asn1.c
src/pluto/asn1.h
src/pluto/crl.c
src/pluto/ocsp.c
src/pluto/pkcs7.c
src/pluto/x509.c

index 171f6ed..0ed890c 100644 (file)
@@ -519,7 +519,7 @@ parse_ac(chunk_t blob, x509acert_t *ac)
            ac->notAfter = asn1totime(&object, ASN1_GENERALIZEDTIME);
            break;
        case AC_OBJ_ATTRIBUTE_TYPE:
-           type = known_oid(object);
+           type = asn1_known_oid(object);
            break;
        case AC_OBJ_ATTRIBUTE_VALUE:
            {
@@ -549,7 +549,7 @@ parse_ac(chunk_t blob, x509acert_t *ac)
            }
            break;
        case AC_OBJ_EXTN_ID:
-           extn_oid = known_oid(object);
+           extn_oid = asn1_known_oid(object);
            break;
        case AC_OBJ_CRITICAL:
            critical = object.len && *object.ptr;
index 30a0dba..4ef7e6a 100644 (file)
@@ -116,7 +116,7 @@ asn1_algorithmIdentifier(int oid)
  *  position in the oid_names table is returned otherwise -1 is returned
  */
 int
-known_oid(chunk_t object)
+asn1_known_oid(chunk_t object)
 {
     int oid = 0;
 
@@ -136,15 +136,51 @@ known_oid(chunk_t object)
        else
        {
            if (oid_names[oid].next)
+           {
                oid = oid_names[oid].next;
+           }
            else
+           {
                return OID_UNKNOWN;
+           }
        }
     }
     return -1;
 }
 
 /*
+ * Converts an known OID index to ASN.1 OID
+ */ 
+chunk_t
+asn1_get_known_oid(int n)
+{
+    chunk_t oid;
+    int i;
+       
+    if (n < 0 || n >= OID_MAX)
+    {
+       return empty_chunk;
+    }
+       
+    i = oid_names[n].level + 1;
+    oid.ptr = alloc_bytes(i, "known oid");
+    oid.len = i;
+
+    do
+    {
+       if (oid_names[n].level >= i)
+       {
+           n--;
+           continue;
+       }
+       oid.ptr[--i] = oid_names[n--].octet;
+    }
+    while (i > 0);
+       
+    return oid;
+}
+
+/*
  *  Decodes the length in bytes of an ASN.1 object
  */
 u_int
@@ -484,7 +520,7 @@ debug_asn1_simple_object(chunk_t object, asn1_t type, u_int cond)
     switch (type)
     {
     case ASN1_OID:
-       oid = known_oid(object);
+       oid = asn1_known_oid(object);
        if (oid != OID_UNKNOWN)
        {
            DBG(DBG_PARSING,
@@ -735,7 +771,7 @@ parse_algorithmIdentifier(chunk_t blob, int level0, chunk_t *parameters)
        switch (objectID)
        {
        case ALGORITHM_ID_ALG:
-           alg = known_oid(object);
+           alg = asn1_known_oid(object);
            break;
        case ALGORITHM_ID_PARAMETERS:
            if (parameters != NULL)
index cead90a..d5f50ad 100644 (file)
@@ -117,7 +117,8 @@ extern const chunk_t ASN1_md5WithRSA_id;
 extern const chunk_t ASN1_sha1WithRSA_id;
 
 extern chunk_t asn1_algorithmIdentifier(int oid);
-extern int known_oid(chunk_t object);
+extern int asn1_known_oid(chunk_t object);
+extern chunk_t asn1_get_known_oid(int n);
 extern u_int asn1_length(chunk_t *blob);
 extern void code_asn1_length(size_t length, chunk_t *code);
 extern u_char* build_asn1_object(chunk_t *object, asn1_t type, size_t datalen);
index add131c..6b82807 100644 (file)
@@ -480,7 +480,7 @@ parse_x509crl(chunk_t blob, u_int level0, x509crl_t *crl)
        case CRL_OBJ_CRL_ENTRY_EXTN_VALUE:
        case CRL_OBJ_EXTN_VALUE:
            {
-               u_int extn_oid = known_oid(extnID);
+               u_int extn_oid = asn1_known_oid(extnID);
 
                if (extn_oid == OID_CRL_REASON_CODE)
                {
index f8bdc70..84e8876 100644 (file)
@@ -1134,7 +1134,7 @@ parse_basic_ocsp_response(chunk_t blob, int level0, response_t *res)
            res->responses = object;
            break;
        case BASIC_RESPONSE_EXT_ID:
-           extn_oid = known_oid(object);
+           extn_oid = asn1_known_oid(object);
            break;
        case BASIC_RESPONSE_CRITICAL:
            critical = object.len && *object.ptr;
@@ -1223,7 +1223,7 @@ parse_ocsp_response(chunk_t blob, response_t * res)
            }
            break;
        case OCSP_RESPONSE_TYPE:
-           ocspResponseType = known_oid(object);
+           ocspResponseType = asn1_known_oid(object);
            break;
        case OCSP_RESPONSE:
            {
@@ -1303,7 +1303,7 @@ parse_ocsp_single_response(chunk_t blob, int level0, single_response_t *sres)
            sres->nextUpdate = asn1totime(&object, ASN1_GENERALIZEDTIME);
            break;
        case SINGLE_RESPONSE_EXT_ID:
-           extn_oid = known_oid(object);
+           extn_oid = asn1_known_oid(object);
            break;
        case SINGLE_RESPONSE_CRITICAL:
            critical = object.len && *object.ptr;
index 2889489..905d4ca 100644 (file)
@@ -217,7 +217,7 @@ pkcs7_parse_contentInfo(chunk_t blob, u_int level0, contentInfo_t *cInfo)
 
        if (objectID == PKCS7_INFO_TYPE)
        {
-           cInfo->type = known_oid(object);
+           cInfo->type = asn1_known_oid(object);
            if (cInfo->type < OID_PKCS7_DATA
            ||  cInfo->type > OID_PKCS7_ENCRYPTED_DATA)
            {
@@ -458,7 +458,7 @@ pkcs7_parse_envelopedData(chunk_t blob, chunk_t *data
            )
            break;
        case PKCS7_CONTENT_TYPE:
-           if (known_oid(object) != OID_PKCS7_DATA)
+           if (asn1_known_oid(object) != OID_PKCS7_DATA)
            {
                 plog("encrypted content not of type pkcs7 data");
                 goto failed;
index e6f7b24..1f9a431 100644 (file)
@@ -562,7 +562,7 @@ dn_parse(chunk_t dn, chunk_t *str)
        }
 
        /* print OID */
-       oid_code = known_oid(oid);
+       oid_code = asn1_known_oid(oid);
        if (oid_code == OID_UNKNOWN)    /* OID not found in list */
        {
            hex_str(oid, str);
@@ -877,7 +877,7 @@ same_dn(chunk_t a, chunk_t b)
 
        /* printableStrings and email RDNs require uppercase comparison */
        if (type_a == type_b && (type_a == ASN1_PRINTABLESTRING ||
-          (type_a == ASN1_IA5STRING && known_oid(oid_a) == OID_PKCS9_EMAIL)))
+          (type_a == ASN1_IA5STRING && asn1_known_oid(oid_a) == OID_PKCS9_EMAIL)))
        {
            if (strncasecmp(value_a.ptr, value_b.ptr, value_b.len) != 0)
            {
@@ -955,7 +955,7 @@ match_dn(chunk_t a, chunk_t b, int *wildcards)
 
        /* printableStrings and email RDNs require uppercase comparison */
        if (type_a == type_b && (type_a == ASN1_PRINTABLESTRING ||
-          (type_a == ASN1_IA5STRING && known_oid(oid_a) == OID_PKCS9_EMAIL)))
+          (type_a == ASN1_IA5STRING && asn1_known_oid(oid_a) == OID_PKCS9_EMAIL)))
        {
            if (strncasecmp(value_a.ptr, value_b.ptr, value_b.len) != 0)
            {
@@ -1553,7 +1553,7 @@ parse_otherName(chunk_t blob, int level0)
        switch (objectID)
        {
        case ON_OBJ_ID_TYPE:
-           oid = known_oid(object);
+           oid = asn1_known_oid(object);
            break;
        case ON_OBJ_VALUE:
            if (oid == OID_XMPP_ADDR)
@@ -1809,7 +1809,7 @@ parse_authorityInfoAccess(chunk_t blob, int level0, chunk_t *accessLocation)
        switch (objectID)
        {
        case AUTH_INFO_ACCESS_METHOD:
-           accessMethod = known_oid(object);
+           accessMethod = asn1_known_oid(object);
            break;
        case AUTH_INFO_ACCESS_LOCATION:
            {
@@ -1870,7 +1870,7 @@ parse_extendedKeyUsage(chunk_t blob, int level0)
             return FALSE;
        }
        if (objectID == EXT_KEY_USAGE_PURPOSE_ID
-       && known_oid(object) == OID_OCSP_SIGNING)
+       && asn1_known_oid(object) == OID_OCSP_SIGNING)
        {
            return TRUE;
        }
@@ -2027,7 +2027,7 @@ parse_x509cert(chunk_t blob, u_int level0, x509cert_t *cert)
            cert->publicExponent = object;
            break;
        case X509_OBJ_EXTN_ID:
-           extn_oid = known_oid(object);
+           extn_oid = asn1_known_oid(object);
            break;
        case X509_OBJ_CRITICAL:
            critical = object.len && *object.ptr;