libimcv: SWID tag generation and discovery
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 20 Apr 2017 09:41:15 +0000 (11:41 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 8 Jul 2017 21:19:51 +0000 (23:19 +0200)
12 files changed:
src/libimcv/plugins/imc_swid/.gitignore
src/libimcv/plugins/imc_swid/Makefile.am
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_apache-2-2-22-13.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_bind-9-8-4-dfsg.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libsqlite-3-7-13-1.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-1-0-1e-2.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-dev-1-0-1e-2.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_openssl-1-0-1e-2.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_sqlite-3-7-13-1.swidtag [deleted file]
src/libimcv/plugins/imc_swid/regid.2004-03.org.strongswan_strongSwan.swidtag.in [deleted file]
src/libimcv/plugins/imc_swid/strongswan.org_strongSwan.swidtag.in [new file with mode: 0644]
src/libimcv/swid/swid_inventory.c

index 448ad2f..59e5e99 100644 (file)
@@ -1 +1 @@
-regid.2004-03.org.strongswan*.swidtag
+strongswan.org_*.swidtag
index c1cdb98..6cb929e 100644 (file)
@@ -1,14 +1,13 @@
-regid = regid.2004-03.org.strongswan
+regid = strongswan.org
 unique_sw_id = strongSwan-$(PACKAGE_VERSION_MAJOR)-$(PACKAGE_VERSION_MINOR)-$(PACKAGE_VERSION_BUILD)$(PACKAGE_VERSION_REVIEW)
 swid_tag = $(regid)_$(unique_sw_id).swidtag
 
-swiddir = $(prefix)/share/$(regid)
-swid_DATA = $(swid_tag)
-ipsec_DATA = $(swid_tag)
+swiddir = $(pkgdatadir)/swidtag
+dist_swid_DATA = $(swid_tag)
 EXTRA_DIST = $(regid)_strongSwan.swidtag.in
 CLEANFILES = $(regid)_strongSwan*.swidtag
 
-$(swid_tag) : regid.2004-03.org.strongswan_strongSwan.swidtag.in
+$(swid_tag) : $(regid)_strongSwan.swidtag.in
        $(AM_V_GEN) \
        sed \
        -e "s:@VERSION_MAJOR@:$(PACKAGE_VERSION_MAJOR):" \
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_apache-2-2-22-13.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_apache-2-2-22-13.swidtag
deleted file mode 100644 (file)
index 82e16d2..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>apache2</product_title>
-  <product_version>
-    <name>2.2-22-13</name>
-    <numeric>
-      <major>2</major>
-      <minor>2</minor>
-      <build>22</build>
-      <review>13</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>Apache Software Foundation</name>
-    <regid>regid.1995-04.org.apache</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>apache-2-2-22-13</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_bind-9-8-4-dfsg.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_bind-9-8-4-dfsg.swidtag
deleted file mode 100644 (file)
index 9e856eb..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>bind9</product_title>
-  <product_version>
-    <name>9-8-4-dfsg</name>
-    <numeric>
-      <major>9</major>
-      <minor>8</minor>
-      <build>4</build>
-      <review>dfsg</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>Internet Systems Consortium</name>
-    <regid>regid.1994-04.org.isc</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>bind-9-8-4-dfsg</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libsqlite-3-7-13-1.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libsqlite-3-7-13-1.swidtag
deleted file mode 100644 (file)
index 7650263..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>libsqlite3</product_title>
-  <product_version>
-    <name>3.7.13-1</name>
-    <numeric>
-      <major>3</major>
-      <minor>7</minor>
-      <build>13</build>
-      <review>1</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>SQLite Project</name>
-    <regid>regid.2002-08.org.sqlite</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>libsqlite-3-7-13-1</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-1-0-1e-2.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-1-0-1e-2.swidtag
deleted file mode 100644 (file)
index 5a31c57..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>libssl1.0.0</product_title>
-  <product_version>
-    <name>1.0.1e-2</name>
-    <numeric>
-      <major>1</major>
-      <minor>0</minor>
-      <build>1e</build>
-      <review>2</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>OpenSSL Project</name>
-    <regid>regid.1998-12.org.openssl</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>libssl-1-0-1e-2</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-dev-1-0-1e-2.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_libssl-dev-1-0-1e-2.swidtag
deleted file mode 100644 (file)
index cc6888b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>libssl-dev</product_title>
-  <product_version>
-    <name>1.0.1e-2</name>
-    <numeric>
-      <major>1</major>
-      <minor>0</minor>
-      <build>1e</build>
-      <review>2</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>OpenSSL Project</name>
-    <regid>regid.1998-12.org.openssl</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>libssl-dev-1-0-1e-2</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_openssl-1-0-1e-2.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_openssl-1-0-1e-2.swidtag
deleted file mode 100644 (file)
index af0a60d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>openssl</product_title>
-  <product_version>
-    <name>1.0.1e-2</name>
-    <numeric>
-      <major>1</major>
-      <minor>0</minor>
-      <build>1e</build>
-      <review>2</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>OpenSSL Project</name>
-    <regid>regid.1998-12.org.openssl</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>openssl-1-0-1e-2</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_sqlite-3-7-13-1.swidtag b/src/libimcv/plugins/imc_swid/regid.1999-03.org.debian/regid.1999-03.org.debian_sqlite-3-7-13-1.swidtag
deleted file mode 100644 (file)
index 43d0fdc..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<software_identification_tag xmlns="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">
-  <entitlement_required_indicator>true</entitlement_required_indicator>
-  <product_title>sqlite3</product_title>
-  <product_version>
-    <name>3.7.13-1</name>
-    <numeric>
-      <major>3</major>
-      <minor>7</minor>
-      <build>13</build>
-      <review>1</review>
-    </numeric>
-  </product_version>
-  <software_creator>
-    <name>SQLite Project</name>
-    <regid>regid.2002-08.org.sqlite</regid>
-  </software_creator>
-  <software_licensor>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </software_licensor>
-  <software_id>
-    <unique_id>sqlite-3-7-13-1</unique_id>
-    <tag_creator_regid>regid.1999-03.org.debian</tag_creator_regid>
-  </software_id>
-  <tag_creator>
-    <name>Debian Project</name>
-    <regid>regid.1999-03.org.debian</regid>
-  </tag_creator>
-</software_identification_tag>
diff --git a/src/libimcv/plugins/imc_swid/regid.2004-03.org.strongswan_strongSwan.swidtag.in b/src/libimcv/plugins/imc_swid/regid.2004-03.org.strongswan_strongSwan.swidtag.in
deleted file mode 100644 (file)
index 8b7b50f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<SoftwareIdentity
-  name="strongSwan"
-  uniqueId="strongSwan-@VERSION_MAJOR@-@VERSION_MINOR@-@VERSION_BUILD@@VERSION_REVIEW@"
-  version="@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_BUILD@@VERSION_REVIEW@" versionScheme="alphanumeric"
-  xmlns="http://standards.iso.org/iso/19770/-2/2014/schema.xsd">
-  <Entity
-    name="strongSwan Project"
-    regid="regid.2004-03.org.strongswan"
-    role="publisher licensor tagcreator"/>
-</SoftwareIdentity>
diff --git a/src/libimcv/plugins/imc_swid/strongswan.org_strongSwan.swidtag.in b/src/libimcv/plugins/imc_swid/strongswan.org_strongSwan.swidtag.in
new file mode 100644 (file)
index 0000000..4935fea
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<SoftwareIdentity
+  name="strongSwan"
+  tagId="strongSwan-@VERSION_MAJOR@-@VERSION_MINOR@-@VERSION_BUILD@@VERSION_REVIEW@"
+  version="@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_BUILD@@VERSION_REVIEW@" versionScheme="alphanumeric"
+  xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd">
+  <Entity
+    name="strongSwan Project"
+    regid="strongswan.org"
+    role="softwareCreator licensor tagCreator"/>
+</SoftwareIdentity>
index a492869..7b05e83 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2014 Andreas Steffen
+ * Copyright (C) 2013-2017 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -237,7 +237,7 @@ static status_t generate_tags(private_swid_inventory_t *this, char *generator,
 }
 
 static bool collect_tags(private_swid_inventory_t *this, char *pathname,
-                                                swid_inventory_t *targets)
+                                                swid_inventory_t *targets, bool is_swidtag_dir)
 {
        char *rel_name, *abs_name;
        struct stat st;
@@ -251,72 +251,49 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname,
                         pathname, strerror(errno));
                return FALSE;
        }
