Parse UPN subjectAltNames in x509 plugin
authorMartin Willi <martin@revosec.ch>
Tue, 10 Aug 2010 15:27:17 +0000 (17:27 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 10 Aug 2010 16:46:31 +0000 (18:46 +0200)
src/libstrongswan/plugins/x509/x509_cert.c

index 92b576a..b60a005 100644 (file)
@@ -260,7 +260,7 @@ static const asn1Object_t otherNameObjects[] = {
 /**
  * Extracts an otherName
  */
-static bool parse_otherName(chunk_t blob, int level0)
+static bool parse_otherName(chunk_t *blob, int level0, id_type_t *type)
 {
        asn1_parser_t *parser;
        chunk_t object;
@@ -268,7 +268,7 @@ static bool parse_otherName(chunk_t blob, int level0)
        int oid = OID_UNKNOWN;
        bool success = FALSE;
 
-       parser = asn1_parser_create(otherNameObjects, blob);
+       parser = asn1_parser_create(otherNameObjects, *blob);
        parser->set_top_level(parser, level0);
 
        while (parser->iterate(parser, &objectID, &object))
@@ -279,13 +279,27 @@ static bool parse_otherName(chunk_t blob, int level0)
                                oid = asn1_known_oid(object);
                                break;
                        case ON_OBJ_VALUE:
-                               if (oid == OID_XMPP_ADDR)
+                               switch (oid)
                                {
-                                       if (!asn1_parse_simple_object(&object, ASN1_UTF8STRING,
-                                                               parser->get_level(parser)+1, "xmppAddr"))
-                                       {
-                                               goto end;
-                                       }
+                                       case OID_XMPP_ADDR:
+                                               if (!asn1_parse_simple_object(&object, ASN1_UTF8STRING,
+                                                                       parser->get_level(parser)+1, "xmppAddr"))
+                                               {
+                                                       goto end;
+                                               }
+                                               break;
+                                       case OID_USER_PRINCIPAL_NAME:
+                                               if (asn1_parse_simple_object(&object, ASN1_UTF8STRING,
+                                                                       parser->get_level(parser)+1, "msUPN"))
+                                               {       /* we handle UPNs as RFC822 addr */
+                                                       *blob = object;
+                                                       *type = ID_RFC822_ADDR;
+                                               }
+                                               else
+                                               {
+                                                       goto end;
+                                               }
+                                               break;
                                }
                                break;
                        default:
@@ -379,7 +393,8 @@ static identification_t *parse_generalName(chunk_t blob, int level0)
                                }
                                break;
                        case GN_OBJ_OTHER_NAME:
-                               if (!parse_otherName(object, parser->get_level(parser)+1))
+                               if (!parse_otherName(&object, parser->get_level(parser)+1,
+                                                                        &id_type))
                                {
                                        goto end;
                                }