Implemented TCG PTS Simple Evidence Final and Request File Measurement attributes
authorSansar Choinyambuu <schoinya@hsr.ch>
Fri, 12 Aug 2011 08:56:02 +0000 (10:56 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Sep 2011 10:08:10 +0000 (12:08 +0200)
src/libimcv/tcg/tcg_pts_attr_req_file_meas.c [new file with mode: 0644]
src/libimcv/tcg/tcg_pts_attr_req_file_meas.h [new file with mode: 0644]
src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c [new file with mode: 0644]
src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h [new file with mode: 0644]

diff --git a/src/libimcv/tcg/tcg_pts_attr_req_file_meas.c b/src/libimcv/tcg/tcg_pts_attr_req_file_meas.c
new file mode 100644 (file)
index 0000000..0b83200
--- /dev/null
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2011 Sansar Choinyambuu
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "tcg_pts_attr_req_file_meas.h"
+
+#include <pa_tnc/pa_tnc_msg.h>
+#include <bio/bio_writer.h>
+#include <bio/bio_reader.h>
+#include <debug.h>
+
+typedef struct private_tcg_pts_attr_req_file_meas_t private_tcg_pts_attr_req_file_meas_t;
+
+/**
+ * Request File Measurement (see section 3.19.1 of PTS Protocol: Binding to TNC IF-M Specification)
+ * 
+ *                       1                   2                   3
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |   Flags     |    Reserved    |           Request ID          |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |                          Delimiter                           |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  ~          Fully Qualified File Path Name (Variable Length)    ~
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+#define PTS_REQ_FILE_MEAS_SIZE                 8
+#define PTS_REQ_FILE_MEAS_RESERVED             0x00
+
+/**
+ * Private data of an tcg_pts_attr_req_file_meas_t object.
+ */
+struct private_tcg_pts_attr_req_file_meas_t {
+
+       /**
+        * Public members of tcg_pts_attr_req_file_meas_t
+        */
+       tcg_pts_attr_req_file_meas_t public;
+
+       /**
+        * Attribute vendor ID
+        */
+       pen_t vendor_id;
+
+       /**
+        * Attribute type
+        */
+       u_int32_t type;
+
+       /**
+        * Attribute value
+        */
+       chunk_t value;
+       
+       /**
+        * Noskip flag
+        */
+       bool noskip_flag;
+       
+       /**
+        * Directory Contents flag
+        */
+       bool directory_flag;
+
+       /**
+        * Request ID
+        */
+       u_int16_t request_id;
+       
+       /**
+        * UTF8 Encoding of Delimiter Character
+        */
+       u_int32_t delimiter;
+               
+       /**
+        * Fully Qualified File Path Name
+        */
+       chunk_t path;
+
+};
+
+METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->vendor_id;
+}
+
+METHOD(pa_tnc_attr_t, get_type, u_int32_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->type;
+}
+
+METHOD(pa_tnc_attr_t, get_value, chunk_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->value;
+}
+
+METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->noskip_flag;
+}
+
+METHOD(pa_tnc_attr_t, set_noskip_flag,void,
+       private_tcg_pts_attr_req_file_meas_t *this, bool noskip)
+{
+       this->noskip_flag = noskip;
+}
+
+METHOD(pa_tnc_attr_t, build, void,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       bio_writer_t *writer;
+       u_int8_t flags = 0;
+       
+       writer = bio_writer_create(PTS_REQ_FILE_MEAS_SIZE);
+       
+       if(this->directory_flag) flags += 128;
+       writer->write_uint8(writer, flags);
+       writer->write_uint8(writer, PTS_REQ_FILE_MEAS_RESERVED);
+       writer->write_uint16(writer, this->request_id);
+       writer->write_uint32(writer, this->delimiter);
+       writer->write_data (writer, this->path);
+
+       this->value = chunk_clone(writer->get_buf(writer));
+       writer->destroy(writer);
+}
+
+METHOD(pa_tnc_attr_t, process, status_t,
+       private_tcg_pts_attr_req_file_meas_t *this, u_int32_t *offset)
+{
+       bio_reader_t *reader;
+       u_int8_t flags;
+       u_int8_t reserved;
+       u_int32_t file_path_len;
+       
+       if (this->value.len < PTS_REQ_FILE_MEAS_SIZE)
+       {
+               DBG1(DBG_TNC, "insufficient data for Request File Measurement");
+               *offset = 0;
+               return FAILED;
+       }
+       reader = bio_reader_create(this->value);
+       
+       reader->read_uint8(reader, &flags);
+       if((flags >> 7) & 1) this->directory_flag = true;
+       
+       reader->read_uint8(reader, &reserved);
+       reader->read_uint16(reader, &this->request_id);
+       reader->read_uint32(reader, &this->delimiter);
+       file_path_len = reader->remaining(reader);
+       reader->read_data(reader, file_path_len, &this->path);
+
+       reader->destroy(reader);
+       return SUCCESS; 
+}
+
+METHOD(pa_tnc_attr_t, destroy, void,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       free(this->value.ptr);
+       free(this->path.ptr);
+       free(this);
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, get_directory_flag, bool,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->directory_flag;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, set_directory_flag, void,
+       private_tcg_pts_attr_req_file_meas_t *this, bool directory_flag)
+{
+       this->directory_flag = directory_flag;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, get_request_id, u_int16_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->request_id;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, set_request_id, void,
+       private_tcg_pts_attr_req_file_meas_t *this, u_int16_t request_id)
+{
+       this->request_id = request_id;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, get_delimiter, u_int32_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->delimiter;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, set_delimiter, void,
+       private_tcg_pts_attr_req_file_meas_t *this, u_int32_t delimiter)
+{
+       this->delimiter = delimiter;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, get_file_path, chunk_t,
+       private_tcg_pts_attr_req_file_meas_t *this)
+{
+       return this->path;
+}
+
+METHOD(tcg_pts_attr_req_file_meas_t, set_file_path, void,
+       private_tcg_pts_attr_req_file_meas_t *this, chunk_t path)
+{
+       this->path = path;
+}
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create(
+                                      bool directory_flag,
+                                      u_int16_t request_id,
+                                      u_int32_t delimiter,
+                                      chunk_t path)
+{
+       private_tcg_pts_attr_req_file_meas_t *this;
+
+       INIT(this,
+               .public = {
+                       .pa_tnc_attribute = {
+                               .get_vendor_id = _get_vendor_id,
+                               .get_type = _get_type,
+                               .get_value = _get_value,
+                               .get_noskip_flag = _get_noskip_flag,
+                               .set_noskip_flag = _set_noskip_flag,
+                               .build = _build,
+                               .process = _process,
+                               .destroy = _destroy,
+                       },
+                       .get_directory_flag= _get_directory_flag,
+                       .set_directory_flag= _set_directory_flag,
+                       .get_request_id = _get_request_id,
+                       .set_request_id = _set_request_id,
+                       .get_delimiter = _get_delimiter,
+                       .set_delimiter = _set_delimiter,
+                       .get_file_path = _get_file_path,
+                       .set_file_path = _set_file_path,
+               },
+               .vendor_id = PEN_TCG,
+               .type = TCG_PTS_REQ_FILE_MEAS,
+               .directory_flag = directory_flag,
+               .request_id = request_id,
+               .delimiter = delimiter,
+               .path = path,
+       );
+
+       return &this->public.pa_tnc_attribute;
+}
+
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create_from_data(chunk_t data)
+{
+       private_tcg_pts_attr_req_file_meas_t *this;
+
+       INIT(this,
+               .public = {
+                       .pa_tnc_attribute = {
+                               .get_vendor_id = _get_vendor_id,
+                               .get_type = _get_type,
+                               .get_value = _get_value,
+                               .get_noskip_flag = _get_noskip_flag,
+                               .set_noskip_flag = _set_noskip_flag,
+                               .build = _build,
+                               .process = _process,
+                               .destroy = _destroy,
+                       },
+                       .get_directory_flag= _get_directory_flag,
+                       .set_directory_flag= _set_directory_flag,
+                       .get_request_id = _get_request_id,
+                       .set_request_id = _set_request_id,
+                       .get_delimiter = _get_delimiter,
+                       .set_delimiter = _set_delimiter,
+                       .get_file_path = _get_file_path,
+                       .set_file_path = _set_file_path,
+               },
+               .vendor_id = PEN_TCG,
+               .type = TCG_PTS_REQ_FILE_MEAS,
+               .value = chunk_clone(data),
+       );
+
+       return &this->public.pa_tnc_attribute;
+}
diff --git a/src/libimcv/tcg/tcg_pts_attr_req_file_meas.h b/src/libimcv/tcg/tcg_pts_attr_req_file_meas.h
new file mode 100644 (file)
index 0000000..171ae57
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2011 Sansar Choinyambuu
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup tcg_pts_attr_req_file_meas tcg_pts_attr_req_file_meas
+ * @{ @ingroup tcg_pts_attr_req_file_meas
+ */
+
+#ifndef TCG_PTS_ATTR_REQ_FILE_MEAS_H_
+#define TCG_PTS_ATTR_REQ_FILE_MEAS_H_
+
+typedef struct tcg_pts_attr_req_file_meas_t tcg_pts_attr_req_file_meas_t;
+
+#include "tcg_attr.h"
+#include "pa_tnc/pa_tnc_attr.h"
+
+/**
+ * Class implementing the TCG PTS Request File Measurement attribute
+ *
+ */
+struct tcg_pts_attr_req_file_meas_t {
+
+       /**
+        * Public PA-TNC attribute interface
+        */
+       pa_tnc_attr_t pa_tnc_attribute;
+       
+       /**
+        * Get flag for PTS Request File Measurement
+        *
+        * @return                              Directory Contents flag
+        */
+       bool (*get_directory_flag)(tcg_pts_attr_req_file_meas_t *this);
+
+       /**
+        * Set flag for PTS Request File Measurement
+        *
+        * @param directory_flag                Directory Contents flag
+        */
+       void (*set_directory_flag)(tcg_pts_attr_req_file_meas_t *this, 
+                               bool directory_flag);
+       
+       /**
+        * Get Request ID
+        *
+        * @return                              Request ID
+        */
+       u_int16_t (*get_request_id)(tcg_pts_attr_req_file_meas_t *this);
+       
+       /**
+        * Set Request ID
+        *
+        * @param request_id                    Request ID
+        */
+       void (*set_request_id)(tcg_pts_attr_req_file_meas_t *this,
+                                               u_int16_t hash_algorithm);
+               
+       /**
+        * Get Delimiter
+        *
+        * @return                              UTF-8 encoding of a Delimiter Character
+        */
+       u_int32_t (*get_delimiter)(tcg_pts_attr_req_file_meas_t *this);
+       
+       /**
+        * Set Delimiter 
+        *
+        * @param delimiter                     UTF-8 encoding of a Delimiter Character
+        */
+       void (*set_delimiter)(tcg_pts_attr_req_file_meas_t *this,
+                                               u_int32_t delimiter);
+
+       /**
+        * Get Fully Qualified File Path Name
+        *
+        * @return                              File Path
+        */
+       chunk_t (*get_file_path)(tcg_pts_attr_req_file_meas_t *this);
+               
+       /**
+        * Set Fully Qualified File Path Name
+        *
+        * @param path                          File Path
+        */
+       void (*set_file_path)(tcg_pts_attr_req_file_meas_t *this,
+                                               chunk_t path);
+       
+};
+
+/**
+ * Creates an tcg_pts_attr_req_file_meas_t object
+ * 
+ * @param directory_flag               Directory Contents Flag
+ * @param request_id                   Request ID
+ * @param delimiter                    Delimiter Character
+ * @param path                         File Path
+ */
+pa_tnc_attr_t* tcg_pts_attr_req_file_meas_create(bool directory_flag,
+                                      u_int16_t request_id,
+                                      u_int32_t delimiter,
+                                      chunk_t path);
+
+/**
+ * Creates an tcg_pts_attr_req_file_meas_t object from received data
+ *
+ * @param value                                unparsed attribute value
+ */
+pa_tnc_attr_t* tcg_pts_attr_req_file_meas_create_from_data(chunk_t value);
+
+#endif /** TCG_PTS_ATTR_REQ_FILE_MEAS_H_ @}*/
diff --git a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.c
new file mode 100644 (file)
index 0000000..95d4c13
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ * Copyright (C) 2011 Sansar Choinyambuu
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "tcg_pts_attr_simple_evid_final.h"
+
+#include <pa_tnc/pa_tnc_msg.h>
+#include <bio/bio_writer.h>
+#include <bio/bio_reader.h>
+#include <debug.h>
+
+typedef struct private_tcg_pts_attr_simple_evid_final_t private_tcg_pts_attr_simple_evid_final_t;
+
+/**
+ * Simple Evidence Final (see section 3.15.2 of PTS Protocol: Binding to TNC IF-M Specification)
+ * 
+ *                       1                   2                   3
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |   Flags     |    Reserved    |  Optional Composite Hash Alg  |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |                  Optional TPM PCR Composite Length           |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  ~          Optional TPM PCR Composite (Variable Length)        ~
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |                  Optional TPM Quote Signature Length         |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  ~          Optional TPM Quote Signature (Variable Length)      ~
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  ~          Optional Evidence Signature (Variable Length)       ~
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+#define PTS_SIMPLE_EVID_FINAL_SIZE                     4
+#define PTS_SIMPLE_EVID_FINAL_RESERVED                 0x00
+
+/**
+ * Private data of an tcg_pts_attr_simple_evid_final_t object.
+ */
+struct private_tcg_pts_attr_simple_evid_final_t {
+
+       /**
+        * Public members of tcg_pts_attr_simple_evid_final_t
+        */
+       tcg_pts_attr_simple_evid_final_t public;
+
+       /**
+        * Attribute vendor ID
+        */
+       pen_t vendor_id;
+
+       /**
+        * Attribute type
+        */
+       u_int32_t type;
+
+       /**
+        * Attribute value
+        */
+       chunk_t value;
+       
+       /**
+        * Noskip flag
+        */
+       bool noskip_flag;
+       
+       /**
+        * Set of flags for Simple Evidence Final
+        */
+       pts_attr_simple_evid_final_flag_t flags;
+
+       /**
+        * Optional Composite Hash Algorithm
+        */
+       pts_attr_meas_algorithms_t comp_hash_algorithm;
+       
+       /**
+        * Optional TPM PCR Composite
+        */
+       chunk_t pcr_comp;
+       
+       /**
+        * Optional TPM Quote Signature
+        */
+       chunk_t tpm_quote_sign;
+       
+       /**
+        * Optional Evidence Signature
+        */
+       chunk_t evid_sign;
+
+};
+
+METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       return this->vendor_id;
+}
+
+METHOD(pa_tnc_attr_t, get_type, u_int32_t,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       return this->type;
+}
+
+METHOD(pa_tnc_attr_t, get_value, chunk_t,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       return this->value;
+}
+
+METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       return this->noskip_flag;
+}
+
+METHOD(pa_tnc_attr_t, set_noskip_flag,void,
+       private_tcg_pts_attr_simple_evid_final_t *this, bool noskip)
+{
+       this->noskip_flag = noskip;
+}
+
+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;
+       u_int16_t algorithm = 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) 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->flags & PTS_SIMPLE_EVID_FINAL_FLAG_EVID) flags += 32;
+       
+       writer->write_uint8(writer, flags);
+       writer->write_uint8(writer, PTS_SIMPLE_EVID_FINAL_RESERVED);
+       
+       /* Determine the hash algorithm to set*/
+       if(this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA384) algorithm = 8192;
+       else if(this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA256) algorithm = 16384;
+       else if(this->comp_hash_algorithm & PTS_MEAS_ALGO_SHA1) algorithm = 32768;
+       writer->write_uint16(writer, algorithm);
+
+       /* Optional fields */
+       if(this->pcr_comp.ptr && this->pcr_comp.len > 0) 
+       {
+               writer->write_uint32 (writer, this->pcr_comp.len);
+               writer->write_data (writer, this->pcr_comp);
+       }
+       if(this->tpm_quote_sign.ptr && this->tpm_quote_sign.len > 0)
+       {
+               writer->write_uint32 (writer, this->tpm_quote_sign.len);
+               writer->write_data (writer, this->tpm_quote_sign);
+       }
+       if(this->evid_sign.ptr && this->evid_sign.len > 0)
+       {
+               writer->write_data (writer, this->evid_sign);
+       }
+       
+       this->value = chunk_clone(writer->get_buf(writer));
+       writer->destroy(writer);
+}
+
+METHOD(pa_tnc_attr_t, process, status_t,
+       private_tcg_pts_attr_simple_evid_final_t *this, u_int32_t *offset)
+{
+       bio_reader_t *reader;
+       u_int8_t flags;
+       u_int8_t reserved;
+       u_int16_t algorithm;
+       
+       if (this->value.len < PTS_SIMPLE_EVID_FINAL_SIZE)
+       {
+               DBG1(DBG_TNC, "insufficient data for Simple Evidence Final");
+               *offset = 0;
+               return FAILED;
+       }
+       reader = bio_reader_create(this->value);
+       
+       reader->read_uint8(reader, &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->flags |= PTS_SIMPLE_EVID_FINAL_FLAG_EVID;
+       
+       reader->read_uint8(reader, &reserved);
+       reader->read_uint16(reader, &algorithm);
+       
+       if((algorithm >> 13) & 1) this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA384;
+       else if((algorithm >> 14) & 1) this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA256;
+       else if((algorithm >> 15) & 1) this->comp_hash_algorithm = PTS_MEAS_ALGO_SHA1;
+               
+       /*  Optional 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;
+               reader->read_uint32(reader, &pcr_comp_len);
+               reader->read_data(reader, pcr_comp_len, &this->pcr_comp);
+               reader->read_uint32(reader, &tpm_quote_sign_len);
+               reader->read_data(reader, tpm_quote_sign_len, &this->tpm_quote_sign);
+       }
+       
+       /*  Optional Evidence Signature field is included */
+       if(this->flags & PTS_SIMPLE_EVID_FINAL_FLAG_EVID)
+       {
+               u_int32_t evid_sign_len = reader->remaining(reader);
+               reader->read_data(reader, evid_sign_len, &this->evid_sign);
+       }
+       
+       reader->destroy(reader);
+       return SUCCESS; 
+}
+
+METHOD(pa_tnc_attr_t, destroy, void,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       free(this->value.ptr);
+       free(this->pcr_comp.ptr);
+       free(this->tpm_quote_sign.ptr);
+       free(this->evid_sign.ptr);
+       free(this);
+}
+
+METHOD(tcg_pts_attr_simple_evid_final_t, get_flags, pts_attr_simple_evid_final_flag_t,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       return this->flags;
+}
+
+METHOD(tcg_pts_attr_simple_evid_final_t, set_flags, void,
+       private_tcg_pts_attr_simple_evid_final_t *this, pts_attr_simple_evid_final_flag_t flags)
+{
+       this->flags = flags;
+}
+
+METHOD(tcg_pts_attr_simple_evid_final_t, get_comp_hash_algorithm, pts_attr_meas_algorithms_t,
+       private_tcg_pts_attr_simple_evid_final_t *this)
+{
+       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_attr_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;
+       else 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;
+       else 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(
+                                      pts_attr_simple_evid_final_flag_t flags,
+                                      pts_attr_meas_algorithms_t comp_hash_algorithm,
+                                      chunk_t pcr_comp,
+                                      chunk_t tpm_quote_sign,
+                                      chunk_t evid_sign)
+{
+       private_tcg_pts_attr_simple_evid_final_t *this;
+
+       INIT(this,
+               .public = {
+                       .pa_tnc_attribute = {
+                               .get_vendor_id = _get_vendor_id,
+                               .get_type = _get_type,
+                               .get_value = _get_value,
+                               .get_noskip_flag = _get_noskip_flag,
+                               .set_noskip_flag = _set_noskip_flag,
+                               .build = _build,
+                               .process = _process,
+                               .destroy = _destroy,
+                       },
+                       .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,
+               .flags = flags,
+               .comp_hash_algorithm = comp_hash_algorithm,
+               .pcr_comp = pcr_comp,
+               .tpm_quote_sign = tpm_quote_sign,
+               .evid_sign = evid_sign,
+       );
+
+       return &this->public.pa_tnc_attribute;
+}
+
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *tcg_pts_attr_simple_evid_final_create_from_data(chunk_t data)
+{
+       private_tcg_pts_attr_simple_evid_final_t *this;
+
+       INIT(this,
+               .public = {
+                       .pa_tnc_attribute = {
+                               .get_vendor_id = _get_vendor_id,
+                               .get_type = _get_type,
+                               .get_value = _get_value,
+                               .get_noskip_flag = _get_noskip_flag,
+                               .set_noskip_flag = _set_noskip_flag,
+                               .build = _build,
+                               .process = _process,
+                               .destroy = _destroy,
+                       },
+                       .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,
+               .value = chunk_clone(data),
+       );
+
+       return &this->public.pa_tnc_attribute;
+}
diff --git a/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h b/src/libimcv/tcg/tcg_pts_attr_simple_evid_final.h
new file mode 100644 (file)
index 0000000..57b4e4d
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2011 Sansar Choinyambuu
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup tcg_pts_attr_simple_evid_final tcg_pts_attr_simple_evid_final
+ * @{ @ingroup tcg_pts_attr_simple_evid_final
+ */
+
+#ifndef TCG_PTS_ATTR_SIMPLE_EVID_FINAL_H_
+#define TCG_PTS_ATTR_SIMPLE_EVID_FINAL_H_
+
+typedef struct tcg_pts_attr_simple_evid_final_t tcg_pts_attr_simple_evid_final_t;
+typedef enum pts_attr_simple_evid_final_flag_t pts_attr_simple_evid_final_flag_t;
+
+#include "tcg_attr.h"
+#include "pa_tnc/pa_tnc_attr.h"
+/* For Optional Composite Hash Algorithm field, pts_attr_meas_algorithms_t*/
+#include "tcg_pts_attr_meas_algo_selection.h" 
+
+/**
+ * PTS Simple Evidence Final Flags
+ */
+enum pts_attr_simple_evid_final_flag_t {
+       /** No Optional TPM PCR Composite nor Optional TPM Quote Signature fields included */
+       PTS_SIMPLE_EVID_FINAL_FLAG_NO =                                         0,
+       /** Optional TPM PCR Composite and Optional TPM Quote Signature fields included */
+       /** using TPM_QUOTE_INFO */
+       PTS_SIMPLE_EVID_FINAL_FLAG_TPM_QUOTE_INFO =                             1,
+       /** 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,
+       /** 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,
+};
+
+/**
+ * Class implementing the TCG PTS Simple Evidence Final attribute
+ *
+ */
+struct tcg_pts_attr_simple_evid_final_t {
+
+       /**
+        * Public PA-TNC attribute interface
+        */
+       pa_tnc_attr_t pa_tnc_attribute;
+       
+       /**
+        * Get flags for PTS Simple Evidence Final
+        *
+        * @return                              Set of flags
+        */
+       pts_attr_simple_evid_final_flag_t (*get_flags)(tcg_pts_attr_simple_evid_final_t *this);
+
+       /**
+        * Set flags for PTS Simple Evidence Final
+        *
+        * @param flags                         Set of flags
+        */
+       void (*set_flags)(tcg_pts_attr_simple_evid_final_t *this, 
+                               pts_attr_simple_evid_final_flag_t flags);
+       
+       /**
+        * Get Optional Composite Hash Algorithm
+        *
+        * @return                              Composite Hash Algorithm
+        */
+       pts_attr_meas_algorithms_t (*get_comp_hash_algorithm)(tcg_pts_attr_simple_evid_final_t *this);
+       
+       /**
+        * Set Optional Composite Hash Algorithm
+        *
+        * @param hash_algorithm                Composite Hash Algorithm
+        */
+       void (*set_comp_hash_algorithm)(tcg_pts_attr_simple_evid_final_t *this,
+                                               pts_attr_meas_algorithms_t hash_algorithm);
+               
+       /**
+        * Get Optional TPM PCR Composite Length
+        *
+        * @return                              Length of Composite PCR Length
+        */
+       u_int32_t (*get_comp_pcr_len)(tcg_pts_attr_simple_evid_final_t *this);
+       
+       /**
+        * Get Optional TPM PCR Composite  
+        *
+        * @return                              PCR Composite
+        */
+       chunk_t (*get_pcr_comp)(tcg_pts_attr_simple_evid_final_t *this);
+               
+       /**
+        * Set Optional TPM PCR Composite 
+        *
+        * @param pcr_comp                      PCR Composite
+        */
+       void (*set_pcr_comp)(tcg_pts_attr_simple_evid_final_t *this,
+                                               chunk_t pcr_comp);
+       
+       /**
+        * Get Optional TPM Quote Signature Length
+        *
+        * @return                              TPM Quote Signature Length
+        */
+       u_int32_t (*get_tpm_quote_sign_len)(tcg_pts_attr_simple_evid_final_t *this);
+       
+       /**
+        * Get Optional TPM Quote Signature 
+        *
+        * @return                              TPM Quote Signature 
+        */
+       chunk_t (*get_tpm_quote_sign)(tcg_pts_attr_simple_evid_final_t *this);
+               
+       /**
+        * Set Optional TPM Quote Signature  
+        *
+        * @param tpm_quote_sign                TPM Quote Signature 
+        */
+       void (*set_tpm_quote_sign)(tcg_pts_attr_simple_evid_final_t *this,
+                                               chunk_t tpm_quote_sign);
+       
+       /**
+        * Get Optional Evidence Signature
+        *
+        * @return                              Optional Evidence Signature
+        */
+       chunk_t (*get_evid_sign)(tcg_pts_attr_simple_evid_final_t *this);
+               
+       /**
+        * Set Optional Evidence Signature
+        *
+        * @param signature                     Optional Evidence Signature
+        */
+       void (*set_evid_sign)(tcg_pts_attr_simple_evid_final_t *this,
+                                               chunk_t signature);
+       
+};
+
+/**
+ * Creates an tcg_pts_attr_simple_evid_final_t object
+ * 
+ * @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_attr_simple_evid_final_flag_t flags,
+                                      pts_attr_meas_algorithms_t comp_hash_algorithm,
+                                      chunk_t pcr_comp,
+                                      chunk_t tpm_quote_sign,
+                                      chunk_t evid_sign);
+
+/**
+ * Creates an tcg_pts_attr_simple_evid_final_t object from received data
+ *
+ * @param value                                unparsed attribute value
+ */
+pa_tnc_attr_t* tcg_pts_attr_simple_evid_final_create_from_data(chunk_t value);
+
+#endif /** TCG_PTS_ATTR_SIMPLE_EVID_FINAL_H_ @}*/