Factored IMC/V Attestation build/process of Component Functional Name
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_comp_evid.c
index 84b3172..b48b0c3 100644 (file)
@@ -77,23 +77,9 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp
  *
  */
 
-/**
- * Qualifier for Functional Component
- * see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification
- *
- *     
- *   0 1 2 3 4 5 
- *  +-+-+-+-+-+-+
- *  |K|S| Type  |
- *  +-+-+-+-+-+-+
- */
-
-
-
 #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
 
 /**
  * Private data of an tcg_pts_attr_simple_comp_evid_t object.
@@ -131,29 +117,19 @@ struct private_tcg_pts_attr_simple_comp_evid_t {
        pts_attr_simple_comp_evid_flag_t flags;
 
        /**
-        * Sub-component Depth
+        * PCR Information included
         */
-       u_int32_t depth;
-       
-       /**
-        * Component Functional Name Vendor ID
-        */
-       u_int32_t comp_vendor_id;
-       
-       /**
-        * Functional Name Encoding Family
-        */
-       u_int8_t family;
-       
+       bool pcr_info_included;
+
        /**
-        * Functional Name Category Qualifier
+        * Sub-component Depth
         */
-       pts_qualifier_t qualifier;
-       
+       u_int32_t depth;
+               
        /**
         * Component Functional Name
         */
-       pts_funct_comp_name_t name;
+       pts_comp_func_name_t *name;
        
        /**
         * Measurement type
@@ -237,58 +213,31 @@ METHOD(pa_tnc_attr_t, build, void,
 {
        bio_writer_t *writer;
        u_int8_t flags = 0;
-       u_int8_t qualifier = 0;
        
        writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE);
-       
        /* Determine the flags to set*/
-       if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR)
+       if (this->pcr_info_included)
        {
                flags += 128;
        }
-       if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_NO_VER)
+       if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_NO_VER)
        {
                flags += 32;
        }
-       else if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL)
+       else if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL)
        {
                flags += 64;
        }
-       else if (this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS)
+       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);
-       
-       if (this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
-       {
-               DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
-       }
-       
-       qualifier += this->qualifier.type;
-       if (this->qualifier.kernel)
-       {
-               qualifier += 16;
-       }
-       if (this->qualifier.sub_component)
-       {
-               qualifier += 32;
-       }
-       
-       /* Unknown or Wildcard should not be used for Qualification*/
-       if (!qualifier || qualifier == 63)
-       {
-               DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
-                                 " Functional Name Qualifier");
-       }
-       
-       writer->write_uint8 (writer, qualifier);
-       writer->write_uint32(writer, this->name);
-       
+
+       writer->write_uint8 (writer, flags);
+       writer->write_uint24(writer, this->depth);
+       writer->write_uint24(writer, this->name->get_vendor_id(this->name));
+       writer->write_uint8 (writer, this->name->get_qualifier(this->name));
+       writer->write_uint32(writer, this->name->get_name(this->name));
        writer->write_uint8 (writer, (this->measurement_type << 7));
        writer->write_uint24(writer, this->extended_pcr);
        writer->write_uint16(writer, this->hash_algorithm);
@@ -309,8 +258,11 @@ METHOD(pa_tnc_attr_t, build, void,
                writer->write_data  (writer, this->pcr_before);
                writer->write_data  (writer, this->pcr_after);
        }
-       
-       writer->write_data (writer, this->measurement);
+
+       if (this->measurement.ptr && this->measurement.len > 0)
+       {
+               writer->write_data (writer, this->measurement);
+       }
        
        this->value = chunk_clone(writer->get_buf(writer));
        writer->destroy(writer);
