diff options
author | Sansar Choinyambuu <schoinya@hsr.ch> | 2011-10-14 18:18:07 +0200 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2011-11-28 14:39:50 +0100 |
commit | 7037b55ff14a093de43ef073785b2b3df168d458 (patch) | |
tree | f8c035c3e9b7899c5d72de33b2477057017c2d1f /src/libpts/tcg | |
parent | d25b7b3d9a102339d7a6f954d10f949825f89048 (diff) | |
download | strongswan-7037b55ff14a093de43ef073785b2b3df168d458.tar.bz2 strongswan-7037b55ff14a093de43ef073785b2b3df168d458.tar.xz |
Replaced with boolean variable for PCR info included and Evidence Signature included flags
Write and Read flags to int first and set flags /Due to special definition/
Diffstat (limited to 'src/libpts/tcg')
-rw-r--r-- | src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c | 81 | ||||
-rw-r--r-- | src/libpts/tcg/tcg_pts_attr_simple_comp_evid.h | 10 | ||||
-rw-r--r-- | src/libpts/tcg/tcg_pts_attr_simple_evid_final.c | 83 | ||||
-rw-r--r-- | src/libpts/tcg/tcg_pts_attr_simple_evid_final.h | 24 |
4 files changed, 156 insertions, 42 deletions
diff --git a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c index 49ae01c64..d33f1f8ef 100644 --- a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c +++ b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c @@ -131,6 +131,11 @@ struct private_tcg_pts_attr_simple_comp_evid_t { pts_attr_simple_comp_evid_flag_t flags; /** + * PCR Information included + */ + bool pcr_info_included; + + /** * Sub-component Depth */ u_int32_t depth; @@ -236,10 +241,28 @@ METHOD(pa_tnc_attr_t, build, void, private_tcg_pts_attr_simple_comp_evid_t *this) { bio_writer_t *writer; - u_int8_t qualifier = 0; + u_int8_t flags = 0, qualifier = 0; writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE); - writer->write_uint8(writer, this->flags); + /* Determine the flags to set*/ + if (this->pcr_info_included) + { + flags += 128; + } + if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_NO_VER) + { + flags += 32; + } + else if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL) + { + flags += 64; + } + else if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS) + { + flags += 96; + } + + writer->write_uint8(writer, flags); writer->write_uint24 (writer, this->depth); writer->write_uint24 (writer, this->comp_vendor_id); @@ -315,7 +338,27 @@ METHOD(pa_tnc_attr_t, process, status_t, reader = bio_reader_create(this->value); reader->read_uint8(reader, &flags); - this->flags = flags; + /* Determine the flags to set*/ + if ((flags >> 7) & 1) + { + this->pcr_info_included = TRUE; + } + if (!((flags >> 6) & 1) && !((flags >> 5) & 1)) + { + this->flags = PTS_SIMPLE_COMP_EVID_FLAG_NO_VALID; + } + else if (!((flags >> 6) & 1) && ((flags >> 5) & 1)) + { + this->flags = PTS_SIMPLE_COMP_EVID_FLAG_NO_VER; + } + else if (((flags >> 6) & 1) && !((flags >> 5) & 1)) + { + this->flags = PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL; + } + else if (((flags >> 6) & 1) && ((flags >> 5) & 1)) + { + this->flags = PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS; + } reader->read_uint24(reader, &this->depth); reader->read_uint24(reader, &this->comp_vendor_id); @@ -330,13 +373,6 @@ METHOD(pa_tnc_attr_t, process, status_t, this->family += 2; } - /* TODO: Generate an IF-M error attribute indicating */ - /* TCG_PTS_INVALID_NAME_FAM */ - //if (&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM) - //{ - // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00"); - //} - if (((fam_and_qualifier >> 5) & 1) ) { this->qualifier.kernel = true; @@ -346,7 +382,6 @@ METHOD(pa_tnc_attr_t, process, status_t, this->qualifier.sub_component = true; } this->qualifier.type = ( fam_and_qualifier & 0xF ); - /* TODO: Check the type is defined in pts_attr_req_funct_comp_type_t */ /* Unknown or Wildcard should not be used for Qualification*/ if (!(fam_and_qualifier & 0x3F) || (fam_and_qualifier & 0x3F) == 0x3F) @@ -356,8 +391,6 @@ METHOD(pa_tnc_attr_t, process, status_t, } reader->read_uint32(reader, &this->name); - /* TODO: Check the name is defined in pts_funct_comp_name_t */ - reader->read_uint8(reader, &measurement_type); this->measurement_type = (measurement_type >> 7 ) & 1; @@ -367,15 +400,14 @@ METHOD(pa_tnc_attr_t, process, status_t, reader->read_uint8(reader, &transformation); this->transformation = transformation; - /* TODO: Check the transformation is defined in pts_pcr_transform_t */ reader->read_data(reader, PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE, &this->measurement_time); this->measurement_time = chunk_clone(this->measurement_time); - + /* Optional Policy URI field is included */ - if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL || - this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS) + if ((this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL) || + (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS)) { u_int16_t policy_uri_len; reader->read_uint16(reader, &policy_uri_len); @@ -384,7 +416,7 @@ METHOD(pa_tnc_attr_t, process, status_t, } /* Optional PCR value fields are included */ - if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR) + if (this->pcr_info_included) { u_int16_t pcr_value_len; reader->read_uint16(reader, &pcr_value_len); @@ -393,7 +425,6 @@ METHOD(pa_tnc_attr_t, process, status_t, reader->read_data(reader, pcr_value_len, &this->pcr_after); this->pcr_after = chunk_clone(this->pcr_after); } - measurement_len = reader->remaining(reader); reader->read_data(reader, measurement_len, &this->measurement); this->measurement = chunk_clone(this->measurement); @@ -414,6 +445,12 @@ METHOD(pa_tnc_attr_t, destroy, void, free(this); } +METHOD(tcg_pts_attr_simple_comp_evid_t, is_pcr_info_included, bool, + private_tcg_pts_attr_simple_comp_evid_t *this) +{ + return this->pcr_info_included; +} + METHOD(tcg_pts_attr_simple_comp_evid_t, get_flags, pts_attr_simple_comp_evid_flag_t, private_tcg_pts_attr_simple_comp_evid_t *this) { @@ -519,8 +556,7 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_measurement, chunk_t, /** * Described in header. */ -pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create( - tcg_pts_attr_simple_comp_evid_params_t params) +pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(tcg_pts_attr_simple_comp_evid_params_t params) { private_tcg_pts_attr_simple_comp_evid_t *this; @@ -536,6 +572,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create( .process = _process, .destroy = _destroy, }, + .is_pcr_info_included = _is_pcr_info_included, .get_flags= _get_flags, .get_sub_component_depth = _get_sub_component_depth, .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id, @@ -555,6 +592,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create( }, .vendor_id = PEN_TCG, .type = TCG_PTS_SIMPLE_COMP_EVID, + .pcr_info_included = params.pcr_info_included, .flags = params.flags, .depth = params.depth, .comp_vendor_id = params.vendor_id, @@ -594,6 +632,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create_from_data(chunk_t data) .process = _process, .destroy = _destroy, }, + .is_pcr_info_included = _is_pcr_info_included, .get_flags= _get_flags, .get_sub_component_depth = _get_sub_component_depth, .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id, diff --git a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.h b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.h index 70f98833d..f72429c0c 100644 --- a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.h +++ b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.h @@ -35,8 +35,6 @@ typedef struct tcg_pts_attr_simple_comp_evid_params_t tcg_pts_attr_simple_comp_e * PTS Simple Component Evidence Flags */ enum pts_attr_simple_comp_evid_flag_t { - /** PCR information fields inlcuded */ - PTS_SIMPLE_COMP_EVID_FLAG_PCR = 0, /** No Validation was attempted */ PTS_SIMPLE_COMP_EVID_FLAG_NO_VALID = 1, /** Attempted validation, unable to verify */ @@ -65,6 +63,7 @@ enum pts_pcr_transform_t { * Parameters for Simple Component Evidence Attribute */ struct tcg_pts_attr_simple_comp_evid_params_t { + bool pcr_info_included; pts_attr_simple_comp_evid_flag_t flags; u_int32_t depth; u_int32_t vendor_id; @@ -90,6 +89,13 @@ struct tcg_pts_attr_simple_comp_evid_t { * Public PA-TNC attribute interface */ pa_tnc_attr_t pa_tnc_attribute; + + /** + * Is Optional PCR Information fields included + * + * @return TRUE if included, FALSE otherwise + */ + bool (*is_pcr_info_included)(tcg_pts_attr_simple_comp_evid_t *this); /** * Get flags for PTS Simple Component Evidence diff --git a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c index 31550201f..2aa584cc7 100644 --- a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c +++ b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c @@ -75,6 +75,11 @@ struct private_tcg_pts_attr_simple_evid_final_t { * Noskip flag */ bool noskip_flag; + + /** + * Is Evidence Signature included + */ + bool evid_sign_included; /** * Set of flags for Simple Evidence Final @@ -137,9 +142,29 @@ METHOD(pa_tnc_attr_t, build, void, private_tcg_pts_attr_simple_evid_final_t *this) { bio_writer_t *writer; + u_int8_t flags = 0; writer = bio_writer_create(PTS_SIMPLE_EVID_FINAL_SIZE); - writer->write_uint8 (writer, this->flags); + + /* Determine the flags to set*/ + if (this->flags == PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO) + { + flags += 64; + } + else if (this->flags == PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2) + { + flags += 128; + } + else if (this->flags == PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER) + { + flags += 192; + } + if (this->evid_sign_included) + { + flags += 32; + } + + writer->write_uint8 (writer, flags); writer->write_uint8 (writer, PTS_SIMPLE_EVID_FINAL_RESERVED); /* Optional fields */ @@ -172,7 +197,7 @@ METHOD(pa_tnc_attr_t, process, status_t, bio_reader_t *reader; u_int8_t flags; u_int8_t reserved; - u_int16_t algorithm; + //u_int16_t algorithm; if (this->value.len < PTS_SIMPLE_EVID_FINAL_SIZE) { @@ -183,16 +208,42 @@ METHOD(pa_tnc_attr_t, process, status_t, reader = bio_reader_create(this->value); reader->read_uint8(reader, &flags); - this->flags = flags; + + /* Determine the flags to set*/ + if (!((flags >> 7) & 1) && !((flags >> 6) & 1)) + { + this->flags = PTS_SIMPLE_EVID_FINAL_FLAG_NO; + } + else if (!((flags >> 7) & 1) && ((flags >> 6) & 1)) + { + this->flags = PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO; + } + else if (((flags >> 7) & 1) && !((flags >> 6) & 1)) + { + this->flags = PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2; + } + else if (((flags >> 7) & 1) && ((flags >> 6) & 1)) + { + this->flags = PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER; + } + if ((flags >> 5) & 1) + { + this->evid_sign_included = TRUE; + } + reader->read_uint8(reader, &reserved); /* Optional Composite Hash Algorithm and TPM PCR Composite field is included */ - if ((flags >> 6) & PTS_SIMPLE_EVID_FINAL_FLAG_NO) + if (this->flags != PTS_SIMPLE_EVID_FINAL_FLAG_NO) { u_int32_t pcr_comp_len; u_int32_t tpm_quote_sign_len; - reader->read_uint16(reader, &algorithm); - this->comp_hash_algorithm = algorithm; + + /** TODO: Ignoring Hashing algorithm field + * There is no flag defined which indicates the precense of it + * reader->read_uint16(reader, &algorithm); + * this->comp_hash_algorithm = algorithm; + */ reader->read_uint32(reader, &pcr_comp_len); reader->read_data(reader, pcr_comp_len, &this->pcr_comp); this->pcr_comp = chunk_clone(this->pcr_comp); @@ -202,7 +253,7 @@ METHOD(pa_tnc_attr_t, process, status_t, } /* Optional Evidence Signature field is included */ - if (this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_EVID) + if (this->evid_sign_included) { u_int32_t evid_sign_len = reader->remaining(reader); reader->read_data(reader, evid_sign_len, &this->evid_sign); @@ -223,6 +274,12 @@ METHOD(pa_tnc_attr_t, destroy, void, free(this); } +METHOD(tcg_pts_attr_simple_evid_final_t, is_evid_sign_included, bool, + private_tcg_pts_attr_simple_evid_final_t *this) +{ + return this->evid_sign_included; +} + METHOD(tcg_pts_attr_simple_evid_final_t, get_flags, pts_simple_evid_final_flag_t, private_tcg_pts_attr_simple_evid_final_t *this) { @@ -257,6 +314,7 @@ METHOD(tcg_pts_attr_simple_evid_final_t, get_evid_sign, chunk_t, * Described in header. */ pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create( + bool evid_sign_included, pts_simple_evid_final_flag_t flags, pts_meas_algorithms_t comp_hash_algorithm, chunk_t pcr_comp, @@ -277,7 +335,8 @@ pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create( .process = _process, .destroy = _destroy, }, - .get_flags= _get_flags, + .is_evid_sign_included = _is_evid_sign_included, + .get_flags = _get_flags, .get_comp_hash_algorithm = _get_comp_hash_algorithm, .get_pcr_comp = _get_pcr_comp, .get_tpm_quote_sign = _get_tpm_quote_sign, @@ -285,11 +344,12 @@ pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create( }, .vendor_id = PEN_TCG, .type = TCG_PTS_SIMPLE_EVID_FINAL, + .evid_sign_included = evid_sign_included, .flags = flags, .comp_hash_algorithm = comp_hash_algorithm, - .pcr_comp = pcr_comp, - .tpm_quote_sign = tpm_quote_sign, - .evid_sign = evid_sign, + .pcr_comp = chunk_clone(pcr_comp), + .tpm_quote_sign = chunk_clone(tpm_quote_sign), + .evid_sign = chunk_clone(evid_sign), ); return &this->public.pa_tnc_attribute; @@ -315,6 +375,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create_from_data(chunk_t data) .process = _process, .destroy = _destroy, }, + .is_evid_sign_included = _is_evid_sign_included, .get_flags= _get_flags, .get_comp_hash_algorithm = _get_comp_hash_algorithm, .get_pcr_comp = _get_pcr_comp, diff --git a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.h b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.h index b54543837..4957cbcb8 100644 --- a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.h +++ b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.h @@ -33,18 +33,16 @@ typedef enum pts_simple_evid_final_flag_t pts_simple_evid_final_flag_t; */ enum pts_simple_evid_final_flag_t { /** No Optional TPM PCR Composite nor Optional TPM Quote Signature fields included */ - PTS_SIMPLE_EVID_FINAL_FLAG_NO = 0, + PTS_SIMPLE_EVID_FINAL_FLAG_NO = 1, /** Optional TPM PCR Composite and Optional TPM Quote Signature fields included */ /** using TPM_QUOTE_INFO */ - PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO = 1, + PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO = 2, /** Optional TPM PCR Composite and Optional TPM Quote Signature fields included */ /** using TPM_QUOTE_INFO2, TPM_CAP_VERSION_INFO was not appended */ - PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2 = 2, + PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2 = 3, /** Optional TPM PCR Composite and Optional TPM Quote Signature fields included */ /** using TPM_QUOTE_INFO2, TPM_CAP_VERSION_INFO was appended */ - PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER = 3, - /** Optional Evidence Signature included */ - PTS_SIMPLE_EVID_FINAL_FLAG_EVID = 4, + PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER = 4, }; /** @@ -57,6 +55,13 @@ struct tcg_pts_attr_simple_evid_final_t { * Public PA-TNC attribute interface */ pa_tnc_attr_t pa_tnc_attribute; + + /** + * Is Optional Evidence Signature Included + * + * @return TRUE if included, FALSE otherwise + */ + bool (*is_evid_sign_included)(tcg_pts_attr_simple_evid_final_t *this); /** * Get flags for PTS Simple Evidence Final @@ -97,14 +102,17 @@ struct tcg_pts_attr_simple_evid_final_t { /** * Creates an tcg_pts_attr_simple_evid_final_t object - * + * + * @param evid_sign_included Evidence Signature included * @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 */ -pa_tnc_attr_t* tcg_pts_attr_simple_evid_final_create(pts_simple_evid_final_flag_t flags, +pa_tnc_attr_t* tcg_pts_attr_simple_evid_final_create( + bool evid_sign_included, + pts_simple_evid_final_flag_t flags, pts_meas_algorithms_t comp_hash_algorithm, chunk_t pcr_comp, chunk_t tpm_quote_sign, |