Defined generic non-nul terminated string PA-TNC attribute
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 17 May 2015 16:16:08 +0000 (18:16 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 18 Aug 2015 19:25:38 +0000 (21:25 +0200)
src/libimcv/Makefile.am
src/libimcv/generic/generic_attr_bool.c
src/libimcv/generic/generic_attr_string.c [new file with mode: 0644]
src/libimcv/generic/generic_attr_string.h [new file with mode: 0644]
src/libimcv/ita/ita_attr.c
src/libimcv/ita/ita_attr_device_id.c [deleted file]
src/libimcv/ita/ita_attr_device_id.h [deleted file]
src/libimcv/plugins/imc_os/imc_os.c
src/libimcv/plugins/imv_attestation/imv_attestation_agent.c
src/libimcv/plugins/imv_os/imv_os_agent.c
src/libimcv/pwg/pwg_attr.c

index d2175a3..af2770c 100644 (file)
@@ -37,6 +37,7 @@ libimcv_la_SOURCES = \
        imv/imv_session_manager.h imv/imv_session_manager.c \
        imv/imv_workitem.h imv/imv_workitem.c \
        generic/generic_attr_bool.h generic/generic_attr_bool.c \
+       generic/generic_attr_string.h generic/generic_attr_string.c \
        ietf/ietf_attr.h ietf/ietf_attr.c \
        ietf/ietf_attr_assess_result.h ietf/ietf_attr_assess_result.c \
        ietf/ietf_attr_attr_request.h ietf/ietf_attr_attr_request.c \
@@ -54,7 +55,6 @@ libimcv_la_SOURCES = \
        ita/ita_attr_get_settings.h ita/ita_attr_get_settings.c \
        ita/ita_attr_settings.h ita/ita_attr_settings.c \
        ita/ita_attr_angel.h ita/ita_attr_angel.c \
-       ita/ita_attr_device_id.h ita/ita_attr_device_id.c \
        os_info/os_info.h os_info/os_info.c \
        pa_tnc/pa_tnc_attr.h \
        pa_tnc/pa_tnc_msg.h pa_tnc/pa_tnc_msg.c \
index 589b5e4..eca077a 100644 (file)
@@ -124,14 +124,15 @@ METHOD(pa_tnc_attr_t, process, status_t,
        bio_reader_t *reader;
        u_int32_t status;
   
-    pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes,
-                                                                                                         this->type.vendor_id);
        *offset = 0;
 
        if (this->value.len < this->length)
        {
                return NEED_MORE;
        }
+    pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes,
+                                                                                                         this->type.vendor_id);
+
        if (this->value.len != ATTR_BOOL_SIZE)
        {
                DBG1(DBG_TNC, "incorrect attribute size for %N/%N",
diff --git a/src/libimcv/generic/generic_attr_string.c b/src/libimcv/generic/generic_attr_string.c
new file mode 100644 (file)
index 0000000..e14e8d2
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2013-2015 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "generic_attr_string.h"
+
+#include <imcv.h>
+#include <pen/pen.h>
+#include <utils/debug.h>
+
+typedef struct private_generic_attr_string_t private_generic_attr_string_t;
+
+/**
+ * Private data of an generic_attr_string_t object.
+ */
+struct private_generic_attr_string_t {
+
+       /**
+        * Public members of generic_attr_string_t
+        */
+       generic_attr_string_t public;
+
+       /**
+        * Vendor-specific attribute type
+        */
+       pen_type_t type;
+
+       /**
+        * Length of attribute value
+        */
+       size_t length;
+
+       /**
+        * Attribute value or segment
+        */
+       chunk_t value;
+
+       /**
+        * Noskip flag
+        */
+       bool noskip_flag;
+
+       /**
+        * Reference count
+        */
+       refcount_t ref;
+};
+
+METHOD(pa_tnc_attr_t, get_type, pen_type_t,
+       private_generic_attr_string_t *this)
+{
+       return this->type;
+}
+
+METHOD(pa_tnc_attr_t, get_value, chunk_t,
+       private_generic_attr_string_t *this)
+{
+       return this->value;
+}
+
+METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
+       private_generic_attr_string_t *this)
+{
+       return this->noskip_flag;
+}
+
+METHOD(pa_tnc_attr_t, set_noskip_flag,void,
+       private_generic_attr_string_t *this, bool noskip)
+{
+       this->noskip_flag = noskip;
+}
+
+METHOD(pa_tnc_attr_t, build, void,
+       private_generic_attr_string_t *this)
+{
+       return;
+}
+
+METHOD(pa_tnc_attr_t, process, status_t,
+       private_generic_attr_string_t *this, u_int32_t *offset)
+{
+       enum_name_t *pa_attr_names;
+       u_char *pos;
+       *offset = 0;
+
+       if (this->value.len < this->length)
+       {
+               return NEED_MORE;
+       }
+    pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes,
+                                                                                                         this->type.vendor_id);
+
+       pos = memchr(this->value.ptr, '\0', this->value.len);
+       if (pos)
+       {
+               DBG1(DBG_TNC, "nul termination in %N/%N string attribute",
+                        pen_names, this->type.vendor_id, pa_attr_names, this->type.type);
+               *offset = pos - this->value.ptr;
+               return FAILED;
+       }
+
+       return SUCCESS;
+}
+
+METHOD(pa_tnc_attr_t, add_segment, void,
+       private_generic_attr_string_t *this, chunk_t segment)
+{
+       this->value = chunk_cat("mc", this->value, segment);
+}
+
+METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
+       private_generic_attr_string_t *this)
+{
+       ref_get(&this->ref);
+       return &this->public.pa_tnc_attribute;
+}
+
+METHOD(pa_tnc_attr_t, destroy, void,
+       private_generic_attr_string_t *this)
+{
+       if (ref_put(&this->ref))
+       {
+               free(this->value.ptr);
+               free(this);
+       }
+}
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *generic_attr_string_create_from_data(size_t length,
+                                                                       chunk_t value, pen_type_t type)
+{
+       private_generic_attr_string_t *this;
+
+       INIT(this,
+               .public = {
+                       .pa_tnc_attribute = {
+                               .get_type = _get_type,
+                               .get_value = _get_value,
+                               .get_noskip_flag = _get_noskip_flag,
+                               .set_noskip_flag = _set_noskip_flag,
+                               .build = _build,
+                               .process = _process,
+                               .add_segment = _add_segment,
+                               .get_ref = _get_ref,
+                               .destroy = _destroy,
+                       },
+               },
+               .type = type,
+               .length = length,
+               .value = chunk_clone(value),
+               .ref = 1,
+       );
+
+       return &this->public.pa_tnc_attribute;
+}
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *generic_attr_string_create(chunk_t value, pen_type_t type)
+{
+       return generic_attr_string_create_from_data(value.len, value, type);
+}
+
diff --git a/src/libimcv/generic/generic_attr_string.h b/src/libimcv/generic/generic_attr_string.h
new file mode 100644 (file)
index 0000000..c721029
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup generic_attr_string generic_attr_string
+ * @{ @ingroup generic_attr
+ */
+
+#ifndef GENERIC_ATTR_STRING_H_
+#define GENERIC_ATTR_STRING_H_
+
+typedef struct generic_attr_string_t generic_attr_string_t;
+
+#include <pen/pen.h>
+#include "pa_tnc/pa_tnc_attr.h"
+
+/**
+ * Class implementing a generic PA-TNC attribute containing a non-nul
+ * terminated string 
+ */
+struct generic_attr_string_t {
+
+       /**
+        * Public PA-TNC attribute interface
+        */
+       pa_tnc_attr_t pa_tnc_attribute;
+};
+
+/**
+ * Creates a generic_attr_string_t object
+ *
+ * @param string                       Non-nul terminated string
+ * @param type                         Vendor ID / Attribute Type
+ */
+pa_tnc_attr_t* generic_attr_string_create(chunk_t string, pen_type_t type);
+
+/**
+ * Creates an generic_attr_string_t object from received data
+ *
+ * @param length                       Total length of attribute value
+ * @param value                                Unparsed attribute value (might be a segment)
+ * @param type                         Vendor ID / Attribute Type
+ */
+pa_tnc_attr_t* generic_attr_string_create_from_data(size_t length,
+                                                                       chunk_t value, pen_type_t type);
+
+#endif /** GENERIC_ATTR_STRING_H_ @}*/
index 9d7706d..35c882c 100644 (file)
@@ -19,7 +19,7 @@
 #include "ita/ita_attr_get_settings.h"
 #include "ita/ita_attr_settings.h"
 #include "ita/ita_attr_angel.h"
-#include "ita/ita_attr_device_id.h"
+#include "generic/generic_attr_string.h"
 
 ENUM(ita_attr_names, ITA_ATTR_COMMAND, ITA_ATTR_DEVICE_ID,
        "Command",
@@ -53,7 +53,8 @@ pa_tnc_attr_t* ita_attr_create_from_data(u_int32_t type, size_t length,
                case ITA_ATTR_STOP_ANGEL:
                        return ita_attr_angel_create_from_data(FALSE);
                case ITA_ATTR_DEVICE_ID:
-                       return ita_attr_device_id_create_from_data(length, value);
+                       return generic_attr_string_create_from_data(length, value,
+                                                                       pen_type_create(PEN_ITA, type));
                default:
                        return NULL;
        }
diff --git a/src/libimcv/ita/ita_attr_device_id.c b/src/libimcv/ita/ita_attr_device_id.c
deleted file mode 100644 (file)
index 2328426..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2013-2014 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-#include "ita_attr.h"
-#include "ita_attr_device_id.h"
-
-#include <pen/pen.h>
-
-#include <utils/debug.h>
-
-typedef struct private_ita_attr_device_id_t private_ita_attr_device_id_t;
-
-/**
- * Private data of an ita_attr_device_id_t object.
- */
-struct private_ita_attr_device_id_t {
-
-       /**
-        * Public members of ita_attr_device_id_t
-        */
-       ita_attr_device_id_t public;
-
-       /**
-        * Vendor-specific attribute type
-        */
-       pen_type_t type;
-
-       /**
-        * Length of attribute value
-        */
-       size_t length;
-
-       /**
-        * Attribute value or segment
-        */
-       chunk_t value;
-
-       /**
-        * Noskip flag
-        */
-       bool noskip_flag;
-
-       /**
-        * Reference count
-        */
-       refcount_t ref;
-};
-
-METHOD(pa_tnc_attr_t, get_type, pen_type_t,
-       private_ita_attr_device_id_t *this)
-{
-       return this->type;
-}
-
-METHOD(pa_tnc_attr_t, get_value, chunk_t,
-       private_ita_attr_device_id_t *this)
-{
-       return this->value;
-}
-
-METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
-       private_ita_attr_device_id_t *this)
-{
-       return this->noskip_flag;
-}
-
-METHOD(pa_tnc_attr_t, set_noskip_flag,void,
-       private_ita_attr_device_id_t *this, bool noskip)
-{
-       this->noskip_flag = noskip;
-}
-
-METHOD(pa_tnc_attr_t, build, void,
-       private_ita_attr_device_id_t *this)
-{
-       return;
-}
-
-METHOD(pa_tnc_attr_t, process, status_t,
-       private_ita_attr_device_id_t *this, u_int32_t *offset)
-{
-       *offset = 0;
-
-       if (this->value.len < this->length)
-       {
-               return NEED_MORE;
-       }
-       return SUCCESS;
-}
-
-METHOD(pa_tnc_attr_t, add_segment, void,
-       private_ita_attr_device_id_t *this, chunk_t segment)
-{
-       this->value = chunk_cat("mc", this->value, segment);
-}
-
-METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
-       private_ita_attr_device_id_t *this)
-{
-       ref_get(&this->ref);
-       return &this->public.pa_tnc_attribute;
-}
-
-METHOD(pa_tnc_attr_t, destroy, void,
-       private_ita_attr_device_id_t *this)
-{
-       if (ref_put(&this->ref))
-       {
-               free(this->value.ptr);
-               free(this);
-       }
-}
-
-/**
- * Described in header.
- */
-pa_tnc_attr_t *ita_attr_device_id_create_from_data(size_t length, chunk_t value)
-{
-       private_ita_attr_device_id_t *this;
-
-       INIT(this,
-               .public = {
-                       .pa_tnc_attribute = {
-                               .get_type = _get_type,
-                               .get_value = _get_value,
-                               .get_noskip_flag = _get_noskip_flag,
-                               .set_noskip_flag = _set_noskip_flag,
-                               .build = _build,
-                               .process = _process,
-                               .add_segment = _add_segment,
-                               .get_ref = _get_ref,
-                               .destroy = _destroy,
-                       },
-               },
-               .type = { PEN_ITA, ITA_ATTR_DEVICE_ID },
-               .length = length,
-               .value = chunk_clone(value),
-               .ref = 1,
-       );
-
-       return &this->public.pa_tnc_attribute;
-}
-
-/**
- * Described in header.
- */
-pa_tnc_attr_t *ita_attr_device_id_create(chunk_t value)
-{
-       return ita_attr_device_id_create_from_data(value.len, value);
-}
-
diff --git a/src/libimcv/ita/ita_attr_device_id.h b/src/libimcv/ita/ita_attr_device_id.h
deleted file mode 100644 (file)
index 94bb778..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2013-2014 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-/**
- * @defgroup ita_attr_device_id ita_attr_device_id
- * @{ @ingroup ita_attr
- */
-
-#ifndef ITA_ATTR_DEVICE_ID_H_
-#define ITA_ATTR_DEVICE_ID_H_
-
-typedef struct ita_attr_device_id_t ita_attr_device_id_t;
-
-#include "pa_tnc/pa_tnc_attr.h"
-
-/**
- * Class implementing the ITA Device ID PA-TNC attribute.
- *
- */
-struct ita_attr_device_id_t {
-
-       /**
-        * Public PA-TNC attribute interface
-        */
-       pa_tnc_attr_t pa_tnc_attribute;
-
-};
-
-/**
- * Creates an ita_attr_device_id_t object
- *
- * @param value                                ITA Device ID attribute value
- */
-pa_tnc_attr_t* ita_attr_device_id_create(chunk_t value);
-
-/**
- * Creates an ita_attr_device_id_t object from received data
- *
- * @param length                       Total length of attribute value
- * @param value                                Unparsed attribute value (might be a segment)
- */
-pa_tnc_attr_t* ita_attr_device_id_create_from_data(size_t length, chunk_t value);
-
-#endif /** ITA_ATTR_DEVICE_ID_H_ @}*/
index 1cb3848..86cf06d 100644 (file)
@@ -19,6 +19,7 @@
 #include <imc/imc_msg.h>
 #include <imc/imc_os_info.h>
 #include <generic/generic_attr_bool.h>
