moved TSS into pts object

This commit is contained in:
Andreas Steffen
2011-09-08 12:08:12 +02:00
parent 48f04107ea
commit 8a2482c7c2
11 changed files with 287 additions and 87 deletions
@@ -7,7 +7,7 @@ AM_CFLAGS = -rdynamic
imcv_LTLIBRARIES = imc-attestation.la
imc_attestation_la_LIBADD = $(top_builddir)/src/libimcv/libimcv.la \
$(top_builddir)/src/libstrongswan/libstrongswan.la -ltspi
$(top_builddir)/src/libstrongswan/libstrongswan.la
imc_attestation_la_SOURCES = imc_attestation.c \
imc_attestation_state.h imc_attestation_state.c
@@ -20,6 +20,7 @@
#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>
@@ -42,10 +43,6 @@
#include <dirent.h>
#include <errno.h>
#include <trousers/tss.h>
#include <trousers/trousers.h>
/* IMC definitions */
static const char imc_name[] = "Attestation";
@@ -151,45 +148,13 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
}
}
/**
* Get the TPM Version Information
*/
static TSS_RESULT get_tpm_version_info(chunk_t *info)
{
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
/* TODO: Needed for parsing version info on IMV side */
//TPM_CAP_VERSION_INFO versionInfo;
//UINT64 offset = 0;
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS)
{
return result;
}
result = Tspi_Context_Connect(hContext, NULL);
if (result != TSS_SUCCESS)
{
return result;
}
result = Tspi_Context_GetTpmObject (hContext, &hTPM);
if (result != TSS_SUCCESS)
{
return result;
}
result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_VERSION_VAL, 0, NULL,
&info->len, &info->ptr);
return result;
}
/**
* Get Hash Measurement of a file
*/
static TNC_Result hash_file(char *path, char *out)
{
BYTE buffer[IMC_ATTESTATION_BUF_SIZE];
char buffer[IMC_ATTESTATION_BUF_SIZE];
FILE *file;
int bytes_read;
hasher_t *hasher;
@@ -289,7 +254,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
/* Switch on the attribute type IMC has received */
switch (handshake_state)
{
case IMC_ATTESTATION_STATE_REQ_PROTO_CAP:
case IMC_ATTESTATION_STATE_REQ_PROTO_CAPS:
{
pts_proto_caps_flag_t flags;
if(proto_caps & PTS_PROTO_CAPS_T)
@@ -310,16 +275,14 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
}
case IMC_ATTESTATION_STATE_GET_TPM_INFO:
{
TSS_RESULT result;
chunk_t tpm_version_info;
pts_t *pts;
result = get_tpm_version_info(&tpm_version_info);
if (result != TSS_SUCCESS)
pts = attestation_state->get_pts(attestation_state);
if (!pts->get_tpm_version_info(pts, &tpm_version_info))
{
DBG1(DBG_IMC,"Error 0x%x on get_tpm_version_info\n", result);
return TNC_RESULT_FATAL;
/* TODO return TCG_PTS_TPM_VERS_NOT_SUPPORTED error attribute */
}
attr = tcg_pts_attr_tpm_version_info_create(tpm_version_info);
break;
}
@@ -535,7 +498,7 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
proto_caps = attr_req_proto_caps->get_flags(attr_req_proto_caps);
attestation_state->set_handshake_state(attestation_state,
IMC_ATTESTATION_STATE_REQ_PROTO_CAP);
IMC_ATTESTATION_STATE_REQ_PROTO_CAPS);
break;
}
case TCG_PTS_MEAS_ALGO:
@@ -44,6 +44,11 @@ struct private_imc_attestation_state_t {
*/
imc_attestation_handshake_state_t handshake_state;
/**
* PTS object
*/
pts_t *pts;
};
METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
@@ -61,6 +66,7 @@ METHOD(imc_state_t, change_state, void,
METHOD(imc_state_t, destroy, void,
private_imc_attestation_state_t *this)
{
this->pts->destroy(this->pts);
free(this);
}
@@ -71,11 +77,18 @@ METHOD(imc_attestation_state_t, get_handshake_state, imc_attestation_handshake_s
}
METHOD(imc_attestation_state_t, set_handshake_state, void,
private_imc_attestation_state_t *this, imc_attestation_handshake_state_t new_state)
private_imc_attestation_state_t *this,
imc_attestation_handshake_state_t new_state)
{
this->handshake_state = new_state;
}
METHOD(imc_attestation_state_t, get_pts, pts_t*,
private_imc_attestation_state_t *this)
{
return this->pts;
}
/**
* Described in header.
*/
@@ -92,10 +105,12 @@ imc_state_t *imc_attestation_state_create(TNC_ConnectionID connection_id)
},
.get_handshake_state = _get_handshake_state,
.set_handshake_state = _set_handshake_state,
.get_pts = _get_pts,
},
.state = TNC_CONNECTION_STATE_CREATE,
.connection_id = connection_id,
.state = TNC_CONNECTION_STATE_CREATE,
.handshake_state = IMC_ATTESTATION_STATE_INIT,
.pts = pts_create(),
);
return &this->public.interface;
@@ -23,6 +23,7 @@
#define IMC_ATTESTATION_STATE_H_
#include <imc/imc_state.h>
#include <tcg/pts/pts.h>
#include <library.h>
typedef struct imc_attestation_state_t imc_attestation_state_t;
@@ -33,7 +34,7 @@ typedef enum imc_attestation_handshake_state_t imc_attestation_handshake_state_t
*/
enum imc_attestation_handshake_state_t {
IMC_ATTESTATION_STATE_INIT,
IMC_ATTESTATION_STATE_REQ_PROTO_CAP,
IMC_ATTESTATION_STATE_REQ_PROTO_CAPS,
IMC_ATTESTATION_STATE_REQ_MEAS_ALGO,
IMC_ATTESTATION_STATE_GET_TPM_INFO,
IMC_ATTESTATION_STATE_GET_AIK,
@@ -55,24 +56,33 @@ struct imc_attestation_state_t {
imc_state_t interface;
/**
* get state of the handshake
* Get state of the handshake
*
* @return the handshake state of IMC
* @return the handshake state of IMC
*/
imc_attestation_handshake_state_t (*get_handshake_state)(imc_attestation_state_t *this);
/**
* get state of the handshake
* Set state of the handshake
*
* @param new_state the handshake state of IMC
*/
void (*set_handshake_state)(imc_attestation_state_t *this, imc_attestation_handshake_state_t new_state);
void (*set_handshake_state)(imc_attestation_state_t *this,
imc_attestation_handshake_state_t new_state);
/**
* Get the PTS object
*
* @return PTS object
*/
pts_t* (*get_pts)(imc_attestation_state_t *this);
};
/**
* Create an imc_attestation_state_t instance
*
* @param id connection ID
* @param id connection ID
*/
imc_state_t* imc_attestation_state_create(TNC_ConnectionID id);
@@ -7,7 +7,7 @@ AM_CFLAGS = -rdynamic
imcv_LTLIBRARIES = imv-attestation.la
imv_attestation_la_LIBADD = $(top_builddir)/src/libimcv/libimcv.la \
$(top_builddir)/src/libstrongswan/libstrongswan.la -ltspi
$(top_builddir)/src/libstrongswan/libstrongswan.la
imv_attestation_la_SOURCES = imv_attestation.c \
imv_attestation_state.h imv_attestation_state.c
@@ -19,8 +19,9 @@
#include <pa_tnc/pa_tnc_msg.h>
#include <ietf/ietf_attr.h>
#include <ietf/ietf_attr_pa_tnc_error.h>
#include <tcg/tcg_attr.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>
#include <tcg/tcg_pts_attr_get_tpm_version_info.h>
@@ -40,9 +41,6 @@
#include <debug.h>
#include <utils/linked_list.h>
#include <trousers/tss.h>
#include <trousers/trousers.h>
/* IMV definitions */
static const char imv_name[] = "Attestation";
@@ -250,7 +248,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
break;
}
case IMV_ATTESTATION_STATE_PROTO_CAP:
case IMV_ATTESTATION_STATE_PROTO_CAPS:
{
/* Send Measurement Algorithms attribute */
attr = tcg_pts_attr_meas_algo_create(supported_algorithms, FALSE);
@@ -428,7 +426,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
proto_caps = attr_proto_caps->get_flags(attr_proto_caps);
/* TODO: What to do with the protocol capabilities from imc */
attestation_state->set_handshake_state(attestation_state,
IMV_ATTESTATION_STATE_PROTO_CAP);
IMV_ATTESTATION_STATE_PROTO_CAPS);
break;
}
case TCG_PTS_MEAS_ALGO_SELECTION:
@@ -457,27 +455,12 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
{
tcg_pts_attr_tpm_version_info_t *attr_tpm;
chunk_t tpm_version_info;
TSS_RESULT result;
TPM_CAP_VERSION_INFO versionInfo;
UINT64 offset = 0;
pts_t *pts;
attr_tpm = (tcg_pts_attr_tpm_version_info_t*)attr;
tpm_version_info = attr_tpm->get_tpm_version_info(attr_tpm);
result = Trspi_UnloadBlob_CAP_VERSION_INFO(&offset,
tpm_version_info.ptr, &versionInfo);
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMV, "TSS Error 0x%x", result);
return TNC_RESULT_FATAL;
}
DBG2(DBG_IMV, "TPM 1.2 Version Info: "
"Chip Version: %hhu.%hhu.%hhu.%hhu, "
"Spec Level: %hu, Errata Rev: %hhu, Vendor ID: %.4s",
versionInfo.version.major, versionInfo.version.minor,
versionInfo.version.revMajor, versionInfo.version.revMinor,
versionInfo.specLevel, versionInfo.errataRev,
versionInfo.tpmVendorID);
pts = attestation_state->get_pts(attestation_state);
pts->set_tpm_version_info(pts, tpm_version_info);
attestation_state->set_handshake_state(attestation_state,
IMV_ATTESTATION_STATE_TPM_INFO);
@@ -54,6 +54,12 @@ struct private_imv_attestation_state_t {
* IMV evaluation result
*/
TNC_IMV_Evaluation_Result eval;
/**
* PTS object
*/
pts_t *pts;
};
typedef struct entry_t entry_t;
@@ -150,6 +156,7 @@ METHOD(imv_state_t, get_reason_string, bool,
METHOD(imv_state_t, destroy, void,
private_imv_attestation_state_t *this)
{
this->pts->destroy(this->pts);
free(this);
}
@@ -165,6 +172,12 @@ METHOD(imv_attestation_state_t, set_handshake_state, void,
this->handshake_state = new_state;
}
METHOD(imv_attestation_state_t, get_pts, pts_t*,
private_imv_attestation_state_t *this)
{
return this->pts;
}
/**
* Described in header.
*/
@@ -184,12 +197,14 @@ imv_state_t *imv_attestation_state_create(TNC_ConnectionID connection_id)
},
.get_handshake_state = _get_handshake_state,
.set_handshake_state = _set_handshake_state,
.get_pts = _get_pts,
},
.connection_id = connection_id,
.state = TNC_CONNECTION_STATE_CREATE,
.handshake_state = IMV_ATTESTATION_STATE_INIT,
.rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
.eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
.connection_id = connection_id,
.pts = pts_create(),
);
return &this->public.interface;
@@ -23,6 +23,7 @@
#define IMV_ATTESTATION_STATE_H_
#include <imv/imv_state.h>
#include <tcg/pts/pts.h>
#include <library.h>
typedef struct imv_attestation_state_t imv_attestation_state_t;
@@ -33,7 +34,7 @@ typedef enum imv_attestation_handshake_state_t imv_attestation_handshake_state_t
*/
enum imv_attestation_handshake_state_t {
IMV_ATTESTATION_STATE_INIT,
IMV_ATTESTATION_STATE_PROTO_CAP,
IMV_ATTESTATION_STATE_PROTO_CAPS,
IMV_ATTESTATION_STATE_MEAS_ALGO,
IMV_ATTESTATION_STATE_TPM_INFO,
IMV_ATTESTATION_STATE_AIK,
@@ -55,24 +56,33 @@ struct imv_attestation_state_t {
imv_state_t interface;
/**
* get state of the handshake
* Get state of the handshake
*
* @return the handshake state of IMV
* @return the handshake state of IMV
*/
imv_attestation_handshake_state_t (*get_handshake_state)(imv_attestation_state_t *this);
/**
* get state of the handshake
* Set state of the handshake
*
* @param new_state the handshake state of IMV
*/
void (*set_handshake_state)(imv_attestation_state_t *this, imv_attestation_handshake_state_t new_state);
void (*set_handshake_state)(imv_attestation_state_t *this,
imv_attestation_handshake_state_t new_state);
/**
* Get the PTS object
*
* @return PTS object
*/
pts_t* (*get_pts)(imv_attestation_state_t *this);
};
/**
* Create an imv_attestation_state_t instance
*
* @param id connection ID
* @param id connection ID
*/
imv_state_t* imv_attestation_state_create(TNC_ConnectionID id);