Factored IMC/V Attestation build/process of Component Functional Name
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_comp_evid.c
index 493a227..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
-        */
-       u_int32_t depth;
-       
-       /**
-        * Component Functional Name Vendor ID
-        */
-       u_int32_t comp_vendor_id;
-       
-       /**
-        * Functional Name Encoding Family
+        * PCR Information included
         */
-       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
@@ -236,38 +212,32 @@ 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;
        
        writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE);
-       writer->write_uint8(writer, this->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)
+       /* Determine the flags to set*/
+       if (this->pcr_info_included)
        {
-               DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
+               flags += 128;
        }
-       
-       qualifier += this->qualifier.type;
-       if (this->qualifier.kernel)
+       if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_NO_VER)
        {
-               qualifier += 16;
+               flags += 32;
        }
-       if (this->qualifier.sub_component)
+       else if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL)
        {
-               qualifier += 32;
+               flags += 64;
        }
-       
-       /* Unknown or Wildcard should not be used for Qualification*/
-       if (!qualifier || qualifier == 63)
+       else if (this->flags == PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS)
        {
-               DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
-                                 " Functional Name Qualifier");
+               flags += 96;
        }
-       
-       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);
@@ -288,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);
@@ -299,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)
        {
@@ -315,67 +286,50 @@ METHOD(pa_tnc_attr_t, process, status_t,
        reader = bio_reader_create(this->value);
        
        reader->read_uint8(reader, &flags);
-       this->flags = flags;
-       
-       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) )
+       /* Determine the flags to set*/
+       if ((flags >> 7) & 1)
        {
-               this->family += 1;
+                this->pcr_info_included = TRUE;
        }
-       if (((fam_and_qualifier >> 7) & 1) )
+       if (!((flags >> 6) & 1) && !((flags >> 5) & 1))
        {
-               this->family += 2;
+               this->flags = PTS_SIMPLE_COMP_EVID_FLAG_NO_VALID;
        }
-       
-       /* 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) )
+       else if (!((flags >> 6) & 1) && ((flags >> 5) & 1))
        {
-               this->qualifier.kernel = true;
+               this->flags = PTS_SIMPLE_COMP_EVID_FLAG_NO_VER;
        }
-       if (((fam_and_qualifier >> 4) & 1) )
+       else if (((flags >> 6) & 1) && !((flags >> 5) & 1))
        {
-               this->qualifier.sub_component = true;
+               this->flags = PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL;
        }
-       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)
+       else if (((flags >> 6) & 1) && ((flags >> 5) & 1))
        {
-               DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
-                                 " Functional Name Qualifier");
+               this->flags = PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS;
        }
        
-       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;
-       
+       reader->read_uint24(reader, &this->depth);
+       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);
-       this->hash_algorithm = algorithm;
+       reader->read_uint8 (reader, &transformation);
+       reader->read_data  (reader, PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE,
+                                                               &this->measurement_time);
+
+       qualifier = fam_and_qualifier & (!PTS_SIMPLE_COMP_EVID_FAMILY_MASK);
        
-       reader->read_uint8(reader, &transformation);
+       this->name = pts_comp_func_name_create(vendor_id, name, qualifier);
+       this->measurement_type = (measurement_type >> 7 ) & 1;
+       this->hash_algorithm = algorithm;
        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 +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);
@@ -393,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);
@@ -414,37 +367,25 @@ 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,
-       private_tcg_pts_attr_simple_comp_evid_t *this)
-{
-       return this->flags;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
-       private_tcg_pts_attr_simple_comp_evid_t *this)
-{
-       return this->depth;
-}
-
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_spec_comp_funct_name_vendor_id, u_int32_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->comp_vendor_id;
+       return this->pcr_info_included;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_family, u_int8_t,
+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)
 {
-       return this->family;
+       return this->flags;
 }
 
-METHOD(tcg_pts_attr_simple_comp_evid_t, get_qualifier, pts_qualifier_t,
+METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
        private_tcg_pts_attr_simple_comp_evid_t *this)
 {
-       return this->qualifier;
+       return this->depth;
 }
 
-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;
@@ -519,8 +460,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,12 +476,10 @@ 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,
-                       .get_family = _get_family,
-                       .get_qualifier = _get_qualifier,
-                       .get_comp_funct_name = _get_comp_funct_name,
+                       .get_comp_func_name = _get_comp_func_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
@@ -555,20 +493,18 @@ 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,
-               .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
-               .qualifier = params.qualifier,
                .name = params.name,
                .extended_pcr = params.extended_pcr,
                .hash_algorithm = params.hash_algorithm,
                .transformation = params.transformation,
-               .measurement_time = chunk_clone(params.measurement_time),
+               .measurement_time = params.measurement_time,
                .policy_uri = chunk_clone(params.policy_uri),
-               .pcr_before = chunk_clone(params.pcr_before),
-               .pcr_after = chunk_clone(params.pcr_after),
-               .measurement = chunk_clone(params.measurement),
+               .pcr_before = params.pcr_before,
+               .pcr_after = params.pcr_after,
+               .measurement = params.measurement,
        );
 
        return &this->public.pa_tnc_attribute;
@@ -594,12 +530,10 @@ 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,
-                       .get_family = _get_family,
-                       .get_qualifier = _get_qualifier,
-                       .get_comp_funct_name = _get_comp_funct_name,
+                       .get_comp_func_name = _get_comp_func_name,
                        .get_measurement_type = _get_measurement_type,
                        .get_extended_pcr = _get_extended_pcr,
                        .get_hash_algorithm = _get_hash_algorithm,
@@ -613,7 +547,6 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create_from_data(chunk_t data)
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_COMP_EVID,
-               .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
                .value = chunk_clone(data),
        );