+#include <generic/generic_attr_string.h>
 #include <ietf/ietf_attr.h>
 #include <ietf/ietf_attr_attr_request.h>
 #include <ietf/ietf_attr_installed_packages.h>
@@ -29,7 +30,6 @@
 #include <ita/ita_attr.h>
 #include <ita/ita_attr_get_settings.h>
 #include <ita/ita_attr_settings.h>
-#include <ita/ita_attr_device_id.h>
 
 #include <tncif_pa_subtypes.h>
 
@@ -331,7 +331,8 @@ static void add_device_id(imc_msg_t *msg)
        }
 
        DBG1(DBG_IMC, "device ID is %.*s", value.len, value.ptr);
-       attr = ita_attr_device_id_create(value);
+       attr = generic_attr_string_create(value, pen_type_create(PEN_ITA,
+                                                                         ITA_ATTR_DEVICE_ID));
        msg->add_attribute(msg, attr);
        free(value.ptr);
 }
index 9656306..28ebd00 100644 (file)
 #include <imv/imv_msg.h>
 #include <imv/imv_session.h>
 #include <imv/imv_os_info.h>
+#include <generic/generic_attr_string.h>
 #include <ietf/ietf_attr.h>
 #include <ietf/ietf_attr_attr_request.h>
 #include <ietf/ietf_attr_pa_tnc_error.h>
 #include <ietf/ietf_attr_product_info.h>
 #include <ietf/ietf_attr_string_version.h>
 #include <ita/ita_attr.h>