-       DBG2(DBG_IMC, "entering %s", pathname);
+       if (is_swidtag_dir)
+       {
+                       DBG2(DBG_IMC, "entering %s", pathname);
+       }
 
        while (enumerator->enumerate(enumerator, &rel_name, &abs_name, &st))
        {
-               char * start, *stop;
+               char *separator, *suffix;
                chunk_t tag_creator;
                chunk_t unique_sw_id = chunk_empty, tag_file_path = chunk_empty;
 
-               if (!strstr(rel_name, "regid."))
-               {
-                       continue;
-               }
                if (S_ISDIR(st.st_mode))
                {
-                       /* In case of a targeted request */
-                       if (targets->get_count(targets))
-                       {
-                               enumerator_t *target_enumerator;
-                               swid_tag_id_t *tag_id;
-                               bool match = FALSE;
-
-                               target_enumerator = targets->create_enumerator(targets);
-                               while (target_enumerator->enumerate(target_enumerator, &tag_id))
-                               {
-                                       if (chunk_equals(tag_id->get_tag_creator(tag_id),
-                                               chunk_from_str(rel_name)))
-                                       {
-                                               match = TRUE;
-                                               break;
-                                       }
-                               }
-                               target_enumerator->destroy(target_enumerator);
-
-                               if (!match)
-                               {
-                                       continue;
-                               }
-                       }
-
-                       if (!collect_tags(this, abs_name, targets))
+                       if (!collect_tags(this, abs_name, targets, is_swidtag_dir ||
+                                                         streq(rel_name, "swidtag")))
                        {
                                goto end;
                        }
                        continue;
                }
+               if (!is_swidtag_dir)
+               {
+                       continue;
+               }
 
-               /* parse the regid filename into its components */
-               start = rel_name;
-               stop = strchr(start, '_');
-               if (!stop)
+               /* found a swidtag file? */
+               suffix = strstr(rel_name, ".swidtag");
+               if (!suffix)
                {
-                       DBG1(DBG_IMC, "  %s", rel_name);
-                       DBG1(DBG_IMC, "  '_' separator not found");
-                       goto end;
+                       continue;
                }
-               tag_creator = chunk_create(start, stop-start);
-               start = stop + 1;
 
-               stop = strstr(start, ".swidtag");
-               if (!stop)
+               /* parse the swidtag filename into its components */
+               separator = strchr(rel_name, '_');
+               if (!separator)
                {
                        DBG1(DBG_IMC, "  %s", rel_name);
-                       DBG1(DBG_IMC, "  swidtag postfix not found");
+                       DBG1(DBG_IMC, "  '_' separator not found");
                        goto end;
                }
-               unique_sw_id = chunk_create(start, stop-start);
+               tag_creator = chunk_create(rel_name, separator-rel_name);
+
+               unique_sw_id = chunk_create(separator+1, suffix-separator-1);
                tag_file_path = chunk_from_str(abs_name);
 
                /* In case of a targeted request */
@@ -334,7 +311,7 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname,
                                target_tag_creator  = tag_id->get_tag_creator(tag_id);
 
                                if (chunk_equals(target_unique_sw_id, unique_sw_id) &&
-                                       chunk_equals(target_tag_creator, tag_creator))
+                                   chunk_equals(target_tag_creator, tag_creator))
                                {
                                        match = TRUE;
                                        break;
@@ -358,7 +335,7 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname,
                        if (!xml_tag)
                        {
                                DBG1(DBG_IMC, "  opening '%s' failed: %s", abs_name,
-                                        strerror(errno));
+                                    strerror(errno));
                                goto end;
                        }
 
@@ -378,7 +355,10 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname,
 
 end:
        enumerator->destroy(enumerator);
-       DBG2(DBG_IMC, "leaving %s", pathname);
+       if (is_swidtag_dir)
+       {
+               DBG2(DBG_IMC, "leaving %s", pathname);
+       }
 
        return success;
 }
@@ -396,7 +376,7 @@ METHOD(swid_inventory_t, collect, bool,
         * Collect swidtag files by iteratively entering all directories in
         * the tree under the "directory" path.
         */
-       return collect_tags(this, directory, targets);
+       return collect_tags(this, directory, targets, FALSE);
 }
 
 METHOD(swid_inventory_t, add, void,