summaryrefslogtreecommitdiff
path: root/src/libpts/tcg
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-02-07 13:27:27 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-02-07 13:27:27 +0100
commit7585facf05d927eb6df3929ce09ed5e60d905437 (patch)
treee4d14b4dc180db20356b6b01ce0112f3a2d7897e /src/libpts/tcg
parentc1343b3278cdf99533b7902744d15969f9d6fdc1 (diff)
downloadvyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.tar.gz
vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.zip
Imported Upstream version 5.0.2
Diffstat (limited to 'src/libpts/tcg')
-rw-r--r--src/libpts/tcg/tcg_pts_attr_aik.c6
-rw-r--r--src/libpts/tcg/tcg_pts_attr_dh_nonce_finish.c8
-rw-r--r--src/libpts/tcg/tcg_pts_attr_dh_nonce_params_req.c8
-rw-r--r--src/libpts/tcg/tcg_pts_attr_dh_nonce_params_resp.c8
-rw-r--r--src/libpts/tcg/tcg_pts_attr_file_meas.c38
-rw-r--r--src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c6
-rw-r--r--src/libpts/tcg/tcg_pts_attr_get_aik.c4
-rw-r--r--src/libpts/tcg/tcg_pts_attr_get_tpm_version_info.c6
-rw-r--r--src/libpts/tcg/tcg_pts_attr_meas_algo.c8
-rw-r--r--src/libpts/tcg/tcg_pts_attr_proto_caps.c8
-rw-r--r--src/libpts/tcg/tcg_pts_attr_req_file_meas.c23
-rw-r--r--src/libpts/tcg/tcg_pts_attr_req_file_meta.c27
-rw-r--r--src/libpts/tcg/tcg_pts_attr_req_func_comp_evid.c12
-rw-r--r--src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c36
-rw-r--r--src/libpts/tcg/tcg_pts_attr_simple_evid_final.c34
-rw-r--r--src/libpts/tcg/tcg_pts_attr_tpm_version_info.c6
-rw-r--r--src/libpts/tcg/tcg_pts_attr_unix_file_meta.c28
17 files changed, 131 insertions, 135 deletions
diff --git a/src/libpts/tcg/tcg_pts_attr_aik.c b/src/libpts/tcg/tcg_pts_attr_aik.c
index 75f3f179c..d5bbdc9cd 100644
--- a/src/libpts/tcg/tcg_pts_attr_aik.c
+++ b/src/libpts/tcg/tcg_pts_attr_aik.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_aik_t private_tcg_pts_attr_aik_t;
@@ -57,7 +57,7 @@ struct private_tcg_pts_attr_aik_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
@@ -135,7 +135,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
u_int8_t flags;
certificate_type_t type;
chunk_t aik_blob;
-
+
if (this->value.len < PTS_AIK_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Attestation Identity Key");
diff --git a/src/libpts/tcg/tcg_pts_attr_dh_nonce_finish.c b/src/libpts/tcg/tcg_pts_attr_dh_nonce_finish.c
index 3ca255cba..4d7281243 100644
--- a/src/libpts/tcg/tcg_pts_attr_dh_nonce_finish.c
+++ b/src/libpts/tcg/tcg_pts_attr_dh_nonce_finish.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_dh_nonce_finish_t
private_tcg_pts_attr_dh_nonce_finish_t;
@@ -36,7 +36,7 @@ typedef struct private_tcg_pts_attr_dh_nonce_finish_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | D-H Initiator Nonce ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_DH_NONCE_FINISH_SIZE 12
@@ -66,7 +66,7 @@ struct private_tcg_pts_attr_dh_nonce_finish_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Selected Hashing Algorithm
*/
@@ -127,7 +127,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint16(writer, this->hash_algo);
writer->write_data (writer, this->initiator_value);
writer->write_data (writer, this->initiator_nonce);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
diff --git a/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_req.c b/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_req.c
index 828c09605..7796dbaab 100644
--- a/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_req.c
+++ b/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_req.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_dh_nonce_params_req_t
private_tcg_pts_attr_dh_nonce_params_req_t;
@@ -32,7 +32,7 @@ typedef struct private_tcg_pts_attr_dh_nonce_params_req_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reserved | Min. Nonce Len | D-H Group Set |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_DH_NONCE_PARAMS_REQ_SIZE 4
@@ -62,7 +62,7 @@ struct private_tcg_pts_attr_dh_nonce_params_req_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Minimum acceptable length of nonce
*/
@@ -116,7 +116,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint8 (writer, PTS_DH_NONCE_PARAMS_REQ_RESERVED);
writer->write_uint8 (writer, this->min_nonce_len);
writer->write_uint16(writer, this->dh_groups);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
diff --git a/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_resp.c b/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_resp.c
index 66ac185b3..1e82e7098 100644
--- a/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_resp.c
+++ b/src/libpts/tcg/tcg_pts_attr_dh_nonce_params_resp.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_dh_nonce_params_resp_t
private_tcg_pts_attr_dh_nonce_params_resp_t;
@@ -38,7 +38,7 @@ typedef struct private_tcg_pts_attr_dh_nonce_params_resp_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | D-H Responder Public Value ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_DH_NONCE_PARAMS_RESP_SIZE 16
@@ -68,7 +68,7 @@ struct private_tcg_pts_attr_dh_nonce_params_resp_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Selected Diffie Hellman group
*/
@@ -135,7 +135,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint16(writer, this->hash_algo_set);
writer->write_data (writer, this->responder_nonce);
writer->write_data (writer, this->responder_value);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
diff --git a/src/libpts/tcg/tcg_pts_attr_file_meas.c b/src/libpts/tcg/tcg_pts_attr_file_meas.c
index 01c4361e1..1daac70e5 100644
--- a/src/libpts/tcg/tcg_pts_attr_file_meas.c
+++ b/src/libpts/tcg/tcg_pts_attr_file_meas.c
@@ -18,15 +18,15 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <utils/linked_list.h>
-#include <debug.h>
+#include <collections/linked_list.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_file_meas_t private_tcg_pts_attr_file_meas_t;
/**
* File Measurement
* see section 3.19.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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -72,12 +72,12 @@ struct private_tcg_pts_attr_file_meas_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* PTS File Measurements
*/
@@ -123,7 +123,7 @@ METHOD(pa_tnc_attr_t, build, void,
char *filename;
chunk_t measurement;
bool first = TRUE;
-
+
if (this->value.ptr)
{
return;
@@ -144,8 +144,7 @@ METHOD(pa_tnc_attr_t, build, void,
first = FALSE;
}
writer->write_data (writer, measurement);
- writer->write_uint16(writer, strlen(filename));
- writer->write_data (writer, chunk_create(filename, strlen(filename)));
+ writer->write_data16(writer, chunk_create(filename, strlen(filename)));
}
enumerator->destroy(enumerator);
@@ -164,12 +163,12 @@ METHOD(pa_tnc_attr_t, process, status_t,
{
bio_reader_t *reader;
u_int64_t number_of_files;
- u_int16_t request_id, meas_len, filename_len;
- size_t len;
+ u_int16_t request_id, meas_len;
chunk_t measurement, filename;
+ size_t len;
char buf[BUF_LEN];
status_t status = FAILED;
-
+
if (this->value.len < PTS_FILE_MEAS_SIZE)
{
DBG1(DBG_TNC, "insufficient data for PTS file measurement header");
@@ -181,9 +180,10 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader->read_uint64(reader, &number_of_files);
reader->read_uint16(reader, &request_id);
reader->read_uint16(reader, &meas_len);
-
+ *offset = PTS_FILE_MEAS_SIZE;
+
this->measurements = pts_file_meas_create(request_id);
-
+
while (number_of_files--)
{
if (!reader->read_data(reader, meas_len, &measurement))
@@ -191,16 +191,14 @@ METHOD(pa_tnc_attr_t, process, status_t,
DBG1(DBG_TNC, "insufficient data for PTS file measurement");
goto end;
}
- if (!reader->read_uint16(reader, &filename_len))
- {
- DBG1(DBG_TNC, "insufficient data for filename length");
- goto end;
- }
- if (!reader->read_data(reader, filename_len, &filename))
+ *offset += meas_len;
+
+ if (!reader->read_data16(reader, &filename))
{
DBG1(DBG_TNC, "insufficient data for filename");
goto end;
}
+ *offset += 2 + filename.len;
len = min(filename.len, BUF_LEN-1);
memcpy(buf, filename.ptr, len);
@@ -225,7 +223,7 @@ METHOD(pa_tnc_attr_t, destroy, void,
{
if (ref_put(&this->ref))
{
- this->measurements->destroy(this->measurements);
+ DESTROY_IF(this->measurements);
free(this->value.ptr);
free(this);
}
diff --git a/src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c b/src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c
index 5eac5ecae..9103e06b2 100644
--- a/src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c
+++ b/src/libpts/tcg/tcg_pts_attr_gen_attest_evid.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_gen_attest_evid_t
private_tcg_pts_attr_gen_attest_evid_t;
@@ -33,7 +33,7 @@ typedef struct private_tcg_pts_attr_gen_attest_evid_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reserved |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_GEN_ATTEST_EVID_SIZE 4
@@ -115,7 +115,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
{
bio_reader_t *reader;
u_int32_t reserved;
-
+
if (this->value.len < PTS_GEN_ATTEST_EVID_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Generate Attestation Evidence");
diff --git a/src/libpts/tcg/tcg_pts_attr_get_aik.c b/src/libpts/tcg/tcg_pts_attr_get_aik.c
index 4b5eae7a7..6f35f5419 100644
--- a/src/libpts/tcg/tcg_pts_attr_get_aik.c
+++ b/src/libpts/tcg/tcg_pts_attr_get_aik.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_get_aik_t private_tcg_pts_attr_get_aik_t;
@@ -112,7 +112,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
{
bio_reader_t *reader;
u_int32_t reserved;
-
+
if (this->value.len < PTS_GET_AIK_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Get AIK");
diff --git a/src/libpts/tcg/tcg_pts_attr_get_tpm_version_info.c b/src/libpts/tcg/tcg_pts_attr_get_tpm_version_info.c
index 0cfc7efa9..4dd64e3a7 100644
--- a/src/libpts/tcg/tcg_pts_attr_get_tpm_version_info.c
+++ b/src/libpts/tcg/tcg_pts_attr_get_tpm_version_info.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_get_tpm_version_info_t
private_tcg_pts_attr_get_tpm_version_info_t;
@@ -33,7 +33,7 @@ typedef struct private_tcg_pts_attr_get_tpm_version_info_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reserved |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_GET_TPM_VER_INFO_SIZE 4
@@ -115,7 +115,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
{
bio_reader_t *reader;
u_int32_t reserved;
-
+
if (this->value.len < PTS_GET_TPM_VER_INFO_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Get TPM Version Information");
diff --git a/src/libpts/tcg/tcg_pts_attr_meas_algo.c b/src/libpts/tcg/tcg_pts_attr_meas_algo.c
index bb95adc9e..abef45bdd 100644
--- a/src/libpts/tcg/tcg_pts_attr_meas_algo.c
+++ b/src/libpts/tcg/tcg_pts_attr_meas_algo.c
@@ -18,12 +18,12 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t;
/**
- * PTS Measurement Algorithm
+ * PTS Measurement Algorithm
* see section 3.9.1 of PTS Protocol: Binding to TNC IF-M Specification
*
* 1 2 3
@@ -31,7 +31,7 @@ typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reserved | Hash Algorithm Set |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_MEAS_ALGO_SIZE 4
@@ -61,7 +61,7 @@ struct private_tcg_pts_attr_meas_algo_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Set of algorithms
*/
diff --git a/src/libpts/tcg/tcg_pts_attr_proto_caps.c b/src/libpts/tcg/tcg_pts_attr_proto_caps.c
index 83665ff69..360883282 100644
--- a/src/libpts/tcg/tcg_pts_attr_proto_caps.c
+++ b/src/libpts/tcg/tcg_pts_attr_proto_caps.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_proto_caps_t private_tcg_pts_attr_proto_caps_t;
@@ -31,7 +31,7 @@ typedef struct private_tcg_pts_attr_proto_caps_t private_tcg_pts_attr_proto_caps
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Reserved |C|V|D|T|X|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *
+ *
*/
#define PTS_PROTO_CAPS_SIZE 4
@@ -61,7 +61,7 @@ struct private_tcg_pts_attr_proto_caps_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Set of flags
*/
@@ -109,7 +109,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer = bio_writer_create(PTS_PROTO_CAPS_SIZE);
writer->write_uint16(writer, PTS_PROTO_CAPS_RESERVED);
writer->write_uint16(writer, this->flags);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
diff --git a/src/libpts/tcg/tcg_pts_attr_req_file_meas.c b/src/libpts/tcg/tcg_pts_attr_req_file_meas.c
index 65bdff579..8b4bfe54d 100644
--- a/src/libpts/tcg/tcg_pts_attr_req_file_meas.c
+++ b/src/libpts/tcg/tcg_pts_attr_req_file_meas.c
@@ -18,14 +18,16 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
+
+#include <string.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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -62,12 +64,12 @@ struct private_tcg_pts_attr_req_file_meas_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Directory Contents flag
*/
@@ -77,12 +79,12 @@ struct private_tcg_pts_attr_req_file_meas_t {
* Request ID
*/
u_int16_t request_id;
-
+
/**
* UTF8 Encoding of Delimiter Character
*/
u_int32_t delimiter;
-
+
/**
* Fully Qualified File Pathname
*/
@@ -124,7 +126,7 @@ METHOD(pa_tnc_attr_t, build, void,
u_int8_t flags = PTS_REQ_FILE_MEAS_NO_FLAGS;
chunk_t pathname;
bio_writer_t *writer;
-
+
if (this->value.ptr)
{
return;
@@ -152,7 +154,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
u_int8_t flags;
u_int8_t reserved;
chunk_t pathname;
-
+
if (this->value.len < PTS_REQ_FILE_MEAS_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Request File Measurement");
@@ -169,10 +171,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
this->directory_flag = (flags & DIRECTORY_CONTENTS_FLAG) !=
PTS_REQ_FILE_MEAS_NO_FLAGS;
-
- this->pathname = malloc(pathname.len + 1);
- memcpy(this->pathname, pathname.ptr, pathname.len);
- this->pathname[pathname.len] = '\0';
+ this->pathname = strndup(pathname.ptr, pathname.len);
reader->destroy(reader);
return SUCCESS;
diff --git a/src/libpts/tcg/tcg_pts_attr_req_file_meta.c b/src/libpts/tcg/tcg_pts_attr_req_file_meta.c
index eb5114172..ff5581435 100644
--- a/src/libpts/tcg/tcg_pts_attr_req_file_meta.c
+++ b/src/libpts/tcg/tcg_pts_attr_req_file_meta.c
@@ -18,14 +18,16 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
+
+#include <string.h>
typedef struct private_tcg_pts_attr_req_file_meta_t private_tcg_pts_attr_req_file_meta_t;
/**
* Request File Metadata
* see section 3.17.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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -60,22 +62,22 @@ struct private_tcg_pts_attr_req_file_meta_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* Directory Contents flag
*/
bool directory_flag;
-
+
/**
* UTF8 Encoding of Delimiter Character
*/
u_int8_t delimiter;
-
+
/**
* Fully Qualified File Pathname
*/
@@ -117,7 +119,7 @@ METHOD(pa_tnc_attr_t, build, void,
u_int8_t flags = PTS_REQ_FILE_META_NO_FLAGS;
chunk_t pathname;
bio_writer_t *writer;
-
+
if (this->value.ptr)
{
return;
@@ -132,7 +134,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint8 (writer, flags);
writer->write_uint8 (writer, this->delimiter);
writer->write_uint16(writer, PTS_REQ_FILE_META_RESERVED);
-
+
writer->write_data (writer, pathname);
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
@@ -145,7 +147,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
u_int8_t flags;
u_int16_t reserved;
chunk_t pathname;
-
+
if (this->value.len < PTS_REQ_FILE_META_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Request File Metadata");
@@ -157,15 +159,12 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader->read_uint8 (reader, &flags);
reader->read_uint8 (reader, &this->delimiter);
reader->read_uint16(reader, &reserved);
-
+
reader->read_data (reader, reader->remaining(reader), &pathname);
this->directory_flag = (flags & DIRECTORY_CONTENTS_FLAG) !=
PTS_REQ_FILE_META_NO_FLAGS;
-
- this->pathname = malloc(pathname.len + 1);
- memcpy(this->pathname, pathname.ptr, pathname.len);
- this->pathname[pathname.len] = '\0';
+ this->pathname = strndup(pathname.ptr, pathname.len);
reader->destroy(reader);
return SUCCESS;
diff --git a/src/libpts/tcg/tcg_pts_attr_req_func_comp_evid.c b/src/libpts/tcg/tcg_pts_attr_req_func_comp_evid.c
index a631e9891..8bb43aef8 100644
--- a/src/libpts/tcg/tcg_pts_attr_req_func_comp_evid.c
+++ b/src/libpts/tcg/tcg_pts_attr_req_func_comp_evid.c
@@ -18,8 +18,8 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <utils/linked_list.h>
-#include <debug.h>
+#include <collections/linked_list.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_req_func_comp_evid_t private_tcg_pts_attr_req_func_comp_evid_t;
@@ -47,7 +47,7 @@ typedef struct private_tcg_pts_attr_req_func_comp_evid_t private_tcg_pts_attr_re
*/
/**
- * Component Functional Name Structure
+ * Component Functional Name Structure
* (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
*
* 1 2 3
@@ -58,7 +58,7 @@ typedef struct private_tcg_pts_attr_req_func_comp_evid_t private_tcg_pts_attr_re
* | Component Functional Name |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
-
+
#define PTS_REQ_FUNC_COMP_EVID_SIZE 12
#define PTS_REQ_FUNC_COMP_FAMILY_MASK 0xC0
@@ -81,7 +81,7 @@ struct private_tcg_pts_attr_req_func_comp_evid_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
@@ -249,7 +249,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
entry->flags = flags;
entry->depth = depth;
entry->name = pts_comp_func_name_create(vendor_id, name, qualifier);
-
+
this->list->insert_last(this->list, entry);
}
status = SUCCESS;
diff --git a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c
index 387f4a115..c659443b7 100644
--- a/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c
+++ b/src/libpts/tcg/tcg_pts_attr_simple_comp_evid.c
@@ -18,16 +18,16 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
#include <time.h>
typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simple_comp_evid_t;
/**
- * Simple Component Evidence
+ * Simple Component Evidence
* see section 3.15.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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -66,7 +66,7 @@ typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simp
*/
/**
- * Specific Functional Component -> Component Functional Name Structure
+ * Specific Functional Component -> Component Functional Name Structure
* see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification
*
* 1 2 3
@@ -108,12 +108,12 @@ struct private_tcg_pts_attr_simple_comp_evid_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* PTS Component Evidence
*/
@@ -184,7 +184,7 @@ METHOD(pa_tnc_attr_t, build, void,
pts_comp_evid_validation_t validation;
time_t measurement_time;
chunk_t measurement, utc_time, pcr_before, pcr_after;
-
+
if (this->value.ptr)
{
return;
@@ -200,7 +200,7 @@ METHOD(pa_tnc_attr_t, build, void,
&pcr_before, &pcr_after);
validation = this->evidence->get_validation(this->evidence,
&policy_uri);
-
+
/* Determine the flags to set*/
flags = validation;
if (has_pcr_info)
@@ -208,7 +208,7 @@ METHOD(pa_tnc_attr_t, build, void,
flags |= PTS_SIMPLE_COMP_EVID_FLAG_PCR;
}
- utc_time = chunk_create(utc_time_buf, PTS_SIMPLE_COMP_EVID_MEAS_TIME_SIZE);
+ utc_time = chunk_create(utc_time_buf, PTS_SIMPLE_COMP_EVID_MEAS_TIME_SIZE);
measurement_time_to_utc(measurement_time, &utc_time);
writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE);
@@ -224,7 +224,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint8 (writer, transform);
writer->write_uint8 (writer, PTS_SIMPLE_COMP_EVID_RESERVED);
writer->write_data (writer, utc_time);
-
+
/* Optional fields */
if (validation == PTS_COMP_EVID_VALIDATION_FAILED ||
validation == PTS_COMP_EVID_VALIDATION_PASSED)
@@ -241,7 +241,7 @@ METHOD(pa_tnc_attr_t, build, void,
}
writer->write_data(writer, measurement);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
@@ -250,7 +250,7 @@ static const int days[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 33
static const int tm_leap_1970 = 477;
/**
- * Convert Simple Component Evidence UTS string format to time_t
+ * Convert Simple Component Evidence UTS string format to time_t
*/
bool measurement_time_from_utc(time_t *measurement_time, chunk_t utc_time)
{
@@ -314,7 +314,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
return FAILED;
}
reader = bio_reader_create(this->value);
-
+
reader->read_uint8 (reader, &flags);
reader->read_uint24(reader, &depth);
reader->read_uint24(reader, &vendor_id);
@@ -364,7 +364,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
}
has_validation = TRUE;
}
-
+
/* Are optional PCR value fields included? */
if (flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR)
{
@@ -389,11 +389,11 @@ METHOD(pa_tnc_attr_t, process, status_t,
has_pcr_info = TRUE;
}
- /* Measurement field comes at the very end */
+ /* Measurement field comes at the very end */
reader->read_data(reader,reader->remaining(reader), &measurement);
reader->destroy(reader);
- /* Create Component Functional Name object */
+ /* Create Component Functional Name object */
name = pts_comp_func_name_create(vendor_id, comp_name, qualifier);
/* Create Component Evidence object */
@@ -439,7 +439,7 @@ METHOD(pa_tnc_attr_t, destroy, void,
{
if (ref_put(&this->ref))
{
- this->evidence->destroy(this->evidence);
+ DESTROY_IF(this->evidence);
free(this->value.ptr);
free(this);
}
@@ -457,7 +457,7 @@ METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_evidence, pts_comp_evidence_t*,
pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(pts_comp_evidence_t *evid)
{
private_tcg_pts_attr_simple_comp_evid_t *this;
-
+
INIT(this,
.public = {
.pa_tnc_attribute = {
diff --git a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c
index 8d2d4f82d..8c76651d6 100644
--- a/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c
+++ b/src/libpts/tcg/tcg_pts_attr_simple_evid_final.c
@@ -19,14 +19,14 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -66,7 +66,7 @@ struct private_tcg_pts_attr_simple_evid_final_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
@@ -81,22 +81,22 @@ struct private_tcg_pts_attr_simple_evid_final_t {
* Optional Composite Hash Algorithm
*/
pts_meas_algorithms_t comp_hash_algorithm;
-
+
/**
* Optional TPM PCR Composite
*/
chunk_t pcr_comp;
-
+
/**
* Optional TPM Quote Signature
*/
chunk_t tpm_quote_sig;
-
+
/**
* Is Evidence Signature included?
*/
bool has_evid_sig;
-
+
/**
* Optional Evidence Signature
*/
@@ -157,7 +157,7 @@ METHOD(pa_tnc_attr_t, build, void,
{
bio_writer_t *writer;
u_int8_t flags;
-
+
if (this->value.ptr)
{
return;
@@ -172,7 +172,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer = bio_writer_create(PTS_SIMPLE_EVID_FINAL_SIZE);
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
@@ -193,7 +193,7 @@ METHOD(pa_tnc_attr_t, build, void,
{
writer->write_data (writer, this->evid_sig);
}
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
@@ -206,7 +206,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
u_int16_t algorithm;
u_int32_t pcr_comp_len, tpm_quote_sig_len, evid_sig_len;
status_t status = FAILED;
-
+
if (this->value.len < PTS_SIMPLE_EVID_FINAL_SIZE)
{
DBG1(DBG_TNC, "insufficient data for Simple Evidence Final");
@@ -214,7 +214,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
return FAILED;
}
reader = bio_reader_create(this->value);
-
+
reader->read_uint8(reader, &flags);
reader->read_uint8(reader, &reserved);
@@ -226,10 +226,10 @@ METHOD(pa_tnc_attr_t, process, status_t,
* 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 Composite Hash Algorithm and TPM PCR Composite fields */
if (this->flags != PTS_SIMPLE_EVID_FINAL_NO)
{
@@ -246,7 +246,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
goto end;
}
this->pcr_comp = chunk_clone(this->pcr_comp);
-
+
if (!reader->read_uint32(reader, &tpm_quote_sig_len))
{
DBG1(DBG_TNC, "insufficient data for PTS Simple Evidence Final "
@@ -261,7 +261,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
}
this->tpm_quote_sig = chunk_clone(this->tpm_quote_sig);
}
-
+
/* Optional Evidence Signature field */
if (this->has_evid_sig)
{
@@ -269,7 +269,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader->read_data(reader, evid_sig_len, &this->evid_sig);
this->evid_sig = chunk_clone(this->evid_sig);
}
-
+
reader->destroy(reader);
return SUCCESS;
diff --git a/src/libpts/tcg/tcg_pts_attr_tpm_version_info.c b/src/libpts/tcg/tcg_pts_attr_tpm_version_info.c
index 8d1e78f18..5143e1676 100644
--- a/src/libpts/tcg/tcg_pts_attr_tpm_version_info.c
+++ b/src/libpts/tcg/tcg_pts_attr_tpm_version_info.c
@@ -18,7 +18,7 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <debug.h>
+#include <utils/debug.h>
typedef struct private_tcg_pts_attr_tpm_version_info_t private_tcg_pts_attr_tpm_version_info_t;
@@ -62,7 +62,7 @@ struct private_tcg_pts_attr_tpm_version_info_t {
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* TPM Version Information
*/
@@ -118,7 +118,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
private_tcg_pts_attr_tpm_version_info_t *this, u_int32_t *offset)
{
bio_reader_t *reader;
-
+
if (this->value.len < PTS_TPM_VER_INFO_SIZE)
{
DBG1(DBG_TNC, "insufficient data for TPM Version Information");
diff --git a/src/libpts/tcg/tcg_pts_attr_unix_file_meta.c b/src/libpts/tcg/tcg_pts_attr_unix_file_meta.c
index 4f93ee885..56686d8ca 100644
--- a/src/libpts/tcg/tcg_pts_attr_unix_file_meta.c
+++ b/src/libpts/tcg/tcg_pts_attr_unix_file_meta.c
@@ -18,15 +18,17 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <bio/bio_writer.h>
#include <bio/bio_reader.h>
-#include <utils/linked_list.h>
-#include <debug.h>
+#include <collections/linked_list.h>
+#include <utils/debug.h>
+
+#include <string.h>
typedef struct private_tcg_pts_attr_file_meta_t private_tcg_pts_attr_file_meta_t;
/**
* Unix-Style File Metadata
* see section 3.17.3 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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -88,12 +90,12 @@ struct private_tcg_pts_attr_file_meta_t {
* Attribute value
*/
chunk_t value;
-
+
/**
* Noskip flag
*/
bool noskip_flag;
-
+
/**
* PTS File Metadata
*/
@@ -136,7 +138,7 @@ METHOD(pa_tnc_attr_t, build, void,
enumerator_t *enumerator;
pts_file_metadata_t *entry;
u_int64_t number_of_files;
-
+
if (this->value.ptr)
{
return;
@@ -163,7 +165,7 @@ METHOD(pa_tnc_attr_t, build, void,
strlen(entry->filename)));
}
enumerator->destroy(enumerator);
-
+
this->value = chunk_clone(writer->get_buf(writer));
writer->destroy(writer);
}
@@ -179,7 +181,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
u_int64_t owner, group;
chunk_t filename;
status_t status = FAILED;
-
+
if (this->value.len < PTS_FILE_META_SIZE)
{
DBG1(DBG_TNC, "insufficient data for PTS Unix-Style file metadata header");
@@ -190,7 +192,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader->read_uint64(reader, &number_of_files);
this->metadata = pts_file_meta_create();
-
+
while (number_of_files--)
{
if (!reader->read_uint16(reader, &len))
@@ -243,7 +245,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
DBG1(DBG_TNC, "insufficient data for filename");
goto end;
}
-
+
entry = malloc_thing(pts_file_metadata_t);
entry->type = type;
entry->filesize = filesize;
@@ -252,9 +254,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
entry->accessed = accessed;
entry->owner = owner;
entry->group = group;
- entry->filename = malloc(filename.len + 1);
- entry->filename[filename.len] = '\0';
- memcpy(entry->filename, filename.ptr, filename.len);
+ entry->filename = strndup(filename.ptr, filename.len);
this->metadata->add(this->metadata, entry);
}
@@ -277,7 +277,7 @@ METHOD(pa_tnc_attr_t, destroy, void,
{
if (ref_put(&this->ref))
{
- this->metadata->destroy(this->metadata);
+ DESTROY_IF(this->metadata);
free(this->value.ptr);
free(this);
}