moved pts_meas_algorithms_t to own header file
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 18 Aug 2011 10:54:38 +0000 (12:54 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Sep 2011 10:08:10 +0000 (12:08 +0200)
src/libimcv/Makefile.am
src/libimcv/plugins/imc_attestation/imc_attestation.c
src/libimcv/plugins/imv_attestation/imv_attestation.c
src/libimcv/tcg/tcg_pts_attr_meas_algo.c
src/libimcv/tcg/tcg_pts_attr_meas_algo.h
src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h
src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h
src/libimcv/tcg/tcg_pts_meas_algo.c [new file with mode: 0644]
src/libimcv/tcg/tcg_pts_meas_algo.h [new file with mode: 0644]

index c296394..e8f8e54 100644 (file)
@@ -16,6 +16,7 @@ libimcv_la_SOURCES = \
        pa_tnc/pa_tnc_msg.h pa_tnc/pa_tnc_msg.c \
        pa_tnc/pa_tnc_attr.h pa_tnc/pa_tnc_attr.c \
        tcg/tcg_attr.h tcg/tcg_attr.c \
+       tcg/tcg_pts_meas_algo.h tcg/tcg_pts_meas_algo.c \
        tcg/tcg_pts_attr_req_proto_caps.h tcg/tcg_pts_attr_req_proto_caps.c \
        tcg/tcg_pts_attr_proto_caps.h tcg/tcg_pts_attr_proto_caps.c \
        tcg/tcg_pts_attr_meas_algo.h tcg/tcg_pts_attr_meas_algo.c \
index 339afb2..ee2561f 100644 (file)
@@ -49,11 +49,13 @@ static const char imc_name[] = "Attestation";
 
 static imc_agent_t *imc_attestation;
 
+/**
+ * Supported PTS measurement algorithms
+ */
+static pts_meas_algorithms_t supported_algorithms = 0;
 
 /**
- * Selected Measurement Algorithm, which is selected during
- * the PTS Measurement Algorithm attributes exchange
- * Default value is SHA256
+ * Selected PTS measurement algorithm after attribute exchange
  */
 static pts_meas_algorithms_t selected_algorithm = PTS_MEAS_ALGO_SHA256;
 
@@ -77,7 +79,8 @@ TNC_Result TNC_IMC_Initialize(TNC_IMCID imc_id,
        }
        imc_attestation = imc_agent_create(imc_name, IMC_VENDOR_ID, IMC_SUBTYPE,
                                                                imc_id, actual_version);
-       if (!imc_attestation)
+       if (!imc_attestation ||
+               !tcg_pts_probe_meas_algorithms(&supported_algorithms))
        {
                return TNC_RESULT_FATAL;
        }
index 9fda853..7b70267 100644 (file)
@@ -54,6 +54,11 @@ static const char imv_name[] = "Attestation";
 static imv_agent_t *imv_attestation;
 
 /**
+ * Supported PTS measurement algorithms
+ */
+static pts_meas_algorithms_t supported_algorithms = 0;
+
+/**
  * List of files and directories to measure
  */
 static linked_list_t *file_list, *directory_list;
@@ -88,7 +93,8 @@ TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id,
        }
        imv_attestation = imv_agent_create(imv_name, IMV_VENDOR_ID, IMV_SUBTYPE,
                                                                imv_id, actual_version);
-       if (!imv_attestation)
+       if (!imv_attestation ||
+               !tcg_pts_probe_meas_algorithms(&supported_algorithms))
        {
                return TNC_RESULT_FATAL;
        }
index a0ea240..b12a83d 100644 (file)
@@ -34,18 +34,6 @@ typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t
  *  
  */
 
-/**
- * Diffie-Hellman Hash Algorithm Values
- * see section 3.8.5 of PTS Protocol: Binding to TNC IF-M Specification
- *
- *                       1          
- *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
- *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *  |1|2|3|R|R|R|R|R|R|R|R|R|R|R|R|R|
- *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *  
- */
-
 #define PTS_MEAS_ALGO_SIZE             4
 #define PTS_MEAS_ALGO_RESERVED 0x00
 
index 8e23a79..d4cc8a1 100644 (file)
 #define TCG_PTS_ATTR_MEAS_ALGO_H_
 
 typedef struct tcg_pts_attr_meas_algo_t tcg_pts_attr_meas_algo_t;
-typedef enum pts_meas_algorithms_t pts_meas_algorithms_t;
 
 #include "tcg_attr.h"
+#include "tcg_pts_meas_algo.h"
 #include "pa_tnc/pa_tnc_attr.h"
 
 /**
- * PTS Measurement Algorithms
- */
-enum pts_meas_algorithms_t {
-       PTS_MEAS_ALGO_SHA1 =    (1<<15),
-       PTS_MEAS_ALGO_SHA256 =  (1<<14),
-       PTS_MEAS_ALGO_SHA384 =  (1<<13),
-};
-
-/**
  * Class implementing the TCG Measurement Algorithm Attribute
  *
  */
index 29f1ad0..709c04b 100644 (file)
@@ -26,15 +26,13 @@ typedef enum pts_attr_simple_comp_evid_flag_t pts_attr_simple_comp_evid_flag_t;
 typedef enum pts_attr_simple_comp_evid_pcr_transform_t pts_attr_simple_comp_evid_pcr_transform_t;
 
 #include "tcg_attr.h"