@@ -320,12 +272,10 @@ METHOD(pa_tnc_attr_t, process, status_t,
        private_tcg_pts_attr_simple_comp_evid_t *this, u_int32_t *offset)
 {
        bio_reader_t *reader;
-       u_int8_t flags;
-       u_int8_t fam_and_qualifier;
-       u_int8_t measurement_type;
+       u_int8_t flags, fam_and_qualifier, qualifier;
+       u_int8_t measurement_type, transformation;
        u_int16_t algorithm;
-       u_int8_t transformation;
-       u_int32_t measurement_len;
+       u_int32_t vendor_id, name, measurement_len;
        
        if (this->value.len < PTS_SIMPLE_COMP_EVID_SIZE)
        {
@@ -336,88 +286,50 @@ METHOD(pa_tnc_attr_t, process, status_t,
        reader = bio_reader_create(this->value);
        
        reader->read_uint8(reader, &flags);
-       
        /* Determine the flags to set*/
        if ((flags >> 7) & 1)
        {
-                this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_PCR;
+                this->pcr_info_included = TRUE;
        }
        if (!((flags >> 6) & 1) && !((flags >> 5) & 1))
        {
-               this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_NO_VALID;
+               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;
+               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;
+               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;
+               this->flags = PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS;
        }
        
        reader->read_uint24(reader, &this->depth);
-       reader->read_uint24(reader, &this->comp_vendor_id);
-       reader->read_uint8(reader, &fam_and_qualifier);
-       
-       if (((fam_and_qualifier >> 6) & 1) )
-       {
-               this->family += 1;
-       }
-       if (((fam_and_qualifier >> 7) & 1) )
-       {
-               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;
-       }
-       if (((fam_and_qualifier >> 4) & 1) )
-       {
-               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 */
+       reader->read_uint24(reader, &vendor_id);
+       reader->read_uint8 (reader, &fam_and_qualifier);
+       reader->read_uint32(reader, &name);
+       reader->read_uint8 (reader, &measurement_type);
+       reader->read_uint24(reader, &this->extended_pcr);
+       reader->read_uint16(reader, &algorithm);
+       reader->read_uint8 (reader, &transformation);
+       reader->read_data  (reader, PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE,
+                                                               &this->measurement_time);
 
-       /* Unknown or Wildcard should not be used for Qualification*/
-       if (!(fam_and_qualifier & 0x3F) || (fam_and_qualifier & 0x3F) == 0x3F)
-       {
-               DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
-                                 " Functional Name Qualifier");
-       }
-       
-       reader->read_uint32(reader, &this->name);
-       /* TODO: Check the name is defined in pts_funct_comp_name_t */
+       qualifier = fam_and_qualifier & (!PTS_SIMPLE_COMP_EVID_FAMILY_MASK);
        
-       reader->read_uint8(reader, &measurement_type);
+       this->name = pts_comp_func_name_create(vendor_id, name, qualifier);
        this->measurement_type = (measurement_type >> 7 ) & 1;
-       
-       reader->read_uint24(reader, &this->extended_pcr);
-       reader->read_uint16(reader, &algorithm);
        this->hash_algorithm = algorithm;
-       
-       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);
@@ -426,7 +338,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);
@@ -435,7 +347,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);
@@ -456,16 +367,16 @@ METHOD(pa_tnc_attr_t, destroy, void,
        free(this);
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_flags, pts_attr_simple_comp_evid_flag_t,
+METHOD(tcg_pts_attr_simple_comp_evid_t, is_pcr_info_included, bool,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
-       return this->flags;
+       return this->pcr_info_included;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_flags, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_simple_comp_evid_flag_t flags)
+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)
 {
-       this->flags = flags;
+       return this->flags;
 }
 
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
@@ -474,43 +385,12 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
        return this->depth;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_spec_comp_funct_name_vendor_id, u_int32_t,
-       private_tcg_pts_attr_simple_comp_evid_t *this)
-{
-       return this->comp_vendor_id;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_family, u_int8_t,
-       private_tcg_pts_attr_simple_comp_evid_t *this)
-{
-       return this->family;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_qualifier, pts_qualifier_t,
-       private_tcg_pts_attr_simple_comp_evid_t *this)
-{
-       return this->qualifier;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_qualifier, void,
-               private_tcg_pts_attr_simple_comp_evid_t *this,
-               pts_qualifier_t qualifier)
-{
-       this->qualifier = qualifier;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_funct_name, pts_funct_comp_name_t,
+METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_func_name, pts_comp_func_name_t*,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->name;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_funct_name, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_funct_comp_name_t name)
-{
-       this->name = name;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_type, u_int8_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
@@ -523,85 +403,42 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_extended_pcr, u_int32_t,
        return this->extended_pcr;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_extended_pcr, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, u_int32_t extended_pcr)
-{
-       this->extended_pcr = extended_pcr;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_hash_algorithm, pts_meas_algorithms_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->hash_algorithm;
 }
 
-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)
-{
-       this->hash_algorithm = hash_algorithm;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_trans, pts_pcr_transform_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->transformation;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_trans, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, pts_pcr_transform_t transformation)
-{
-       this->transformation = transformation;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_time, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->measurement_time;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_measurement_time, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement_time)
-{
-       this->measurement_time = measurement_time;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_policy_uri, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->policy_uri;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_policy_uri, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t policy_uri)
-{
-       this->policy_uri = policy_uri;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_before_value, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->pcr_before;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_before_value, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_before)
-{
-       this->pcr_before = pcr_before;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_after_value, chunk_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
        return this->pcr_after;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_after_value, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_after)
-{
-       this->pcr_after = pcr_after;
-}
-
 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_len, u_int16_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
