moved proto_caps and meas_algo to pts object

This commit is contained in:
Andreas Steffen
2011-09-08 12:08:12 +02:00
parent 8a2482c7c2
commit 01e069b675
9 changed files with 213 additions and 121 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ libimcv_la_SOURCES = \
tcg/tcg_pts_attr_req_file_meas.h tcg/tcg_pts_attr_req_file_meas.c \
tcg/tcg_pts_attr_file_meas.h tcg/tcg_pts_attr_file_meas.c \
tcg/pts/pts.h tcg/pts/pts.c \
tcg/pts/pts_funct_comp_name.h \
tcg/pts/pts_proto_caps.h tcg/pts/pts_funct_comp_name.h \
tcg/pts/pts_meas_algo.h tcg/pts/pts_meas_algo.c
# CFLAGS = -Wall -Werror
@@ -20,7 +20,6 @@
#include <ietf/ietf_attr.h>
#include <ietf/ietf_attr_pa_tnc_error.h>
#include <tcg/pts/pts.h>
#include <tcg/tcg_pts_attr_proto_caps.h>
#include <tcg/tcg_pts_attr_meas_algo.h>
#include <tcg/tcg_pts_attr_get_tpm_version_info.h>
@@ -58,16 +57,6 @@ static imc_agent_t *imc_attestation;
*/
static pts_meas_algorithms_t supported_algorithms = 0;
/**
* PTS Protocol capabilities
*/
static pts_proto_caps_flag_t proto_caps;
/**
* Selected PTS measurement algorithm after attribute exchange
*/
static pts_meas_algorithms_t selected_algorithm = PTS_MEAS_ALGO_SHA256;
/**
* List of files and directories to measure
*/
@@ -157,10 +146,12 @@ static TNC_Result hash_file(char *path, char *out)
char buffer[IMC_ATTESTATION_BUF_SIZE];
FILE *file;
int bytes_read;
pts_meas_algorithms_t selected_algorithm;
hasher_t *hasher;
hash_algorithm_t hash_alg;
/* Create a hasher */
selected_algorithm = PTS_MEAS_ALGO_SHA256; /* temporary fix, move to pts */
hash_alg = pts_meas_to_hash_algorithm(selected_algorithm);
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
if (!hasher)
@@ -239,6 +230,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
{
pa_tnc_msg_t *msg;
pa_tnc_attr_t *attr;
pts_t *pts;
imc_state_t *state;
imc_attestation_state_t *attestation_state;
imc_attestation_handshake_state_t handshake_state;
@@ -250,6 +242,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
}
attestation_state = (imc_attestation_state_t*)state;
handshake_state = attestation_state->get_handshake_state(attestation_state);
pts = attestation_state->get_pts(attestation_state);
/* Switch on the attribute type IMC has received */
switch (handshake_state)
@@ -257,28 +250,23 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
case IMC_ATTESTATION_STATE_REQ_PROTO_CAPS:
{
pts_proto_caps_flag_t flags;
if(proto_caps & PTS_PROTO_CAPS_T)
{
flags = PTS_PROTO_CAPS_T;
}
if(proto_caps & PTS_PROTO_CAPS_V)
{
flags |= PTS_PROTO_CAPS_V;
}
flags = pts->get_proto_caps(pts);
attr = tcg_pts_attr_proto_caps_create(flags, FALSE);
break;
}
case IMC_ATTESTATION_STATE_REQ_MEAS_ALGO:
{
pts_meas_algorithms_t selected_algorithm;
selected_algorithm = pts->get_meas_algorithm(pts);
attr = tcg_pts_attr_meas_algo_create(selected_algorithm, TRUE);
break;
}
case IMC_ATTESTATION_STATE_GET_TPM_INFO:
{
chunk_t tpm_version_info;
pts_t *pts;
pts = attestation_state->get_pts(attestation_state);
if (!pts->get_tpm_version_info(pts, &tpm_version_info))
{
/* TODO return TCG_PTS_TPM_VERS_NOT_SUPPORTED error attribute */
@@ -292,7 +280,9 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
enumerator_t *enumerator;
tcg_pts_attr_file_meas_t *attr_file_meas;
u_int16_t meas_len = HASH_SIZE_SHA1;
pts_meas_algorithms_t selected_algorithm;
selected_algorithm = PTS_MEAS_ALGO_SHA256; /* temporary fix, move to pts */
if (selected_algorithm & PTS_MEAS_ALGO_SHA384)
{
meas_len = HASH_SIZE_SHA384;
@@ -422,6 +412,7 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
imc_state_t *state;
imc_attestation_state_t *attestation_state;
enumerator_t *enumerator;
pts_t *pts;
TNC_Result result;
bool fatal_error = FALSE;
@@ -431,6 +422,14 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
return TNC_RESULT_NOT_INITIALIZED;
}
/* get current IMC state */
if (!imc_attestation->get_state(imc_attestation, connection_id, &state))
{
return TNC_RESULT_FATAL;
}
attestation_state = (imc_attestation_state_t*)state;
pts = attestation_state->get_pts(attestation_state);
/* parse received PA-TNC message and automatically handle any errors */
result = imc_attestation->receive_message(imc_attestation, connection_id,
chunk_create(msg, msg_len), msg_type,
@@ -477,25 +476,17 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
}
else if (attr->get_vendor_id(attr) == PEN_TCG)
{
/**
* Handle TCG PTS attributes
*/
/* get current IMC state */
if (!imc_attestation->get_state(imc_attestation, connection_id, &state))
{
return TNC_RESULT_FATAL;
}
attestation_state = (imc_attestation_state_t*)state;
switch(attr->get_type(attr))
{
case TCG_PTS_REQ_PROTO_CAPS:
{
tcg_pts_attr_proto_caps_t *attr_req_proto_caps;
attr_req_proto_caps = (tcg_pts_attr_proto_caps_t*)attr;
proto_caps = attr_req_proto_caps->get_flags(attr_req_proto_caps);
tcg_pts_attr_proto_caps_t *attr_cast;
pts_proto_caps_flag_t imc_flags, imv_flags;
attr_cast = (tcg_pts_attr_proto_caps_t*)attr;
imv_flags = attr_cast->get_flags(attr_cast);
imc_flags = pts->get_proto_caps(pts);
pts->set_proto_caps(pts, imc_flags & imv_flags);
attestation_state->set_handshake_state(attestation_state,
IMC_ATTESTATION_STATE_REQ_PROTO_CAPS);
@@ -503,10 +494,11 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
}
case TCG_PTS_MEAS_ALGO:
{
tcg_pts_attr_meas_algo_t *attr_meas_algo;
tcg_pts_attr_meas_algo_t *attr_cast;
pts_meas_algorithms_t selected_algorithm;
attr_meas_algo = (tcg_pts_attr_meas_algo_t*)attr;
selected_algorithm = attr_meas_algo->get_algorithms(attr_meas_algo);
attr_cast = (tcg_pts_attr_meas_algo_t*)attr;
selected_algorithm = attr_cast->get_algorithms(attr_cast);
if ((supported_algorithms & PTS_MEAS_ALGO_SHA384) &&
(selected_algorithm & PTS_MEAS_ALGO_SHA384))
@@ -523,12 +515,9 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
}
else
{
/* TODO generate an error message */
selected_algorithm = PTS_MEAS_ALGO_SHA256;
/* TODO send a TCG_PTS_HASH_ALG_NOT_SUPPORTED error */
}
DBG2(DBG_IMC, "selected PTS measurement algorithm is %N",
hash_algorithm_names,
pts_meas_to_hash_algorithm(selected_algorithm));
pts->set_meas_algorithm(pts, selected_algorithm);
attestation_state->set_handshake_state(attestation_state,
IMC_ATTESTATION_STATE_REQ_MEAS_ALGO);
@@ -555,19 +544,19 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
break;
case TCG_PTS_REQ_FILE_MEAS:
{
tcg_pts_attr_req_file_meas_t *attr_req_file_meas;
tcg_pts_attr_req_file_meas_t *attr_cast;
measurement_req_entry_t *entry;
u_int32_t delimiter;
attr_req_file_meas = (tcg_pts_attr_req_file_meas_t*)attr;
attr_cast = (tcg_pts_attr_req_file_meas_t*)attr;
file_list = linked_list_create();
directory_list = linked_list_create();
delimiter = attr_req_file_meas->get_delimiter(attr_req_file_meas);
delimiter = attr_cast->get_delimiter(attr_cast);
entry = malloc_thing(measurement_req_entry_t);
entry->request_id = attr_req_file_meas->get_request_id(attr_req_file_meas);
entry->path = attr_req_file_meas->get_file_path(attr_req_file_meas).ptr;
entry->request_id = attr_cast->get_request_id(attr_cast);
entry->path = attr_cast->get_file_path(attr_cast).ptr;
(attr_req_file_meas->get_directory_flag(attr_req_file_meas)) ?
attr_cast->get_directory_flag(attr_cast) ?
directory_list->insert_last(directory_list, entry) :
file_list->insert_last(file_list, entry);
@@ -110,7 +110,7 @@ imc_state_t *imc_attestation_state_create(TNC_ConnectionID connection_id)
.connection_id = connection_id,
.state = TNC_CONNECTION_STATE_CREATE,
.handshake_state = IMC_ATTESTATION_STATE_INIT,
.pts = pts_create(),
.pts = pts_create(TRUE),
);
return &this->public.interface;
@@ -20,7 +20,6 @@
#include <ietf/ietf_attr.h>
#include <ietf/ietf_attr_pa_tnc_error.h>
#include <tcg/pts/pts.h>
#include <tcg/tcg_attr.h>
#include <tcg/tcg_pts_attr_proto_caps.h>
#include <tcg/tcg_pts_attr_meas_algo.h>
@@ -224,6 +223,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
pa_tnc_msg_t *msg;
pa_tnc_attr_t *attr;
TNC_Result result;
pts_t *pts;
imv_state_t *state;
imv_attestation_state_t *attestation_state;
imv_attestation_handshake_state_t handshake_state;
@@ -232,10 +232,10 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
{
return TNC_RESULT_FATAL;
}
attestation_state = (imv_attestation_state_t*)state;
handshake_state = attestation_state->get_handshake_state(attestation_state);
pts = attestation_state->get_pts(attestation_state);
/* Switch on the attribute type IMV has received */
switch (handshake_state)
{
@@ -244,7 +244,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
pts_proto_caps_flag_t flags;
/* Send Request Protocol Capabilities attribute */
flags = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_V | PTS_PROTO_CAPS_C;
flags = pts->get_proto_caps(pts);
attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
break;
}
@@ -342,6 +342,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
pa_tnc_attr_t *attr;
imv_state_t *state;
imv_attestation_state_t *attestation_state;
pts_t *pts;
enumerator_t *enumerator;
TNC_Result result;
bool fatal_error = FALSE;
@@ -357,6 +358,8 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
{
return TNC_RESULT_FATAL;
}
attestation_state = (imv_attestation_state_t*)state;
pts = attestation_state->get_pts(attestation_state);
/* parse received PA-TNC message and automatically handle any errors */
result = imv_attestation->receive_message(imv_attestation, connection_id,
@@ -404,62 +407,41 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
}
else if (attr->get_vendor_id(attr) == PEN_TCG)
{
/**
* Handle TCG PTS attributes
*/
/* get current IMC state */
if (!imv_attestation->get_state(imv_attestation, connection_id, &state))
{
return TNC_RESULT_FATAL;
}
attestation_state = (imv_attestation_state_t*)state;
switch(attr->get_type(attr))
{
case TCG_PTS_PROTO_CAPS:
{
tcg_pts_attr_proto_caps_t *attr_proto_caps;
pts_proto_caps_flag_t proto_caps;
tcg_pts_attr_proto_caps_t *attr_cast;
pts_proto_caps_flag_t flags;
attr_proto_caps = (tcg_pts_attr_proto_caps_t*)attr;
proto_caps = attr_proto_caps->get_flags(attr_proto_caps);
/* TODO: What to do with the protocol capabilities from imc */
attr_cast = (tcg_pts_attr_proto_caps_t*)attr;
flags = attr_cast->get_flags(attr_cast);
pts->set_proto_caps(pts, flags);
attestation_state->set_handshake_state(attestation_state,
IMV_ATTESTATION_STATE_PROTO_CAPS);
break;
}
case TCG_PTS_MEAS_ALGO_SELECTION:
{
tcg_pts_attr_meas_algo_t *attr_meas;
tcg_pts_attr_meas_algo_t *attr_cast;
pts_meas_algorithms_t selected_algorithm;
hash_algorithm_t hash_alg;
attr_meas = (tcg_pts_attr_meas_algo_t*)attr;
selected_algorithm = attr_meas->get_algorithms(attr_meas);
hash_alg = pts_meas_to_hash_algorithm(selected_algorithm);
if (hash_alg == HASH_UNKNOWN)
{
/* TODO generate an error message */
break;
}
DBG2(DBG_IMV, "selected PTS measurement algorithm is %N",
hash_algorithm_names, hash_alg);
/* TODO: What to do with the selected algorithm from imc */
attr_cast = (tcg_pts_attr_meas_algo_t*)attr;
selected_algorithm = attr_cast->get_algorithms(attr_cast);
pts->set_meas_algorithm(pts, selected_algorithm);
attestation_state->set_handshake_state(attestation_state,
IMV_ATTESTATION_STATE_MEAS_ALGO);
break;
}
case TCG_PTS_TPM_VERSION_INFO:
{
tcg_pts_attr_tpm_version_info_t *attr_tpm;
tcg_pts_attr_tpm_version_info_t *attr_cast;
chunk_t tpm_version_info;
pts_t *pts;
attr_tpm = (tcg_pts_attr_tpm_version_info_t*)attr;
tpm_version_info = attr_tpm->get_tpm_version_info(attr_tpm);
pts = attestation_state->get_pts(attestation_state);
attr_cast = (tcg_pts_attr_tpm_version_info_t*)attr;
tpm_version_info = attr_cast->get_tpm_version_info(attr_cast);
pts->set_tpm_version_info(pts, tpm_version_info);
attestation_state->set_handshake_state(attestation_state,
@@ -481,15 +463,15 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
break;
case TCG_PTS_FILE_MEAS:
{
tcg_pts_attr_file_meas_t *attr_file_meas;
tcg_pts_attr_file_meas_t *attr_cast;
u_int64_t num_of_files;
u_int16_t request_id;
u_int16_t meas_len;
attr_file_meas = (tcg_pts_attr_file_meas_t*)attr;
num_of_files = attr_file_meas->get_number_of_files(attr_file_meas);
request_id = attr_file_meas->get_request_id(attr_file_meas);
meas_len = attr_file_meas->get_meas_len(attr_file_meas);
attr_cast = (tcg_pts_attr_file_meas_t*)attr;
num_of_files = attr_cast->get_number_of_files(attr_cast);
request_id = attr_cast->get_request_id(attr_cast);
meas_len = attr_cast->get_meas_len(attr_cast);
/* TODO: Start working here */
@@ -204,7 +204,7 @@ imv_state_t *imv_attestation_state_create(TNC_ConnectionID connection_id)
.handshake_state = IMV_ATTESTATION_STATE_INIT,
.rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
.eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
.pts = pts_create(),
.pts = pts_create(FALSE),
);
return &this->public.interface;
+61 -1
View File
@@ -16,6 +16,7 @@
#include "pts.h"
#include <debug.h>
#include <crypto/hashers/hasher.h>
#include <trousers/tss.h>
#include <trousers/trousers.h>
@@ -33,12 +34,60 @@ struct private_pts_t {
*/
pts_t public;
/**
* PTS Protocol Capabilities
*/
pts_proto_caps_flag_t proto_caps;
/**
* PTS Measurement Algorithm
*/
pts_meas_algorithms_t algorithm;
/**
* Contains a TPM_CAP_VERSION_INFO struct
*/
chunk_t tpm_version_info;
};
METHOD(pts_t, get_proto_caps, pts_proto_caps_flag_t,
private_pts_t *this)
{
return this->proto_caps;
}
METHOD(pts_t, set_proto_caps, void,
private_pts_t *this, pts_proto_caps_flag_t flags)
{
this->proto_caps = flags;
DBG2(DBG_TNC, "supported PTS protocol capabilities: %s%s%s%s%s",
flags & PTS_PROTO_CAPS_C ? "C" : ".",
flags & PTS_PROTO_CAPS_V ? "V" : ".",
flags & PTS_PROTO_CAPS_D ? "D" : ".",
flags & PTS_PROTO_CAPS_T ? "T" : ".",
flags & PTS_PROTO_CAPS_X ? "X" : ".");
}
METHOD(pts_t, get_meas_algorithm, pts_meas_algorithms_t,
private_pts_t *this)
{
return this->algorithm;
}
METHOD(pts_t, set_meas_algorithm, void,
private_pts_t *this, pts_meas_algorithms_t algorithm)
{
hash_algorithm_t hash_alg;
hash_alg = pts_meas_to_hash_algorithm(algorithm);
DBG2(DBG_TNC, "selected PTS measurement algorithm is %N",
hash_algorithm_names, hash_alg);
if (hash_alg != HASH_UNKNOWN)
{
this->algorithm = algorithm;
}
}
/**
* Print TPM 1.2 Version Info
*/
@@ -125,18 +174,29 @@ METHOD(pts_t, destroy, void,
/**
* See header
*/
pts_t *pts_create(void)
pts_t *pts_create(bool is_imc)
{
private_pts_t *this;
INIT(this,
.public = {
.get_proto_caps = _get_proto_caps,
.set_proto_caps = _set_proto_caps,
.get_meas_algorithm = _get_meas_algorithm,
.set_meas_algorithm = _set_meas_algorithm,
.get_tpm_version_info = _get_tpm_version_info,
.set_tpm_version_info = _set_tpm_version_info,
.destroy = _destroy,
},
.proto_caps = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_C,
.algorithm = PTS_MEAS_ALGO_SHA256,
);
if (!is_imc)
{
this->proto_caps |= PTS_PROTO_CAPS_V;
}
return &this->public;
}
+39 -6
View File
@@ -23,6 +23,9 @@
typedef struct pts_t pts_t;
#include "pts_proto_caps.h"
#include "pts_meas_algo.h"
#include <library.h>
/**
@@ -32,17 +35,45 @@ typedef struct pts_t pts_t;
struct pts_t {
/**
* get TPM 1.2 Version Info
* Get PTS Protocol Capabilities
*
* @param info chunk containing a TPM_CAP_VERSION_INFO struct
* @return TRUE if TPM Version Info available
* @return protocol capabilities flags
*/
pts_proto_caps_flag_t (*get_proto_caps)(pts_t *this);
/**
* Set PTS Protocol Capabilities
*
* @param flags protocol capabilities flags
*/
void (*set_proto_caps)(pts_t *this, pts_proto_caps_flag_t flags);
/**
* Get PTS Measurement Algorithm
*
* @return measurement algorithm
*/
pts_meas_algorithms_t (*get_meas_algorithm)(pts_t *this);
/**
* Set PTS Measurement Algorithm
*
* @param algorithm measurement algorithm
*/
void (*set_meas_algorithm)(pts_t *this, pts_meas_algorithms_t algorithm);
/**
* Get TPM 1.2 Version Info
*
* @param info chunk containing a TPM_CAP_VERSION_INFO struct
* @return TRUE if TPM Version Info available
*/
bool (*get_tpm_version_info)(pts_t *this, chunk_t *info);
/**
* set TPM 1.2 Version Info
* Set TPM 1.2 Version Info
*
* @param info chunk containing a TPM_CAP_VERSION_INFO struct
* @param info chunk containing a TPM_CAP_VERSION_INFO struct
*/
void (*set_tpm_version_info)(pts_t *this, chunk_t info);
@@ -55,7 +86,9 @@ struct pts_t {
/**
* Creates an pts_t object
*
* @param is_imc TRUE if running on an IMC
*/
pts_t* pts_create(void);
pts_t* pts_create(bool is_imc);
#endif /** PTS_H_ @}*/
+44
View File
@@ -0,0 +1,44 @@
/*
* 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_proto_caps tcg_pts_attr_proto_caps
* @{ @ingroup tcg_pts_attr_proto_caps
*/
#ifndef PTS_PROTO_CAPS_H_
#define PTS_PROTO_CAPS_H_
typedef enum pts_proto_caps_flag_t pts_proto_caps_flag_t;
#include <library.h>
/**
* PTS Protocol Capabilities Flags
*/
enum pts_proto_caps_flag_t {
/** XML based Evidence Support flag */
PTS_PROTO_CAPS_X = (1<<0),
/** Trusted Platform Evidence flag */
PTS_PROTO_CAPS_T = (1<<1),
/** DH Nonce Negotiation Support flag */
PTS_PROTO_CAPS_D = (1<<2),
/** Verification Support flag */
PTS_PROTO_CAPS_V = (1<<3),
/** Current (In-Memory) Evidence Support flag */
PTS_PROTO_CAPS_C = (1<<4),
};
#endif /** PTS_PROTO_CAPS_H_ @}*/
+1 -17
View File
@@ -22,26 +22,10 @@
#define TCG_PTS_ATTR_PROTO_CAPS_H_
typedef struct tcg_pts_attr_proto_caps_t tcg_pts_attr_proto_caps_t;
typedef enum pts_proto_caps_flag_t pts_proto_caps_flag_t;
#include "tcg_attr.h"
#include "pa_tnc/pa_tnc_attr.h"
/**
* PTS Protocol Capabilities Flags
*/
enum pts_proto_caps_flag_t {
/** XML based Evidence Support flag */
PTS_PROTO_CAPS_X = (1<<0),
/** Trusted Platform Evidence flag */
PTS_PROTO_CAPS_T = (1<<1),
/** DH Nonce Negotiation Support flag */
PTS_PROTO_CAPS_D = (1<<2),
/** Verification Support flag */
PTS_PROTO_CAPS_V = (1<<3),
/** Current (In-Memory) Evidence Support flag */
PTS_PROTO_CAPS_C = (1<<4),
};
#include "pts/pts_proto_caps.h"
/**
* Class implementing the TCG PTS Protocol Capabilities Attribute