+#include "tcg_pts_meas_algo.h"
 #include "pa_tnc/pa_tnc_attr.h"
 
 /* For Qualifier and Component Name fields, tcg_pts_qualifier_t, 
  * pts_attr_req_funct_comp_name_bin_enum_t, pts_attr_req_funct_comp_type_t */
 #include "tcg_pts_attr_req_funct_comp_evid.h" 
 
-/* For Hash Algorithm field, pts_attr_meas_algorithms_t */
-#include "tcg_pts_attr_meas_algo.h" 
-
 /**
  * PTS Simple Component Evidence Flags
  */
index 4537986..8eca1be 100644 (file)
@@ -25,11 +25,9 @@ typedef struct tcg_pts_attr_simple_evid_final_t tcg_pts_attr_simple_evid_final_t
 typedef enum pts_simple_evid_final_flag_t pts_simple_evid_final_flag_t;
 
 #include "tcg_attr.h"
+#include "tcg_pts_attr_meas_algo.h"
 #include "pa_tnc/pa_tnc_attr.h"
 
-/* For Optional Composite Hash Algorithm field, pts_attr_meas_algorithms_t*/
-#include "tcg_pts_attr_meas_algo.h" 
-
 /**
  * PTS Simple Evidence Final Flags
  */
diff --git a/src/libimcv/tcg/tcg_pts_meas_algo.c b/src/libimcv/tcg/tcg_pts_meas_algo.c
new file mode 100644 (file)
index 0000000..159a925
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 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 "tcg_pts_meas_algo.h"
+
+#include <debug.h>
+#include <crypto/hashers/hasher.h>
+
+/**
+ * Described in header.
+ */
+bool tcg_pts_probe_meas_algorithms(pts_meas_algorithms_t *algorithms)
+{
+       enumerator_t *enumerator;
+    hash_algorithm_t hash_alg;
+    const char *plugin_name;
+       char format1[] = "  %s PTS measurement algorithm %N[%s] available";
+       char format2[] = "  %s PTS measurement algorithm %N not available";
+       
+       *algorithms = 0;
+
+       enumerator = lib->crypto->create_hasher_enumerator(lib->crypto);
+       while (enumerator->enumerate(enumerator, &hash_alg, &plugin_name))
+       {
+               if (hash_alg == HASH_SHA1)
+               {
+                       *algorithms |= PTS_MEAS_ALGO_SHA1;
+                       DBG2(DBG_TNC, format1, "mandatory", hash_algorithm_names, hash_alg,
+                                                                 plugin_name);
+               }
+               else if (hash_alg == HASH_SHA256)
+               {
+                       *algorithms |= PTS_MEAS_ALGO_SHA256;
+                       DBG2(DBG_TNC, format1, "mandatory", hash_algorithm_names, hash_alg,
+                                                                 plugin_name);
+               }
+               else if (hash_alg == HASH_SHA384)
+               {
+                       *algorithms |= PTS_MEAS_ALGO_SHA384;
+                       DBG2(DBG_TNC, format1, "optional ", hash_algorithm_names, hash_alg,
+                                                                 plugin_name);
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       if (!(*algorithms & PTS_MEAS_ALGO_SHA384))
+       {       
+               DBG1(DBG_TNC, format2, "optional ", hash_algorithm_names, HASH_SHA384);
+       }
+       if ((*algorithms & PTS_MEAS_ALGO_SHA1) &&
+               (*algorithms & PTS_MEAS_ALGO_SHA256))
+       {
+               return TRUE;
+       }
+       if (!(*algorithms & PTS_MEAS_ALGO_SHA1))
+       {       
+               DBG1(DBG_TNC, format2, "mandatory", hash_algorithm_names, HASH_SHA1);
+       }
+       if (!(*algorithms & PTS_MEAS_ALGO_SHA256))
+       {       
+               DBG1(DBG_TNC, format2, "mandatory", hash_algorithm_names, HASH_SHA256);
+       }
+       return FALSE;
+}
+
diff --git a/src/libimcv/tcg/tcg_pts_meas_algo.h b/src/libimcv/tcg/tcg_pts_meas_algo.h
new file mode 100644 (file)
index 0000000..824e789
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 Sansar Choinyambuu
+ * 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 tcg_pts_meas_algo tcg_pts_meas_algo
+ * @{ @ingroup tcg_pts_meas_algo
+ */
+
+#ifndef TCG_PTS_MEAS_ALGO_H_
+#define TCG_PTS_MEAS_ALGO_H_
+
+#include <library.h>
+
+typedef enum pts_meas_algorithms_t pts_meas_algorithms_t;
+
+/**
+ * PTS Measurement Algorithms
+ */
+enum pts_meas_algorithms_t {
+       PTS_MEAS_ALGO_SHA1 =    (1<<15),
+       PTS_MEAS_ALGO_SHA256 =  (1<<14),
+       PTS_MEAS_ALGO_SHA384 =  (1<<13),
+};
+
+/**
+ * Diffie-Hellman Hash Algorithm Values
+ * see section 3.8.5 of PTS Protocol: Binding to TNC IF-M Specification
+ *
+ *                       1          
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |1|2|3|R|R|R|R|R|R|R|R|R|R|R|R|R|
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  
+ */
+
+/**
+ * Probe available PTS measurement algorithms
+ *
+ * @param algorithms   set of available algorithms
+ * @return                             TRUE if mandatory algorithms are available
+ */
+bool tcg_pts_probe_meas_algorithms(pts_meas_algorithms_t *algorithms);
+
+#endif /** TCG_PTS_MEAS_ALGO_H_ @}*/