@@ -620,30 +457,13 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_measurement, chunk_t,
        return this->measurement;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_measurement, void,
-       private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement)
-{
-       this->measurement = measurement;
-}
-
 /**
  * Described in header.
  */
-pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
-                                                                       pts_attr_simple_comp_evid_flag_t flags,
-                                                                       u_int32_t depth, u_int32_t vendor_id,
-                                                                       pts_qualifier_t qualifier,
-                                                                       pts_funct_comp_name_t name,
-                                                                       u_int32_t extended_pcr,
-                                                                       pts_meas_algorithms_t hash_algorithm,
-                                                                       pts_pcr_transform_t transformation,
-                                                                       chunk_t measurement_time,
-                                                                       chunk_t policy_uri,
-                                                                       chunk_t pcr_before, chunk_t pcr_after,
-                                                                       chunk_t measurement)
+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;
-
+       
        INIT(this,
                .public = {
                        .pa_tnc_attribute = {
@@ -656,50 +476,35 @@ 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,
-                       .set_flags= _set_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
-                       .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
-                       .get_family = _get_family,
-                       .get_qualifier = _get_qualifier,
-                       .set_qualifier = _set_qualifier,
-                       .get_comp_funct_name = _get_comp_funct_name,
-                       .set_comp_funct_name = _set_comp_funct_name,
+                       .get_comp_func_name = _get_comp_func_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
-                       .set_extended_pcr = _set_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
-                       .set_hash_algorithm = _set_hash_algorithm,
                        .get_pcr_trans = _get_pcr_trans,
-                       .set_pcr_trans = _set_pcr_trans,
                        .get_measurement_time = _get_measurement_time,
-                       .set_measurement_time = _set_measurement_time,
                        .get_policy_uri = _get_policy_uri,
-                       .set_policy_uri = _set_policy_uri,
                        .get_pcr_before_value = _get_pcr_before_value,
-                       .set_pcr_before_value = _set_pcr_before_value,
                        .get_pcr_after_value = _get_pcr_after_value,
-                       .set_pcr_after_value = _set_pcr_after_value,
                        .get_pcr_len = _get_pcr_len,
                        .get_comp_measurement = _get_comp_measurement,
-                       .set_comp_measurement = _set_comp_measurement,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_COMP_EVID,
-               .flags = flags,
-               .depth = depth,
-               .comp_vendor_id = vendor_id,
-               .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
-               .qualifier = qualifier,
-               .name = name,
-               .extended_pcr = extended_pcr,
-               .hash_algorithm = hash_algorithm,
-               .transformation = transformation,
-               .measurement_time = measurement_time,
-               .policy_uri = policy_uri,
-               .pcr_before = pcr_before,
-               .pcr_after = pcr_after,
-               .measurement = measurement,
+               .pcr_info_included = params.pcr_info_included,
+               .flags = params.flags,
+               .depth = params.depth,
+               .name = params.name,
+               .extended_pcr = params.extended_pcr,
+               .hash_algorithm = params.hash_algorithm,
+               .transformation = params.transformation,
+               .measurement_time = params.measurement_time,
+               .policy_uri = chunk_clone(params.policy_uri),
+               .pcr_before = params.pcr_before,
+               .pcr_after = params.pcr_after,
+               .measurement = params.measurement,
        );
 
        return &this->public.pa_tnc_attribute;
@@ -725,33 +530,20 @@ 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,
-                       .set_flags= _set_flags,
                        .get_sub_component_depth = _get_sub_component_depth,
-                       .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
-                       .get_family = _get_family,
-                       .get_qualifier = _get_qualifier,
-                       .set_qualifier = _set_qualifier,
-                       .get_comp_funct_name = _get_comp_funct_name,
-                       .set_comp_funct_name = _set_comp_funct_name,
+                       .get_comp_func_name = _get_comp_func_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
-                       .set_extended_pcr = _set_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
-                       .set_hash_algorithm = _set_hash_algorithm,
                        .get_pcr_trans = _get_pcr_trans,
-                       .set_pcr_trans = _set_pcr_trans,
                        .get_measurement_time = _get_measurement_time,
-                       .set_measurement_time = _set_measurement_time,
                        .get_policy_uri = _get_policy_uri,
-                       .set_policy_uri = _set_policy_uri,
                        .get_pcr_before_value = _get_pcr_before_value,
-                       .set_pcr_before_value = _set_pcr_before_value,
                        .get_pcr_after_value = _get_pcr_after_value,
-                       .set_pcr_after_value = _set_pcr_after_value,
                        .get_pcr_len = _get_pcr_len,
                        .get_comp_measurement = _get_comp_measurement,
-                       .set_comp_measurement = _set_comp_measurement,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_COMP_EVID,