From 3f3664ec43ec0a3bd2804b6a256494118f66f8a6 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Thu, 18 Aug 2011 12:54:38 +0200 Subject: [PATCH] moved pts_meas_algorithms_t to own header file --- src/libimcv/Makefile.am | 1 + .../plugins/imc_attestation/imc_attestation.c | 11 ++- .../plugins/imv_attestation/imv_attestation.c | 8 +- src/libimcv/tcg/tcg_pts_attr_meas_algo.c | 12 --- src/libimcv/tcg/tcg_pts_attr_meas_algo.h | 11 +-- .../tcg/tcg_pts_attr_simple_comp_evid.h | 4 +- .../tcg/tcg_pts_attr_simple_evid_final.h | 4 +- src/libimcv/tcg/tcg_pts_meas_algo.c | 77 +++++++++++++++++++ src/libimcv/tcg/tcg_pts_meas_algo.h | 57 ++++++++++++++ 9 files changed, 152 insertions(+), 33 deletions(-) create mode 100644 src/libimcv/tcg/tcg_pts_meas_algo.c create mode 100644 src/libimcv/tcg/tcg_pts_meas_algo.h diff --git a/src/libimcv/Makefile.am b/src/libimcv/Makefile.am index c29639429..e8f8e5453 100644 --- a/src/libimcv/Makefile.am +++ b/src/libimcv/Makefile.am @@ -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 \ diff --git a/src/libimcv/plugins/imc_attestation/imc_attestation.c b/src/libimcv/plugins/imc_attestation/imc_attestation.c index 339afb23a..ee2561f4d 100644 --- a/src/libimcv/plugins/imc_attestation/imc_attestation.c +++ b/src/libimcv/plugins/imc_attestation/imc_attestation.c @@ -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; } diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation.c b/src/libimcv/plugins/imv_attestation/imv_attestation.c index 9fda853b5..7b7026747 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation.c @@ -53,6 +53,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 */ @@ -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; } diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo.c b/src/libimcv/tcg/tcg_pts_attr_meas_algo.c index a0ea240d6..b12a83d96 100644 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo.c +++ b/src/libimcv/tcg/tcg_pts_attr_meas_algo.c @@ -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 diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo.h b/src/libimcv/tcg/tcg_pts_attr_meas_algo.h index 8e23a79d4..d4cc8a182 100644 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo.h +++ b/src/libimcv/tcg/tcg_pts_attr_meas_algo.h @@ -22,20 +22,11 @@ #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 * diff --git a/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h b/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h index 29f1ad00b..709c04b45 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h +++ b/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h @@ -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 */ diff --git a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h index 4537986f7..8eca1be9f 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h +++ b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h @@ -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 index 000000000..159a925e8 --- /dev/null +++ b/src/libimcv/tcg/tcg_pts_meas_algo.c @@ -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 . + * + * 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 +#include + +/** + * 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 index 000000000..824e7895d --- /dev/null +++ b/src/libimcv/tcg/tcg_pts_meas_algo.h @@ -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 . + * + * 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 + +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_ @}*/