Factored IMC/V Attestation build/process of Component Functional Name
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_comp_evid.c
index b2798d0..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.
@@ -139,26 +125,11 @@ struct private_tcg_pts_attr_simple_comp_evid_t {
         * Sub-component Depth
         */
        u_int32_t depth;
-       
-       /**
-        * Component Functional Name Vendor ID
-        */
-       u_int32_t comp_vendor_id;
-       
-       /**
-        * Functional Name Encoding Family
-        */
-       u_int8_t family;
-       
-       /**
-        * Functional Name Category Qualifier
-        */
-       pts_qualifier_t qualifier;
-       
+               
        /**
         * Component Functional Name
         */
-       pts_ita_funct_comp_name_t name;
+       pts_comp_func_name_t *name;
        
        /**
         * Measurement type
@@ -241,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);
@@ -307,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)
        {
@@ -323,51 +286,45 @@ 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;
        }
-       
-       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 );
-
-       /* 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);
-       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;
-       
-       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 */
@@ -428,25 +385,7 @@ 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, 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;
@@ -540,10 +479,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(tcg_pts_attr_simple_comp_evi
                        .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,
@@ -557,11 +493,9 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(tcg_pts_attr_simple_comp_evi
                },
                .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,
@@ -570,7 +504,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(tcg_pts_attr_simple_comp_evi
                .policy_uri = chunk_clone(params.policy_uri),
                .pcr_before = params.pcr_before,
                .pcr_after = params.pcr_after,
-               .measurement = chunk_clone(params.measurement),
+               .measurement = params.measurement,
        );
 
        return &this->public.pa_tnc_attribute;
@@ -599,10 +533,7 @@ pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create_from_data(chunk_t data)
                        .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,
@@ -616,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),
        );