diff --git a/src/libimcv/Makefile.am b/src/libimcv/Makefile.am index 503b1d63d..c29639429 100644 --- a/src/libimcv/Makefile.am +++ b/src/libimcv/Makefile.am @@ -19,7 +19,6 @@ libimcv_la_SOURCES = \ 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 \ - tcg/tcg_pts_attr_meas_algo_selection.h tcg/tcg_pts_attr_meas_algo_selection.c \ tcg/tcg_pts_attr_get_tpm_version_info.h tcg/tcg_pts_attr_get_tpm_version_info.c \ tcg/tcg_pts_attr_tpm_version_info.h tcg/tcg_pts_attr_tpm_version_info.c \ tcg/tcg_pts_attr_get_aik.h tcg/tcg_pts_attr_get_aik.c \ diff --git a/src/libimcv/pa_tnc/pa_tnc_attr.c b/src/libimcv/pa_tnc/pa_tnc_attr.c index 6f410a6cd..07a821cd4 100644 --- a/src/libimcv/pa_tnc/pa_tnc_attr.c +++ b/src/libimcv/pa_tnc/pa_tnc_attr.c @@ -21,7 +21,6 @@ #include "tcg/tcg_pts_attr_req_proto_caps.h" #include "tcg/tcg_pts_attr_proto_caps.h" #include "tcg/tcg_pts_attr_meas_algo.h" -#include "tcg/tcg_pts_attr_meas_algo_selection.h" #include "tcg/tcg_pts_attr_get_tpm_version_info.h" #include "tcg/tcg_pts_attr_tpm_version_info.h" #include "tcg/tcg_pts_attr_get_aik.h" @@ -73,9 +72,9 @@ pa_tnc_attr_t* pa_tnc_attr_create_create_from_data(pen_t vendor_id, u_int32_t ty case TCG_PTS_PROTO_CAPS: return tcg_pts_attr_proto_caps_create_from_data(value); case TCG_PTS_MEAS_ALGO: - return tcg_pts_attr_meas_algo_create_from_data(value); + return tcg_pts_attr_meas_algo_create_from_data(value, FALSE); case TCG_PTS_MEAS_ALGO_SELECTION: - return tcg_pts_attr_meas_algo_selection_create_from_data(value); + return tcg_pts_attr_meas_algo_create_from_data(value, TRUE); case TCG_PTS_GET_TPM_VERSION_INFO: return tcg_pts_attr_get_tpm_version_info_create_from_data(value); case TCG_PTS_TPM_VERSION_INFO: diff --git a/src/libimcv/plugins/imc_attestation/imc_attestation.c b/src/libimcv/plugins/imc_attestation/imc_attestation.c index 5ac87da44..339afb23a 100644 --- a/src/libimcv/plugins/imc_attestation/imc_attestation.c +++ b/src/libimcv/plugins/imc_attestation/imc_attestation.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -43,9 +43,9 @@ static const char imc_name[] = "Attestation"; -#define IMC_VENDOR_ID PEN_TCG -#define IMC_SUBTYPE PA_SUBTYPE_TCG_PTS -#define IMC_ATTESTATION_MAX_FILE_SIZE 32768 +#define IMC_VENDOR_ID PEN_TCG +#define IMC_SUBTYPE PA_SUBTYPE_TCG_PTS +#define IMC_ATTESTATION_MAX_FILE_SIZE 32768 static imc_agent_t *imc_attestation; @@ -266,7 +266,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id) algorithm = PTS_MEAS_ALGO_SHA1; /* Save the selected algorithm for further attributes creation */ selected_algorithm = algorithm; - attr = tcg_pts_attr_meas_algo_selection_create(algorithm); + attr = tcg_pts_attr_meas_algo_create(algorithm, TRUE); break; } case IMC_ATTESTATION_STATE_GET_TPM_INFO: diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation.c b/src/libimcv/plugins/imv_attestation/imv_attestation.c index e60626d44..9fda853b5 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation.c @@ -203,18 +203,22 @@ static TNC_Result send_message(TNC_ConnectionID connection_id) { case IMV_ATTESTATION_STATE_INIT: { - /* Send Request Protocol Capabilities attribute */ pts_proto_caps_flag_t flags; - flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_VER | PTS_PROTO_CAPS_CURRENT; + + /* Send Request Protocol Capabilities attribute */ + flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_VER | + PTS_PROTO_CAPS_CURRENT; attr = tcg_pts_attr_req_proto_caps_create(flags); break; } case IMV_ATTESTATION_STATE_PROTO_CAP: { - /* Send Measurement Algorithms attribute */ pts_meas_algorithms_t algorithms; - algorithms = PTS_MEAS_ALGO_SHA1 | PTS_MEAS_ALGO_SHA256 | PTS_MEAS_ALGO_SHA384; - attr = tcg_pts_attr_meas_algo_create(algorithms); + + /* Send Measurement Algorithms attribute */ + algorithms = PTS_MEAS_ALGO_SHA1 | PTS_MEAS_ALGO_SHA256 | + PTS_MEAS_ALGO_SHA384; + attr = tcg_pts_attr_meas_algo_create(algorithms, FALSE); break; } case IMV_ATTESTATION_STATE_MEAS_ALGO: diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo.c b/src/libimcv/tcg/tcg_pts_attr_meas_algo.c index 5a391c924..a0ea240d6 100644 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo.c +++ b/src/libimcv/tcg/tcg_pts_attr_meas_algo.c @@ -28,7 +28,6 @@ typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Reserved | Hash Algorithm Set | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -41,7 +40,6 @@ typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t * * 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| * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -49,7 +47,7 @@ typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t */ #define PTS_MEAS_ALGO_SIZE 4 -#define PTS_MEAS_ALGO_RESERVED 0x00 +#define PTS_MEAS_ALGO_RESERVED 0x00 /** * Private data of an tcg_pts_attr_meas_algo_t object. @@ -122,26 +120,10 @@ METHOD(pa_tnc_attr_t, build, void, private_tcg_pts_attr_meas_algo_t *this) { bio_writer_t *writer; - u_int16_t algorithms = 0; writer = bio_writer_create(PTS_MEAS_ALGO_SIZE); writer->write_uint16 (writer, PTS_MEAS_ALGO_RESERVED); - - /* Determine the hash algorithms to set*/ - if (this->algorithms & PTS_MEAS_ALGO_SHA384) - { - algorithms += 8192; - } - if (this->algorithms & PTS_MEAS_ALGO_SHA256) - { - algorithms += 16384; - } - if (this->algorithms & PTS_MEAS_ALGO_SHA1) - { - algorithms += 32768; - } - writer->write_uint16(writer, algorithms); - + writer->write_uint16(writer, this->algorithms); this->value = chunk_clone(writer->get_buf(writer)); writer->destroy(writer); } @@ -150,8 +132,7 @@ METHOD(pa_tnc_attr_t, process, status_t, private_tcg_pts_attr_meas_algo_t *this, u_int32_t *offset) { bio_reader_t *reader; - u_int16_t reserved; - u_int16_t algorithms; + u_int16_t reserved, algorithms; if (this->value.len < PTS_MEAS_ALGO_SIZE) { @@ -162,20 +143,7 @@ METHOD(pa_tnc_attr_t, process, status_t, reader = bio_reader_create(this->value); reader->read_uint16 (reader, &reserved); reader->read_uint16(reader, &algorithms); - - if ((algorithms >> 13) & 1) - { - this->algorithms |= PTS_MEAS_ALGO_SHA384; - } - if ((algorithms >> 14) & 1) - { - this->algorithms |= PTS_MEAS_ALGO_SHA256; - } - if ((algorithms >> 15) & 1) - { - this->algorithms |= PTS_MEAS_ALGO_SHA1; - } - + this->algorithms = algorithms; reader->destroy(reader); return SUCCESS; @@ -204,7 +172,8 @@ METHOD(tcg_pts_attr_meas_algo_t, set_algorithms, void, /** * Described in header. */ -pa_tnc_attr_t *tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms) +pa_tnc_attr_t *tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms, + bool selection) { private_tcg_pts_attr_meas_algo_t *this; @@ -224,7 +193,7 @@ pa_tnc_attr_t *tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms) .set_algorithms = _set_algorithms, }, .vendor_id = PEN_TCG, - .type = TCG_PTS_MEAS_ALGO, + .type = selection ? TCG_PTS_MEAS_ALGO_SELECTION : TCG_PTS_MEAS_ALGO, .algorithms = algorithms, ); @@ -235,7 +204,8 @@ pa_tnc_attr_t *tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms) /** * Described in header. */ -pa_tnc_attr_t *tcg_pts_attr_meas_algo_create_from_data(chunk_t data) +pa_tnc_attr_t *tcg_pts_attr_meas_algo_create_from_data(chunk_t data, + bool selection) { private_tcg_pts_attr_meas_algo_t *this; @@ -255,7 +225,7 @@ pa_tnc_attr_t *tcg_pts_attr_meas_algo_create_from_data(chunk_t data) .set_algorithms = _set_algorithms, }, .vendor_id = PEN_TCG, - .type = TCG_PTS_MEAS_ALGO, + .type = selection ? TCG_PTS_MEAS_ALGO_SELECTION : TCG_PTS_MEAS_ALGO, .value = chunk_clone(data), ); diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo.h b/src/libimcv/tcg/tcg_pts_attr_meas_algo.h index 03c4b21b2..8e23a79d4 100644 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo.h +++ b/src/libimcv/tcg/tcg_pts_attr_meas_algo.h @@ -31,12 +31,9 @@ typedef enum pts_meas_algorithms_t pts_meas_algorithms_t; * PTS Measurement Algorithms */ enum pts_meas_algorithms_t { - /** SHA-384 */ - PTS_MEAS_ALGO_SHA1 = (1<<0), - /** SHA-256 */ - PTS_MEAS_ALGO_SHA256 = (1<<1), - /** SHA-1 */ - PTS_MEAS_ALGO_SHA384 = (1<<2), + PTS_MEAS_ALGO_SHA1 = (1<<15), + PTS_MEAS_ALGO_SHA256 = (1<<14), + PTS_MEAS_ALGO_SHA384 = (1<<13), }; /** @@ -60,7 +57,7 @@ struct tcg_pts_attr_meas_algo_t { /** * Set PTS Measurement Algorithm Set * - * @param flags set of algorithms + * @param flags set of algorithms */ void (*set_algorithms)(tcg_pts_attr_meas_algo_t *this, pts_meas_algorithms_t algorithms); @@ -70,15 +67,19 @@ struct tcg_pts_attr_meas_algo_t { /** * Creates an tcg_pts_attr_meas_algo_t object * - * @param algorithms set of algorithms + * @param algorithms set of algorithms + * @param selection TRUE if a selection */ -pa_tnc_attr_t* tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms); +pa_tnc_attr_t* tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms, + bool selection); /** * Creates an tcg_pts_attr_meas_algo_t object from received data * * @param value unparsed attribute value + * @param selection TRUE if a selection */ -pa_tnc_attr_t* tcg_pts_attr_meas_algo_create_from_data(chunk_t value); +pa_tnc_attr_t* tcg_pts_attr_meas_algo_create_from_data(chunk_t value, + bool selection); #endif /** TCG_PTS_ATTR_MEAS_ALGO_H_ @}*/ diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.c b/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.c deleted file mode 100644 index d7985dcff..000000000 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * 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. - */ - -#include "tcg_pts_attr_meas_algo_selection.h" - -#include -#include -#include -#include - -typedef struct private_tcg_pts_attr_meas_algo_selection_t private_tcg_pts_attr_meas_algo_selection_t; - -/** - * PTS Measurement Algorithm Selection - * see section 3.9.2 of PTS Protocol: Binding to TNC IF-M Specification - * - * 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Reserved | Hash Algorithm Set | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ - -/** - * 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_SEL_SIZE 4 -#define PTS_MEAS_ALGO_SEL_RESERVED 0x00 - -/** - * Private data of an tcg_pts_attr_meas_algo_selection_t object. - */ -struct private_tcg_pts_attr_meas_algo_selection_t { - - /** - * Public members of tcg_pts_attr_meas_algo_selection_t - */ - tcg_pts_attr_meas_algo_selection_t public; - - /** - * Attribute vendor ID - */ - pen_t vendor_id; - - /** - * Attribute type - */ - u_int32_t type; - - /** - * Attribute value - */ - chunk_t value; - - /** - * Noskip flag - */ - bool noskip_flag; - - /** - * A Selected Measurement Algorithm - */ - pts_meas_algorithms_t algorithm; - -}; - -METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - return this->vendor_id; -} - -METHOD(pa_tnc_attr_t, get_type, u_int32_t, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - return this->type; -} - -METHOD(pa_tnc_attr_t, get_value, chunk_t, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - return this->value; -} - -METHOD(pa_tnc_attr_t, get_noskip_flag, bool, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - return this->noskip_flag; -} - -METHOD(pa_tnc_attr_t, set_noskip_flag,void, - private_tcg_pts_attr_meas_algo_selection_t *this, bool noskip) -{ - this->noskip_flag = noskip; -} - -METHOD(pa_tnc_attr_t, build, void, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - bio_writer_t *writer; - u_int16_t algorithm = 0; - - writer = bio_writer_create(PTS_MEAS_ALGO_SEL_SIZE); - writer->write_uint16 (writer, PTS_MEAS_ALGO_SEL_RESERVED); - - /* Determine the hash algorithm to set*/ - if (this->algorithm & PTS_MEAS_ALGO_SHA384) - { - algorithm = 8192; - } - else if (this->algorithm & PTS_MEAS_ALGO_SHA256) - { - algorithm = 16384; - } - else if (this->algorithm & PTS_MEAS_ALGO_SHA1) - { - algorithm = 32768; - } - writer->write_uint16(writer, algorithm); - - this->value = chunk_clone(writer->get_buf(writer)); - writer->destroy(writer); -} - -METHOD(pa_tnc_attr_t, process, status_t, - private_tcg_pts_attr_meas_algo_selection_t *this, u_int32_t *offset) -{ - bio_reader_t *reader; - u_int16_t reserved; - u_int16_t algorithm; - - if (this->value.len < PTS_MEAS_ALGO_SEL_SIZE) - { - DBG1(DBG_TNC, "insufficient data for PTS Measurement Algorithm Selection"); - *offset = 0; - return FAILED; - } - reader = bio_reader_create(this->value); - reader->read_uint16 (reader, &reserved); - reader->read_uint16(reader, &algorithm); - - if ((algorithm >> 13) & 1) - { - this->algorithm = PTS_MEAS_ALGO_SHA384; - } - else if ((algorithm >> 14) & 1) - { - this->algorithm = PTS_MEAS_ALGO_SHA256; - } - else if ((algorithm >> 15) & 1) - { - this->algorithm = PTS_MEAS_ALGO_SHA1; - } - - reader->destroy(reader); - - return SUCCESS; -} - -METHOD(pa_tnc_attr_t, destroy, void, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - free(this->value.ptr); - free(this); -} - -METHOD(tcg_pts_attr_meas_algo_selection_t, get_algorithm, pts_meas_algorithms_t, - private_tcg_pts_attr_meas_algo_selection_t *this) -{ - return this->algorithm; -} - -METHOD(tcg_pts_attr_meas_algo_selection_t, set_algorithm, void, - private_tcg_pts_attr_meas_algo_selection_t *this, - pts_meas_algorithms_t algorithm) -{ - this->algorithm = algorithm; -} - -/** - * Described in header. - */ -pa_tnc_attr_t *tcg_pts_attr_meas_algo_selection_create(pts_meas_algorithms_t algorithm) -{ - private_tcg_pts_attr_meas_algo_selection_t *this; - - INIT(this, - .public = { - .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, - .get_type = _get_type, - .get_value = _get_value, - .get_noskip_flag = _get_noskip_flag, - .set_noskip_flag = _set_noskip_flag, - .build = _build, - .process = _process, - .destroy = _destroy, - }, - .get_algorithm = _get_algorithm, - .set_algorithm = _set_algorithm, - }, - .vendor_id = PEN_TCG, - .type = TCG_PTS_MEAS_ALGO_SELECTION, - .algorithm = algorithm, - ); - - return &this->public.pa_tnc_attribute; -} - - -/** - * Described in header. - */ -pa_tnc_attr_t *tcg_pts_attr_meas_algo_selection_create_from_data(chunk_t data) -{ - private_tcg_pts_attr_meas_algo_selection_t *this; - - INIT(this, - .public = { - .pa_tnc_attribute = { - .get_vendor_id = _get_vendor_id, - .get_type = _get_type, - .get_value = _get_value, - .get_noskip_flag = _get_noskip_flag, - .set_noskip_flag = _set_noskip_flag, - .build = _build, - .process = _process, - .destroy = _destroy, - }, - .get_algorithm = _get_algorithm, - .set_algorithm = _set_algorithm, - }, - .vendor_id = PEN_TCG, - .type = TCG_PTS_MEAS_ALGO_SELECTION, - .value = chunk_clone(data), - ); - - return &this->public.pa_tnc_attribute; -} diff --git a/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.h b/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.h deleted file mode 100644 index 0f03de3c5..000000000 --- a/src/libimcv/tcg/tcg_pts_attr_meas_algo_selection.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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_attr_meas_algo_selection tcg_pts_attr_meas_algo_selection - * @{ @ingroup tcg_pts_attr_meas_algo_selection - */ - -#ifndef TCG_PTS_ATTR_MEAS_ALGO_SELECTION_H_ -#define TCG_PTS_ATTR_MEAS_ALGO_SELECTION_H_ - -typedef struct tcg_pts_attr_meas_algo_selection_t tcg_pts_attr_meas_algo_selection_t; - -#include "tcg_attr.h" -#include "pa_tnc/pa_tnc_attr.h" -#include "tcg_pts_attr_meas_algo.h" - -/** - * Class implementing the TCG Measurement Algorithm Selection Attribute - * - */ -struct tcg_pts_attr_meas_algo_selection_t { - - /** - * Public PA-TNC attribute interface - */ - pa_tnc_attr_t pa_tnc_attribute; - - /** - * Get a selected PTS Measurement Algorithm - * - * @return A Selected Measurement Algorithm - */ - pts_meas_algorithms_t (*get_algorithm)(tcg_pts_attr_meas_algo_selection_t *this); - - /** - * Set PTS Measurement Algorithm - * - * @param flags A Selected Measurement Algorithm - */ - void (*set_algorithm)(tcg_pts_attr_meas_algo_selection_t *this, - pts_meas_algorithms_t algorithm); - -}; - -/** - * Creates an tcg_pts_attr_meas_algo_selection_t object - * - * @param algorithm A Selected Measurement Algorithm - */ -pa_tnc_attr_t* tcg_pts_attr_meas_algo_selection_create(pts_meas_algorithms_t algorithm); - -/** - * Creates an tcg_pts_attr_meas_algo_selection_t object from received data - * - * @param value unparsed attribute value - */ -pa_tnc_attr_t* tcg_pts_attr_meas_algo_selection_create_from_data(chunk_t value); - -#endif /** TCG_PTS_ATTR_MEAS_ALGO_H_ @}*/ diff --git a/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.c b/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.c index a8b628ae1..2d1938ea2 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.c +++ b/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.c @@ -28,39 +28,38 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Flags | Sub-Component Depth | + * | Flags | Sub-Component Depth | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Specific Functional Component | + * | Specific Functional Component | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Specific Functional Component | + * | Specific Functional Component | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measure. Type | Extended into PCR | + * | Measure. Type | Extended into PCR | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Hash Algorithm | PCR Transform | Reserved | + * | Hash Algorithm | PCR Transform | Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measurement Date/Time | + * | Measurement Date/Time | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measurement Date/Time | + * | Measurement Date/Time | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measurement Date/Time | + * | Measurement Date/Time | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measurement Date/Time | + * | Measurement Date/Time | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Measurement Date/Time | + * | Measurement Date/Time | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Optional Policy URI Length | Opt. Verification Policy URI ~ + * | Optional Policy URI Length | Opt. Verification Policy URI ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional Verification Policy URI ~ + * ~ Optional Verification Policy URI ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Optional PCR Length | Optional PCR Before Value ~ + * | Optional PCR Length | Optional PCR Before Value ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional PCR Before Value (Variable Length) ~ + * ~ Optional PCR Before Value (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional PCR After Value (Variable Length) ~ + * ~ Optional PCR After Value (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Component Measurement (Variable Length) ~ + * ~ Component Measurement (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ @@ -70,7 +69,6 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Component Functional Name Vendor ID |Fam| Qualifier | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -84,7 +82,7 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp * see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification * * - * 0 1 2 3 4 5 + * 0 1 2 3 4 5 * +-+-+-+-+-+-+ * |K|S| Type | * +-+-+-+-+-+-+ @@ -92,10 +90,10 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp -#define PTS_SIMPLE_COMP_EVID_SIZE 40 +#define PTS_SIMPLE_COMP_EVID_SIZE 40 #define PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE 20 -#define PTS_SIMPLE_COMP_EVID_RESERVED 0x00 -#define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00 +#define PTS_SIMPLE_COMP_EVID_RESERVED 0x00 +#define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00 /** * Private data of an tcg_pts_attr_simple_comp_evid_t object. @@ -240,7 +238,6 @@ METHOD(pa_tnc_attr_t, build, void, bio_writer_t *writer; u_int8_t flags = 0; u_int8_t qualifier = 0; - u_int16_t algorithm = 0; writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE); @@ -294,22 +291,7 @@ METHOD(pa_tnc_attr_t, build, void, writer->write_uint8 (writer, (this->measurement_type << 7)); writer->write_uint24 (writer, this->extended_pcr); - - /* Determine the hash algorithm to set*/ - if (this->hash_algorithm & PTS_MEAS_ALGO_SHA384) - { - algorithm = 8192; - } - else if (this->hash_algorithm & PTS_MEAS_ALGO_SHA256) - { - algorithm = 16384; - } - else if (this->hash_algorithm & PTS_MEAS_ALGO_SHA1) - { - algorithm = 32768; - } - writer->write_uint16(writer, algorithm); - + writer->write_uint16(writer, this->hash_algorithm); writer->write_uint8 (writer, this->transformation); writer->write_data (writer, this->measurement_time); @@ -423,19 +405,7 @@ METHOD(pa_tnc_attr_t, process, status_t, reader->read_uint24(reader, &this->extended_pcr); reader->read_uint16(reader, &algorithm); - - if ((algorithm >> 13) & 1) - { - this->hash_algorithm = PTS_MEAS_ALGO_SHA384; - } - else if ((algorithm >> 14) & 1) - { - this->hash_algorithm = PTS_MEAS_ALGO_SHA256; - } - else if ((algorithm >> 15) & 1) - { - this->hash_algorithm = PTS_MEAS_ALGO_SHA1; - } + this->hash_algorithm = algorithm; reader->read_uint8(reader, &transformation); this->transformation = transformation; @@ -561,7 +531,8 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_hash_algorithm, pts_meas_algorithms_ } METHOD(tcg_pts_attr_simple_comp_evid_t, set_hash_algorithm, void, - private_tcg_pts_attr_simple_comp_evid_t *this, pts_meas_algorithms_t hash_algorithm) + private_tcg_pts_attr_simple_comp_evid_t *this, + pts_meas_algorithms_t hash_algorithm) { this->hash_algorithm = hash_algorithm; } 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 db6695bf3..29f1ad00b 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h +++ b/src/libimcv/tcg/tcg_pts_attr_simple_comp_evid.h @@ -27,11 +27,13 @@ typedef enum pts_attr_simple_comp_evid_pcr_transform_t pts_attr_simple_comp_evid #include "tcg_attr.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_selection.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.c b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c index 1dbdfa4cb..f37576e93 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c +++ b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c @@ -28,24 +28,23 @@ typedef struct private_tcg_pts_attr_simple_evid_final_t private_tcg_pts_attr_sim * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Flags | Reserved | Optional Composite Hash Alg | + * | Flags | Reserved | Optional Composite Hash Alg | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Optional TPM PCR Composite Length | + * | Optional TPM PCR Composite Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional TPM PCR Composite (Variable Length) ~ + * ~ Optional TPM PCR Composite (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Optional TPM Quote Signature Length | + * | Optional TPM Quote Signature Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional TPM Quote Signature (Variable Length) ~ + * ~ Optional TPM Quote Signature (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Optional Evidence Signature (Variable Length) ~ + * ~ Optional Evidence Signature (Variable Length) ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ #define PTS_SIMPLE_EVID_FINAL_SIZE 4 -#define PTS_SIMPLE_EVID_FINAL_RESERVED 0x00 +#define PTS_SIMPLE_EVID_FINAL_RESERVED 0x00 /** * Private data of an tcg_pts_attr_simple_evid_final_t object. @@ -139,7 +138,6 @@ METHOD(pa_tnc_attr_t, build, void, { bio_writer_t *writer; u_int8_t flags = 0; - u_int16_t algorithm = 0; writer = bio_writer_create(PTS_SIMPLE_EVID_FINAL_SIZE); @@ -160,23 +158,9 @@ METHOD(pa_tnc_attr_t, build, void, { flags += 32; } - writer->write_uint8(writer, flags); - writer->write_uint8(writer, PTS_SIMPLE_EVID_FINAL_RESERVED); - - /* Determine the hash algorithm to set*/ - if (this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA384) - { - algorithm = 8192; - } - else if (this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA256) - { - algorithm = 16384; - } - else if (this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA1) - { - algorithm = 32768; - } - writer->write_uint16(writer, algorithm); + writer->write_uint8 (writer, flags); + writer->write_uint8 (writer, PTS_SIMPLE_EVID_FINAL_RESERVED); + writer->write_uint16(writer, this->comp_hash_algorithm); /* Optional fields */ if (this->pcr_comp.ptr && this->pcr_comp.len > 0) @@ -240,19 +224,7 @@ METHOD(pa_tnc_attr_t, process, status_t, reader->read_uint8(reader, &reserved); reader->read_uint16(reader, &algorithm); - - if ((algorithm >> 13) & 1) - { - this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA384; - } - else if ((algorithm >> 14) & 1) - { - this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA256; - } - else if ((algorithm >> 15) & 1) - { - this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA1; - } + this->comp_hash_algorithm = algorithm; /* Optional TPM PCR Composite field is included */ if (!(this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_NO)) 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 f768b0203..4537986f7 100644 --- a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h +++ b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h @@ -26,8 +26,9 @@ typedef enum pts_simple_evid_final_flag_t pts_simple_evid_final_flag_t; #include "tcg_attr.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_selection.h" +#include "tcg_pts_attr_meas_algo.h" /** * PTS Simple Evidence Final Flags @@ -109,7 +110,7 @@ struct tcg_pts_attr_simple_evid_final_t { * @param pcr_comp PCR Composite */ void (*set_pcr_comp)(tcg_pts_attr_simple_evid_final_t *this, - chunk_t pcr_comp); + chunk_t pcr_comp); /** * Get Optional TPM Quote Signature Length @@ -131,7 +132,7 @@ struct tcg_pts_attr_simple_evid_final_t { * @param tpm_quote_sign TPM Quote Signature */ void (*set_tpm_quote_sign)(tcg_pts_attr_simple_evid_final_t *this, - chunk_t tpm_quote_sign); + chunk_t tpm_quote_sign); /** * Get Optional Evidence Signature @@ -146,24 +147,24 @@ struct tcg_pts_attr_simple_evid_final_t { * @param signature Optional Evidence Signature */ void (*set_evid_sign)(tcg_pts_attr_simple_evid_final_t *this, - chunk_t signature); + chunk_t signature); }; /** * Creates an tcg_pts_attr_simple_evid_final_t object * - * @param flags Set of flags - * @param comp_hash_algorithm Composite Hash Algorithm - * @param pcr_comp Optional TPM PCR Composite + * @param flags Set of flags + * @param comp_hash_algorithm Composite Hash Algorithm + * @param pcr_comp Optional TPM PCR Composite * @param tpm_quote_sign Optional TPM Quote Signature - * @param evid_sign Optional Evidence Signature + * @param evid_sign Optional Evidence Signature */ pa_tnc_attr_t* tcg_pts_attr_simple_evid_final_create(pts_simple_evid_final_flag_t flags, - pts_meas_algorithms_t comp_hash_algorithm, - chunk_t pcr_comp, - chunk_t tpm_quote_sign, - chunk_t evid_sign); + pts_meas_algorithms_t comp_hash_algorithm, + chunk_t pcr_comp, + chunk_t tpm_quote_sign, + chunk_t evid_sign); /** * Creates an tcg_pts_attr_simple_evid_final_t object from received data