-#include <ita/ita_attr_device_id.h>
 #include <tcg/tcg_attr.h>
 #include <tcg/pts/tcg_pts_attr_meas_algo.h>
 #include <tcg/pts/tcg_pts_attr_proto_caps.h>
index 41b9d0b..4bf6c7e 100644 (file)
@@ -24,6 +24,7 @@
 #include <imv/imv_agent.h>
 #include <imv/imv_msg.h>
 #include <generic/generic_attr_bool.h>
+#include <generic/generic_attr_string.h>
 #include <ietf/ietf_attr.h>
 #include <ietf/ietf_attr_attr_request.h>
 #include <ietf/ietf_attr_installed_packages.h>
@@ -36,7 +37,6 @@
 #include <ita/ita_attr.h>
 #include <ita/ita_attr_get_settings.h>
 #include <ita/ita_attr_settings.h>
-#include <ita/ita_attr_device_id.h>
 #include "tcg/seg/tcg_seg_attr_max_size.h"
 #include "tcg/seg/tcg_seg_attr_seg_env.h"
 
index bbc8e02..0301cc7 100644 (file)
@@ -83,28 +83,30 @@ pa_tnc_attr_t* pwg_attr_create_from_data(u_int32_t type, size_t length, chunk_t
                case PWG_HCD_PSTN_FAX_ENABLED:
                        return generic_attr_bool_create_from_data(length, value,
                                                                        pen_type_create(PEN_PWG, type));
-               case PWG_HCD_FIREWALL_SETTING:
-                       return ietf_attr_port_filter_create_from_data(length, value,
-                                                                       pen_type_create(PEN_PWG, type));
                case PWG_HCD_ATTRS_NATURAL_LANG:
                case PWG_HCD_MACHINE_TYPE_MODEL:
                case PWG_HCD_VENDOR_NAME:
-               case PWG_HCD_VENDOR_SMI_CODE:
-               case PWG_HCD_TIME_SOURCE:
                case PWG_HCD_FIRMWARE_NAME:
                case PWG_HCD_FIRMWARE_PATCHES:
                case PWG_HCD_FIRMWARE_STRING_VERSION:
-               case PWG_HCD_FIRMWARE_VERSION:
-               case PWG_HCD_RESIDENT_APP_NAME:
-               case PWG_HCD_RESIDENT_APP_PATCHES:
-               case PWG_HCD_RESIDENT_APP_STRING_VERSION:
-               case PWG_HCD_RESIDENT_APP_VERSION:
+               case PWG_HCD_TIME_SOURCE:
                case PWG_HCD_USER_APP_NAME:
                case PWG_HCD_USER_APP_PATCHES:
                case PWG_HCD_USER_APP_STRING_VERSION:
-               case PWG_HCD_USER_APP_VERSION:
+               case PWG_HCD_RESIDENT_APP_NAME:
+               case PWG_HCD_RESIDENT_APP_PATCHES:
+               case PWG_HCD_RESIDENT_APP_STRING_VERSION:
                case PWG_HCD_CERTIFICATION_STATE:
                case PWG_HCD_CONFIGURATION_STATE:
+                       return generic_attr_string_create_from_data(length, value,
+                                                                       pen_type_create(PEN_PWG, type));
+               case PWG_HCD_FIREWALL_SETTING:
+                       return ietf_attr_port_filter_create_from_data(length, value,
+                                                                       pen_type_create(PEN_PWG, type));
+               case PWG_HCD_VENDOR_SMI_CODE:
+               case PWG_HCD_FIRMWARE_VERSION:
+               case PWG_HCD_RESIDENT_APP_VERSION:
+               case PWG_HCD_USER_APP_VERSION:
                default:
                        return NULL;
        }