Implemented matching of Optional PCR Composite field value when Hashing was done...
[strongswan.git] / src / libpts / tcg / tcg_pts_attr_simple_evid_final.c
index fa2f6e5..c6a5af3 100644 (file)
@@ -43,7 +43,7 @@ typedef struct private_tcg_pts_attr_simple_evid_final_t private_tcg_pts_attr_sim
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 
-#define PTS_SIMPLE_EVID_FINAL_SIZE                     4
+#define PTS_SIMPLE_EVID_FINAL_SIZE                     2
 #define PTS_SIMPLE_EVID_FINAL_RESERVED         0x00
 
 /**
@@ -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
@@ -140,26 +145,32 @@ METHOD(pa_tnc_attr_t, build, void,
        u_int8_t flags = 0;
        
        writer = bio_writer_create(PTS_SIMPLE_EVID_FINAL_SIZE);
-       
+
        /* Determine the flags to set*/
-       if (this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO)
+       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)
+       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)
+       else if (this->flags == PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER)
        {
                flags += 192;
        }
-       if (this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_EVID)
+       if (this->evid_sign_included)
        {
                flags += 32;
        }
+       
        writer->write_uint8 (writer, flags);
        writer->write_uint8 (writer, PTS_SIMPLE_EVID_FINAL_RESERVED);
+       
+       /** Optional Composite Hash Algorithm field is always present
+        * Field has value of all zeroes if not used.
+        * Implemented adhering the suggestion of Paul Sangster 28.Oct.2011
+        */
        writer->write_uint16(writer, this->comp_hash_algorithm);
 
        /* Optional fields */
