From c567b0595f34b715c2cef883b06a9f7eafc25dc1 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Thu, 18 Aug 2011 16:54:03 +0200 Subject: [PATCH] combined request with tcg_pts_attr_proto_caps --- src/libimcv/Makefile.am | 1 - src/libimcv/pa_tnc/pa_tnc_attr.c | 5 +- .../plugins/imc_attestation/imc_attestation.c | 4 +- .../plugins/imv_attestation/imv_attestation.c | 7 +- src/libimcv/tcg/tcg_pts_attr_proto_caps.c | 82 +----- src/libimcv/tcg/tcg_pts_attr_proto_caps.h | 27 +- src/libimcv/tcg/tcg_pts_attr_req_proto_caps.c | 265 ------------------ src/libimcv/tcg/tcg_pts_attr_req_proto_caps.h | 72 ----- 8 files changed, 32 insertions(+), 431 deletions(-) delete mode 100644 src/libimcv/tcg/tcg_pts_attr_req_proto_caps.c delete mode 100644 src/libimcv/tcg/tcg_pts_attr_req_proto_caps.h diff --git a/src/libimcv/Makefile.am b/src/libimcv/Makefile.am index b9046fa47..9719a06d8 100644 --- a/src/libimcv/Makefile.am +++ b/src/libimcv/Makefile.am @@ -18,7 +18,6 @@ libimcv_la_SOURCES = \ tcg/tcg_attr.h tcg/tcg_attr.c \ tcg/tcg_pts_funct_comp_name.h \ 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 \ tcg/tcg_pts_attr_get_tpm_version_info.h tcg/tcg_pts_attr_get_tpm_version_info.c \ diff --git a/src/libimcv/pa_tnc/pa_tnc_attr.c b/src/libimcv/pa_tnc/pa_tnc_attr.c index 07a821cd4..e299c4210 100644 --- a/src/libimcv/pa_tnc/pa_tnc_attr.c +++ b/src/libimcv/pa_tnc/pa_tnc_attr.c @@ -18,7 +18,6 @@ #include "ietf/ietf_attr_pa_tnc_error.h" #include "ietf/ietf_attr_port_filter.h" #include "tcg/tcg_attr.h" -#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_get_tpm_version_info.h" @@ -68,9 +67,9 @@ pa_tnc_attr_t* pa_tnc_attr_create_create_from_data(pen_t vendor_id, u_int32_t ty switch (type) { case TCG_PTS_REQ_PROTO_CAPS: - return tcg_pts_attr_req_proto_caps_create_from_data(value); + return tcg_pts_attr_proto_caps_create_from_data(value, TRUE); case TCG_PTS_PROTO_CAPS: - return tcg_pts_attr_proto_caps_create_from_data(value); + return tcg_pts_attr_proto_caps_create_from_data(value, FALSE); case TCG_PTS_MEAS_ALGO: return tcg_pts_attr_meas_algo_create_from_data(value, FALSE); case TCG_PTS_MEAS_ALGO_SELECTION: diff --git a/src/libimcv/plugins/imc_attestation/imc_attestation.c b/src/libimcv/plugins/imc_attestation/imc_attestation.c index 3195da3d0..3747f38a8 100644 --- a/src/libimcv/plugins/imc_attestation/imc_attestation.c +++ b/src/libimcv/plugins/imc_attestation/imc_attestation.c @@ -227,8 +227,8 @@ static TNC_Result send_message(TNC_ConnectionID connection_id) case IMC_ATTESTATION_STATE_REQ_PROTO_CAP: { pts_proto_caps_flag_t flags; - flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_VER; - attr = tcg_pts_attr_proto_caps_create(flags); + flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_V; + attr = tcg_pts_attr_proto_caps_create(flags, FALSE); break; } case IMC_ATTESTATION_STATE_REQ_MEAS_ALGO: diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation.c b/src/libimcv/plugins/imv_attestation/imv_attestation.c index 45adfac47..2a375698f 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -237,9 +237,8 @@ static TNC_Result send_message(TNC_ConnectionID connection_id) pts_proto_caps_flag_t flags; /* 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); + flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_V | PTS_PROTO_CAPS_C; + attr = tcg_pts_attr_proto_caps_create(flags, TRUE); break; } case IMV_ATTESTATION_STATE_PROTO_CAP: diff --git a/src/libimcv/tcg/tcg_pts_attr_proto_caps.c b/src/libimcv/tcg/tcg_pts_attr_proto_caps.c index 631774bd9..f063b92a7 100644 --- a/src/libimcv/tcg/tcg_pts_attr_proto_caps.c +++ b/src/libimcv/tcg/tcg_pts_attr_proto_caps.c @@ -28,15 +28,14 @@ typedef struct private_tcg_pts_attr_proto_caps_t private_tcg_pts_attr_proto_caps * * 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 |C|V|D|T|X| * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * */ -#define PTS_PROTO_CAPS_SIZE 4 -#define PTS_PROTO_CAPS_RESERVED 0x00 +#define PTS_PROTO_CAPS_SIZE 4 +#define PTS_PROTO_CAPS_RESERVED 0x0000 /** * Private data of an tcg_pts_attr_proto_caps_t object. @@ -109,33 +108,10 @@ METHOD(pa_tnc_attr_t, build, void, private_tcg_pts_attr_proto_caps_t *this) { bio_writer_t *writer; - u_int8_t flags = 0; writer = bio_writer_create(PTS_PROTO_CAPS_SIZE); - writer->write_uint24 (writer, PTS_PROTO_CAPS_RESERVED); - - /* Determine the flags to set*/ - if (this->flags & PTS_PROTO_CAPS_XML) - { - flags += 1; - } - if (this->flags & PTS_PROTO_CAPS_T) - { - flags += 2; - } - if (this->flags & PTS_PROTO_CAPS_DH) - { - flags += 4; - } - if (this->flags & PTS_PROTO_CAPS_VER) - { - flags += 8; - } - if (this->flags & PTS_PROTO_CAPS_CURRENT) - { - flags += 16; - } - writer->write_uint8(writer, flags); + writer->write_uint16(writer, PTS_PROTO_CAPS_RESERVED); + writer->write_uint16(writer, this->flags); this->value = chunk_clone(writer->get_buf(writer)); writer->destroy(writer); @@ -145,8 +121,7 @@ METHOD(pa_tnc_attr_t, process, status_t, private_tcg_pts_attr_proto_caps_t *this, u_int32_t *offset) { bio_reader_t *reader; - u_int32_t reserved; - u_int8_t flags; + u_int16_t reserved, flags; if (this->value.len < PTS_PROTO_CAPS_SIZE) { @@ -155,30 +130,9 @@ METHOD(pa_tnc_attr_t, process, status_t, return FAILED; } reader = bio_reader_create(this->value); - reader->read_uint24 (reader, &reserved); - reader->read_uint8(reader, &flags); - - if ((flags >> 0) & 1) - { - this->flags |= PTS_PROTO_CAPS_XML; - } - if ((flags >> 1) & 1) - { - this->flags |= PTS_PROTO_CAPS_T; - } - if ((flags >> 2) & 1) - { - this->flags |= PTS_PROTO_CAPS_DH; - } - if ((flags >> 3) & 1) - { - this->flags |= PTS_PROTO_CAPS_VER; - } - if ((flags >> 4) & 1) - { - this->flags |= PTS_PROTO_CAPS_CURRENT; - } - + reader->read_uint16(reader, &reserved); + reader->read_uint16(reader, &flags); + this->flags = flags; reader->destroy(reader); return SUCCESS; @@ -197,17 +151,11 @@ METHOD(tcg_pts_attr_proto_caps_t, get_flags, pts_proto_caps_flag_t, return this->flags; } -METHOD(tcg_pts_attr_proto_caps_t, set_flags, void, - private_tcg_pts_attr_proto_caps_t *this, - pts_proto_caps_flag_t flags) -{ - this->flags = flags; -} - /** * Described in header. */ -pa_tnc_attr_t *tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags) +pa_tnc_attr_t *tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags, + bool request) { private_tcg_pts_attr_proto_caps_t *this; @@ -224,21 +172,20 @@ pa_tnc_attr_t *tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags) .destroy = _destroy, }, .get_flags = _get_flags, - .set_flags = _set_flags, }, .vendor_id = PEN_TCG, - .type = TCG_PTS_PROTO_CAPS, + .type = request ? TCG_PTS_REQ_PROTO_CAPS : TCG_PTS_PROTO_CAPS, .flags = flags, ); return &this->public.pa_tnc_attribute; } - /** * Described in header. */ -pa_tnc_attr_t *tcg_pts_attr_proto_caps_create_from_data(chunk_t data) +pa_tnc_attr_t *tcg_pts_attr_proto_caps_create_from_data(chunk_t data, + bool request) { private_tcg_pts_attr_proto_caps_t *this; @@ -255,10 +202,9 @@ pa_tnc_attr_t *tcg_pts_attr_proto_caps_create_from_data(chunk_t data) .destroy = _destroy, }, .get_flags = _get_flags, - .set_flags = _set_flags, }, .vendor_id = PEN_TCG, - .type = TCG_PTS_PROTO_CAPS, + .type = request ? TCG_PTS_REQ_PROTO_CAPS : TCG_PTS_PROTO_CAPS, .value = chunk_clone(data), ); diff --git a/src/libimcv/tcg/tcg_pts_attr_proto_caps.h b/src/libimcv/tcg/tcg_pts_attr_proto_caps.h index aaf2f300e..933a84495 100644 --- a/src/libimcv/tcg/tcg_pts_attr_proto_caps.h +++ b/src/libimcv/tcg/tcg_pts_attr_proto_caps.h @@ -32,20 +32,19 @@ typedef enum pts_proto_caps_flag_t pts_proto_caps_flag_t; */ enum pts_proto_caps_flag_t { /** XML based Evidence Support flag */ - PTS_PROTO_CAPS_XML = (1<<0), + PTS_PROTO_CAPS_X = (1<<0), /** Trusted Platform Evidence flag */ - PTS_PROTO_CAPS_T = (1<<1), + PTS_PROTO_CAPS_T = (1<<1), /** DH Nonce Negotiation Support flag */ - PTS_PROTO_CAPS_DH = (1<<2), + PTS_PROTO_CAPS_D = (1<<2), /** Verification Support flag */ - PTS_PROTO_CAPS_VER = (1<<3), + PTS_PROTO_CAPS_V = (1<<3), /** Current (In-Memory) Evidence Support flag */ - PTS_PROTO_CAPS_CURRENT = (1<<4), + PTS_PROTO_CAPS_C = (1<<4), }; /** * Class implementing the TCG PTS Protocol Capabilities Attribute - * */ struct tcg_pts_attr_proto_caps_t { @@ -61,28 +60,24 @@ struct tcg_pts_attr_proto_caps_t { */ pts_proto_caps_flag_t (*get_flags)(tcg_pts_attr_proto_caps_t *this); - /** - * Set PTS procol capabilities flags - * - * @param flags set of flags - */ - void (*set_flags)(tcg_pts_attr_proto_caps_t *this, - pts_proto_caps_flag_t flags); - }; /** * Creates an tcg_pts_attr_proto_caps_t object * * @param flags set of flags + * @param request TRUE for a PTS protocol capabilities request */ -pa_tnc_attr_t* tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags); +pa_tnc_attr_t* tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags, + bool request); /** * Creates an tcg_pts_attr_proto_caps_t object from received data * * @param value unparsed attribute value + * @param request TRUE for a PTS protocol capabilities request */ -pa_tnc_attr_t* tcg_pts_attr_proto_caps_create_from_data(chunk_t value); +pa_tnc_attr_t* tcg_pts_attr_proto_caps_create_from_data(chunk_t value, + bool request); #endif /** TCG_PTS_ATTR_PROTO_CAPS_H_ @}*/ diff --git a/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.c b/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.c deleted file mode 100644 index 49fb28ef2..000000000 --- a/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.c +++ /dev/null @@ -1,265 +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_req_proto_caps.h" - -#include -#include -#include -#include - -typedef struct private_tcg_pts_attr_req_proto_caps_t private_tcg_pts_attr_req_proto_caps_t; - -/** - * Request PTS Protocol Capabilities - * see section 3.6 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 |C|V|D|T|X| - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ - -#define PTS_PROTO_CAPS_SIZE 4 -#define PTS_PROTO_CAPS_RESERVED 0x00 - -/** - * Private data of an tcg_pts_attr_req_proto_caps_t object. - */ -struct private_tcg_pts_attr_req_proto_caps_t { - - /** - * Public members of tcg_pts_attr_req_proto_caps_t - */ - tcg_pts_attr_req_proto_caps_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; - - /** - * Set of flags - */ - pts_proto_caps_flag_t flags; - -}; - -METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - return this->vendor_id; -} - -METHOD(pa_tnc_attr_t, get_type, u_int32_t, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - return this->type; -} - -METHOD(pa_tnc_attr_t, get_value, chunk_t, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - return this->value; -} - -METHOD(pa_tnc_attr_t, get_noskip_flag, bool, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - return this->noskip_flag; -} - -METHOD(pa_tnc_attr_t, set_noskip_flag,void, - private_tcg_pts_attr_req_proto_caps_t *this, bool noskip) -{ - this->noskip_flag = noskip; -} - -METHOD(pa_tnc_attr_t, build, void, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - bio_writer_t *writer; - u_int8_t flags = 0; - - writer = bio_writer_create(PTS_PROTO_CAPS_SIZE); - writer->write_uint24 (writer, PTS_PROTO_CAPS_RESERVED); - - /* Determine the flags to set*/ - if (this->flags & PTS_PROTO_CAPS_XML) - { - flags += 1; - } - if (this->flags & PTS_PROTO_CAPS_T) - { - flags += 2; - } - if (this->flags & PTS_PROTO_CAPS_DH) - { - flags += 4; - } - if (this->flags & PTS_PROTO_CAPS_VER) - { - flags += 8; - } - if (this->flags & PTS_PROTO_CAPS_CURRENT) - { - flags += 16; - } - writer->write_uint8(writer, flags); - - this->value = chunk_clone(writer->get_buf(writer)); - writer->destroy(writer); -} - -METHOD(pa_tnc_attr_t, process, status_t, - private_tcg_pts_attr_req_proto_caps_t *this, u_int32_t *offset) -{ - bio_reader_t *reader; - u_int32_t reserved; - u_int8_t flags; - - if (this->value.len < PTS_PROTO_CAPS_SIZE) - { - DBG1(DBG_TNC, "insufficient data for Request PTS Protocol Capabilities"); - *offset = 0; - return FAILED; - } - reader = bio_reader_create(this->value); - reader->read_uint24 (reader, &reserved); - reader->read_uint8(reader, &flags); - - if ((flags >> 0) & 1) - { - this->flags |= PTS_PROTO_CAPS_XML; - } - if ((flags >> 1) & 1) - { - this->flags |= PTS_PROTO_CAPS_T; - } - if ((flags >> 2) & 1) - { - this->flags |= PTS_PROTO_CAPS_DH; - } - if ((flags >> 3) & 1) - { - this->flags |= PTS_PROTO_CAPS_VER; - } - if ((flags >> 4) & 1) - { - this->flags |= PTS_PROTO_CAPS_CURRENT; - } - - reader->destroy(reader); - - return SUCCESS; -} - -METHOD(pa_tnc_attr_t, destroy, void, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - free(this->value.ptr); - free(this); -} - -METHOD(tcg_pts_attr_req_proto_caps_t, get_flags, pts_proto_caps_flag_t, - private_tcg_pts_attr_req_proto_caps_t *this) -{ - return this->flags; -} - -METHOD(tcg_pts_attr_req_proto_caps_t, set_flags, void, - private_tcg_pts_attr_req_proto_caps_t *this, pts_proto_caps_flag_t flags) -{ - this->flags = flags; -} - -/** - * Described in header. - */ -pa_tnc_attr_t *tcg_pts_attr_req_proto_caps_create(pts_proto_caps_flag_t flags) -{ - private_tcg_pts_attr_req_proto_caps_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_flags = _get_flags, - .set_flags = _set_flags, - }, - .vendor_id = PEN_TCG, - .type = TCG_PTS_REQ_PROTO_CAPS, - .flags = flags, - ); - - return &this->public.pa_tnc_attribute; -} - - -/** - * Described in header. - */ -pa_tnc_attr_t *tcg_pts_attr_req_proto_caps_create_from_data(chunk_t data) -{ - private_tcg_pts_attr_req_proto_caps_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_flags = _get_flags, - .set_flags = _set_flags, - }, - .vendor_id = PEN_TCG, - .type = TCG_PTS_REQ_PROTO_CAPS, - .value = chunk_clone(data), - ); - - return &this->public.pa_tnc_attribute; -} diff --git a/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.h b/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.h deleted file mode 100644 index 6431e4770..000000000 --- a/src/libimcv/tcg/tcg_pts_attr_req_proto_caps.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_req_proto_caps tcg_pts_attr_req_proto_caps - * @{ @ingroup tcg_pts_attr_req_proto_caps - */ - -#ifndef TCG_PTS_ATTR_REQ_PROTO_CAPS_H_ -#define TCG_PTS_ATTR_REQ_PROTO_CAPS_H_ - -typedef struct tcg_pts_attr_req_proto_caps_t tcg_pts_attr_req_proto_caps_t; - -#include "tcg_attr.h" -#include "pa_tnc/pa_tnc_attr.h" -#include "tcg_pts_attr_proto_caps.h" - -/** - * Class implementing the TCG Request PTS Protocol Capabilities Attribute - * - */ -struct tcg_pts_attr_req_proto_caps_t { - - /** - * Public PA-TNC attribute interface - */ - pa_tnc_attr_t pa_tnc_attribute; - - /** - * Get PTS procol capabilities flags - * - * @return set of flags - */ - pts_proto_caps_flag_t (*get_flags)(tcg_pts_attr_req_proto_caps_t *this); - - /** - * Set PTS procol capabilities flags - * - * @param flags set of flags - */ - void (*set_flags)(tcg_pts_attr_req_proto_caps_t *this, - pts_proto_caps_flag_t flags); - -}; - -/** - * Creates an tcg_pts_attr_req_proto_caps_t object - * - * @param flags set of flags - */ -pa_tnc_attr_t* tcg_pts_attr_req_proto_caps_create(pts_proto_caps_flag_t flags); - -/** - * Creates an tcg_pts_attr_req_proto_caps_t object from received data - * - * @param value unparsed attribute value - */ -pa_tnc_attr_t* tcg_pts_attr_req_proto_caps_create_from_data(chunk_t value); - -#endif /** TCG_PTS_ATTR_REQ_PROTO_CAPS_H_ @}*/