X.509: Add parsing of alternative name to internal TLS implementation
[wpasupplicant] / src / tls / asn1.c
index 96bc1ac..2cb9318 100644 (file)
@@ -85,28 +85,16 @@ int asn1_get_next(const u8 *buf, size_t len, struct asn1_hdr *hdr)
 }
 
 
-int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
-                const u8 **next)
+int asn1_parse_oid(const u8 *buf, size_t len, struct asn1_oid *oid)
 {
-       struct asn1_hdr hdr;
        const u8 *pos, *end;
        unsigned long val;
        u8 tmp;
 
        os_memset(oid, 0, sizeof(*oid));
 
-       if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0)
-               return -1;
-
-       if (hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_OID) {
-               wpa_printf(MSG_DEBUG, "ASN.1: Expected OID - found class %d "
-                          "tag 0x%x", hdr.class, hdr.tag);
-               return -1;
-       }
-
-       pos = hdr.payload;
-       end = hdr.payload + hdr.length;
-       *next = end;
+       pos = buf;
+       end = buf + len;
 
        while (pos < end) {
                val = 0;
@@ -141,6 +129,26 @@ int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
 }
 
 
+int asn1_get_oid(const u8 *buf, size_t len, struct asn1_oid *oid,
+                const u8 **next)
+{
+       struct asn1_hdr hdr;
+
+       if (asn1_get_next(buf, len, &hdr) < 0 || hdr.length == 0)
+               return -1;
+
+       if (hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_OID) {
+               wpa_printf(MSG_DEBUG, "ASN.1: Expected OID - found class %d "
+                          "tag 0x%x", hdr.class, hdr.tag);
+               return -1;
+       }
+
+       *next = hdr.payload + hdr.length;
+
+       return asn1_parse_oid(hdr.payload, hdr.length, oid);
+}
+
+
 void asn1_oid_to_str(struct asn1_oid *oid, char *buf, size_t len)
 {
        char *pos = buf;