@@ -203,44 +214,52 @@ METHOD(pa_tnc_attr_t, process, status_t,
        /* Determine the flags to set*/
        if (!((flags >> 7) & 1) && !((flags >> 6) & 1))
        {
-               this->flags |= PTS_SIMPLE_EVID_FINAL_FLAG_NO;
+               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;
+               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;
+               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;
+               this->flags = PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO2_CAP_VER;
        }
        if ((flags >> 5) & 1)
        {
-               this->flags |= PTS_SIMPLE_EVID_FINAL_FLAG_EVID;
+               this->evid_sign_included = TRUE;
        }
        
        reader->read_uint8(reader, &reserved);
+
+       /** Optional Composite Hash Algorithm field is always present
+        * Field has value of all zeroes if not used.
+        * Implemented adhering the suggestion of Paul Sangster 28.Oct.2011
+        */
+       
        reader->read_uint16(reader, &algorithm);
        this->comp_hash_algorithm = algorithm;
        
-       /*  Optional TPM PCR Composite field is included */
-       if (!(this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_NO))
+       /*  Optional Composite Hash Algorithm and TPM PCR Composite field is included */
+       if (this->flags != PTS_SIMPLE_EVID_FINAL_FLAG_NO)
        {
-               u_int32_t pcr_comp_len;
-               u_int32_t tpm_quote_sign_len;
+               u_int32_t pcr_comp_len, tpm_quote_sign_len;
+               
                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);
+               
+               this->pcr_comp = chunk_empty;
                reader->read_uint32(reader, &tpm_quote_sign_len);
                reader->read_data(reader, tpm_quote_sign_len, &this->tpm_quote_sign);
                this->tpm_quote_sign = chunk_clone(this->tpm_quote_sign);
        }
        
        /*  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);
@@ -261,16 +280,16 @@ METHOD(pa_tnc_attr_t, destroy, void,
        free(this);
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, get_flags, pts_simple_evid_final_flag_t,
+METHOD(tcg_pts_attr_simple_evid_final_t, is_evid_sign_included, bool,
        private_tcg_pts_attr_simple_evid_final_t *this)
 {
-       return this->flags;
+       return this->evid_sign_included;
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, set_flags, void,
-       private_tcg_pts_attr_simple_evid_final_t *this, pts_simple_evid_final_flag_t flags)
+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)
 {
-       this->flags = flags;
+       return this->flags;
 }
 
 METHOD(tcg_pts_attr_simple_evid_final_t, get_comp_hash_algorithm, pts_meas_algorithms_t,
@@ -279,72 +298,29 @@ METHOD(tcg_pts_attr_simple_evid_final_t, get_comp_hash_algorithm, pts_meas_algor
        return this->comp_hash_algorithm;
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, set_comp_hash_algorithm, void,
-       private_tcg_pts_attr_simple_evid_final_t *this, pts_meas_algorithms_t comp_hash_algorithm)
-{
-       this->comp_hash_algorithm = comp_hash_algorithm;
-}
-
-METHOD(tcg_pts_attr_simple_evid_final_t, get_comp_pcr_len, u_int32_t,
-       private_tcg_pts_attr_simple_evid_final_t *this)
-{
-       if (this->pcr_comp.ptr && this->pcr_comp.len > 0)
-       {
-               return this->pcr_comp.len;
-       }
-       return 0;
-}
-
 METHOD(tcg_pts_attr_simple_evid_final_t, get_pcr_comp, chunk_t,
        private_tcg_pts_attr_simple_evid_final_t *this)
 {
        return this->pcr_comp;
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, set_pcr_comp, void,
-       private_tcg_pts_attr_simple_evid_final_t *this, chunk_t pcr_comp)
-{
-       this->pcr_comp = pcr_comp;
-}
-
-METHOD(tcg_pts_attr_simple_evid_final_t, get_tpm_quote_sign_len, u_int32_t,
-       private_tcg_pts_attr_simple_evid_final_t *this)
-{
-       if (this->tpm_quote_sign.ptr && this->tpm_quote_sign.len > 0)
-       {
-               return this->tpm_quote_sign.len;
-       }
-       return 0;
-}
-
 METHOD(tcg_pts_attr_simple_evid_final_t, get_tpm_quote_sign, chunk_t,
        private_tcg_pts_attr_simple_evid_final_t *this)
 {
        return this->tpm_quote_sign;
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, set_tpm_quote_sign, void,
-       private_tcg_pts_attr_simple_evid_final_t *this, chunk_t tpm_quote_sign)
-{
-       this->tpm_quote_sign = tpm_quote_sign;
-}
-
 METHOD(tcg_pts_attr_simple_evid_final_t, get_evid_sign, chunk_t,
        private_tcg_pts_attr_simple_evid_final_t *this)
 {
        return this->evid_sign;
 }
 
-METHOD(tcg_pts_attr_simple_evid_final_t, set_evid_sign, void,
-       private_tcg_pts_attr_simple_evid_final_t *this, chunk_t evid_sign)
-{
-       this->evid_sign = evid_sign;
-}
-
 /**
  * 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,
@@ -365,26 +341,21 @@ pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create(
                                .process = _process,
                                .destroy = _destroy,
                        },
-                       .get_flags= _get_flags,
-                       .set_flags= _set_flags,
+                       .is_evid_sign_included = _is_evid_sign_included,
+                       .get_flags = _get_flags,
                        .get_comp_hash_algorithm = _get_comp_hash_algorithm,
-                       .set_comp_hash_algorithm = _set_comp_hash_algorithm,
-                       .get_comp_pcr_len = _get_comp_pcr_len,
                        .get_pcr_comp = _get_pcr_comp,
-                       .set_pcr_comp = _set_pcr_comp,
-                       .get_tpm_quote_sign_len = _get_tpm_quote_sign_len,
                        .get_tpm_quote_sign = _get_tpm_quote_sign,
-                       .set_tpm_quote_sign = _set_tpm_quote_sign,
                        .get_evid_sign = _get_evid_sign,
-                       .set_evid_sign = _set_evid_sign,
                },
                .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;
@@ -410,18 +381,12 @@ 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,
-                       .set_flags= _set_flags,
                        .get_comp_hash_algorithm = _get_comp_hash_algorithm,
-                       .set_comp_hash_algorithm = _set_comp_hash_algorithm,
-                       .get_comp_pcr_len = _get_comp_pcr_len,
                        .get_pcr_comp = _get_pcr_comp,
-                       .set_pcr_comp = _set_pcr_comp,
-                       .get_tpm_quote_sign_len = _get_tpm_quote_sign_len,
                        .get_tpm_quote_sign = _get_tpm_quote_sign,
-                       .set_tpm_quote_sign = _set_tpm_quote_sign,
                        .get_evid_sign = _get_evid_sign,
-                       .set_evid_sign = _set_evid_sign,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_SIMPLE_EVID_FINAL,