detect TPM presence on IMC

This commit is contained in:
Andreas Steffen
2011-09-08 12:08:12 +02:00
parent 01e069b675
commit 8c4db12fa0
+45 -23
View File
@@ -44,6 +44,11 @@ struct private_pts_t {
*/
pts_meas_algorithms_t algorithm;
/**
* Do we have an activated TPM
*/
bool has_tpm;
/**
* Contains a TPM_CAP_VERSION_INFO struct
*/
@@ -117,13 +122,39 @@ static void print_tpm_version_info(private_pts_t *this)
METHOD(pts_t, get_tpm_version_info, bool,
private_pts_t *this, chunk_t *info)
{
if (!this->has_tpm)
{
return FALSE;
}
*info = this->tpm_version_info;
print_tpm_version_info(this);
return TRUE;
}
METHOD(pts_t, set_tpm_version_info, void,
private_pts_t *this, chunk_t info)
{
this->tpm_version_info = chunk_clone(info);
print_tpm_version_info(this);
}
METHOD(pts_t, destroy, void,
private_pts_t *this)
{
free(this->tpm_version_info.ptr);
free(this);
}
/**
* Check for a TPM by querying for TPM Version Info
*/
static bool has_tpm(private_pts_t *this)
{
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
if (!this->tpm_version_info.ptr)
{
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS)
{
@@ -147,30 +178,13 @@ METHOD(pts_t, get_tpm_version_info, bool,
goto err;
}
this->tpm_version_info = chunk_clone(this->tpm_version_info);
}
*info = this->tpm_version_info;
print_tpm_version_info(this);
return TRUE;
err:
DBG1(DBG_TNC, "could not get tpm version info: tss error 0x%x", result);
DBG1(DBG_TNC, "TPM not available: tss error 0x%x", result);
return FALSE;
}
METHOD(pts_t, set_tpm_version_info, void,
private_pts_t *this, chunk_t info)
{
this->tpm_version_info = chunk_clone(info);
print_tpm_version_info(this);
}
METHOD(pts_t, destroy, void,
private_pts_t *this)
{
free(this->tpm_version_info.ptr);
free(this);
}
/**
* See header
*/
@@ -188,13 +202,21 @@ pts_t *pts_create(bool is_imc)
.set_tpm_version_info = _set_tpm_version_info,
.destroy = _destroy,
},
.proto_caps = PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_C,
.proto_caps = PTS_PROTO_CAPS_V,
.algorithm = PTS_MEAS_ALGO_SHA256,
);
if (!is_imc)
if (is_imc)
{
this->proto_caps |= PTS_PROTO_CAPS_V;
if (has_tpm(this))
{
this->has_tpm = TRUE;
this->proto_caps |= PTS_PROTO_CAPS_T;
}
}
else
{
this->proto_caps |= PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_C;
}
return &this->public;