refactored simple component evidence

This commit is contained in:
Andreas Steffen
2011-11-28 21:22:01 +01:00
parent 21b4efc097
commit cb3ecd5aa5
15 changed files with 851 additions and 839 deletions
+101 -10
View File
@@ -17,7 +17,6 @@
#include "ita_comp_tboot.h"
#include "ita_comp_func_name.h"
#include "pts/pts_func_comp_evid_req.h"
#include "pts/components/pts_component.h"
#include <debug.h>
@@ -32,7 +31,7 @@ typedef struct pts_ita_comp_tboot_t pts_ita_comp_tboot_t;
struct pts_ita_comp_tboot_t {
/**
* Public pts_component_manager_t interface.
* Public pts_component_t interface.
*/
pts_component_t public;
@@ -40,6 +39,17 @@ struct pts_ita_comp_tboot_t {
* Component Functional Name
*/
pts_comp_func_name_t *name;
/**
* Extended PCR last handled
*/
u_int32_t extended_pcr;
/**
* Time of TBOOT measurement
*/
time_t measurement_time;
};
METHOD(pts_component_t, get_comp_func_name, pts_comp_func_name_t*,
@@ -54,18 +64,99 @@ METHOD(pts_component_t, get_evidence_flags, u_int8_t,
return PTS_REQ_FUNC_COMP_FLAG_PCR;
}
METHOD(pts_component_t, measure, bool,
pts_ita_comp_tboot_t *this)
METHOD(pts_component_t, measure, status_t,
pts_ita_comp_tboot_t *this, pts_t *pts, pts_comp_evidence_t **evidence)
{
/* TODO measure the tboot functional component */
return FALSE;
pts_comp_evidence_t *evid;
char *meas_hex, *pcr_before_hex, *pcr_after_hex;
chunk_t measurement, pcr_before, pcr_after;
switch (this->extended_pcr)
{
case 0:
/* dummy data since currently the TBOOT log is not retrieved */
time(&this->measurement_time);
meas_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr17_meas", NULL);
pcr_before_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr17_before", NULL);
pcr_after_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr17_after", NULL);
this->extended_pcr = PCR_TBOOT_POLICY;
break;
case PCR_TBOOT_POLICY:
/* dummy data since currently the TBOOT log is not retrieved */
meas_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr18_meas", NULL);
pcr_before_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr18_before", NULL);
pcr_after_hex = lib->settings->get_str(lib->settings,
"libimcv.plugins.imc-attestation.pcr18_after", NULL);
this->extended_pcr = PCR_TBOOT_MLE;
break;
default:
return FAILED;
}
measurement = chunk_from_hex(
chunk_create(meas_hex, strlen(meas_hex)), NULL);
pcr_before = chunk_from_hex(
chunk_create(pcr_before_hex, strlen(pcr_before_hex)), NULL);
pcr_after = chunk_from_hex(
chunk_create(pcr_after_hex, strlen(pcr_after_hex)), NULL);
evid = *evidence = pts_comp_evidence_create(this->name, 0,
this->extended_pcr,
PTS_MEAS_ALGO_SHA1, PTS_PCR_TRANSFORM_NO,
this->measurement_time, measurement);
evid->set_pcr_info(evid, pcr_before, pcr_after);
return (this->extended_pcr == PCR_TBOOT_MLE) ? SUCCESS : NEED_MORE;
}
METHOD(pts_component_t, verify, bool,
pts_ita_comp_tboot_t *this)
METHOD(pts_component_t, verify, status_t,
pts_ita_comp_tboot_t *this, pts_t *pts, pts_database_t *pts_db,
pts_comp_evidence_t *evidence)
{
/* TODO verify the measurement of the tboot functional component */
return FALSE;
bool has_pcr_info;
u_int32_t extended_pcr;
pts_meas_algorithms_t algo;
pts_pcr_transform_t transform;
time_t measurement_time;
chunk_t measurement, pcr_before, pcr_after;
pcr_entry_t *entry;
switch (this->extended_pcr)
{
case 0:
this->extended_pcr = PCR_TBOOT_POLICY;
break;
case PCR_TBOOT_POLICY:
this->extended_pcr = PCR_TBOOT_MLE;
break;
default:
return FAILED;
}
measurement = evidence->get_measurement(evidence, &extended_pcr,
&algo, &transform, &measurement_time);
if (extended_pcr != this->extended_pcr)
{
return FAILED;
}
/* TODO check measurement in database */
has_pcr_info = evidence->get_pcr_info(evidence, &pcr_before, &pcr_after);
if (has_pcr_info)
{
entry = malloc_thing(pcr_entry_t);
entry->pcr_number = extended_pcr;
memcpy(entry->pcr_value, pcr_after.ptr, PCR_LEN);
pts->add_pcr_entry(pts, entry);
}
return (this->extended_pcr == PCR_TBOOT_MLE) ? SUCCESS : NEED_MORE;
}
METHOD(pts_component_t, destroy, void,
+60 -10
View File
@@ -17,7 +17,6 @@
#include "ita_comp_tgrub.h"
#include "ita_comp_func_name.h"
#include "pts/pts_func_comp_evid_req.h"
#include "pts/components/pts_component.h"
#include <debug.h>
@@ -32,7 +31,7 @@ typedef struct pts_ita_comp_tgrub_t pts_ita_comp_tgrub_t;
struct pts_ita_comp_tgrub_t {
/**
* Public pts_component_manager_t interface.
* Public pts_component_t interface.
*/
pts_component_t public;
@@ -54,18 +53,69 @@ METHOD(pts_component_t, get_evidence_flags, u_int8_t,
return PTS_REQ_FUNC_COMP_FLAG_PCR;
}
METHOD(pts_component_t, measure, bool,
pts_ita_comp_tgrub_t *this)
METHOD(pts_component_t, measure, status_t,
pts_ita_comp_tgrub_t *this, pts_t *pts, pts_comp_evidence_t **evidence)
{
/* TODO measure the tgrub functional component */
return FALSE;
pts_comp_evidence_t *evid;
u_int32_t extended_pcr;
time_t measurement_time;
chunk_t measurement, pcr_before, pcr_after;
/* Provisional implementation for TGRUB */
extended_pcr = PCR_DEBUG;
time(&measurement_time);
if (!pts->read_pcr(pts, extended_pcr, &pcr_after))
{
DBG1(DBG_PTS, "error occured while reading PCR: %d", extended_pcr);
return FAILED;
}
measurement = chunk_alloc(HASH_SIZE_SHA1);
memset(measurement.ptr, 0x00, measurement.len);
pcr_before = chunk_alloc(PCR_LEN);
memset(pcr_before.ptr, 0x00, pcr_before.len);
evid = *evidence = pts_comp_evidence_create(this->name, 0, extended_pcr,
PTS_MEAS_ALGO_SHA1, PTS_PCR_TRANSFORM_NO,
measurement_time, measurement);
evid->set_pcr_info(evid, pcr_before, pcr_after);
return SUCCESS;
}
METHOD(pts_component_t, verify, bool,
pts_ita_comp_tgrub_t *this)
METHOD(pts_component_t, verify, status_t,
pts_ita_comp_tgrub_t *this, pts_t *pts, pts_database_t *pts_db,
pts_comp_evidence_t *evidence)
{
/* TODO verify the measurement of the tgrub functional component */
return FALSE;
bool has_pcr_info;
u_int32_t extended_pcr;
pts_meas_algorithms_t algo;
pts_pcr_transform_t transform;
time_t measurement_time;
chunk_t measurement, pcr_before, pcr_after;
pcr_entry_t *entry;
measurement = evidence->get_measurement(evidence, &extended_pcr,
&algo, &transform, &measurement_time);
if (extended_pcr != PCR_DEBUG)
{
return FAILED;
}
/* TODO check measurement in database */
has_pcr_info = evidence->get_pcr_info(evidence, &pcr_before, &pcr_after);
if (has_pcr_info)
{
entry = malloc_thing(pcr_entry_t);
entry->pcr_number = extended_pcr;
memcpy(entry->pcr_value, pcr_after.ptr, PCR_LEN);
pts->add_pcr_entry(pts, entry);
}
return SUCCESS;
}
METHOD(pts_component_t, destroy, void,
@@ -0,0 +1,225 @@
/*
* Copyright (C) 2011 Sansar Choinyambuu, Andreas Steffen
* 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 "pts/components/pts_comp_evidence.h"
#include <debug.h>
typedef struct private_pts_comp_evidence_t private_pts_comp_evidence_t;
/**
* Private data of a pts_comp_evidence_t object.
*/
struct private_pts_comp_evidence_t {
/**
* Public pts_comp_evidence_t interface.
*/
pts_comp_evidence_t public;
/**
* Component Functional Name
*/
pts_comp_func_name_t *name;
/**
* Sub-Component Depth
*/
u_int32_t depth;
/**
* Measurement Time
*/
time_t measurement_time;
/**
* Measurement Time
*/
chunk_t measurement;
/**
* Measurement Hash Algorithm
*/
pts_meas_algorithms_t hash_algorithm;
/**
* Is PCR Information included?
*/
bool has_pcr_info;
/**
* PCR the measurement was extended into
*/
u_int32_t extended_pcr;
/**
* PCR value before extension
*/
chunk_t pcr_before;
/**
* PCR value after extension
*/
chunk_t pcr_after;
/**
* Transformation used for extending measurement into PCR
*/
pts_pcr_transform_t transform;
/**
* Component Validation Result
*/
pts_comp_evid_validation_t validation;
/**
* Verification Policy URI
*/
chunk_t policy_uri;
};
METHOD(pts_comp_evidence_t, get_comp_func_name, pts_comp_func_name_t*,
private_pts_comp_evidence_t *this, u_int32_t *depth)
{
if (depth)
{
*depth = this->depth;
}
return this->name;
}
METHOD(pts_comp_evidence_t, get_extended_pcr, u_int32_t,
private_pts_comp_evidence_t *this)
{
return this->extended_pcr;
}
METHOD(pts_comp_evidence_t, get_measurement, chunk_t,
private_pts_comp_evidence_t *this, u_int32_t *extended_pcr,
pts_meas_algorithms_t *algo, pts_pcr_transform_t *transform,
time_t *measurement_time)
{
if (extended_pcr)
{
*extended_pcr = this->extended_pcr;
}
if (algo)
{
*algo = this->hash_algorithm;
}
if (transform)
{
*transform = this->transform;
}
if (measurement_time)
{
*measurement_time = this->measurement_time;
}
return this->measurement;
}
METHOD(pts_comp_evidence_t, get_pcr_info, bool,
private_pts_comp_evidence_t *this, chunk_t *pcr_before, chunk_t *pcr_after)
{
if (pcr_before)
{
*pcr_before = this->pcr_before;
}
if (pcr_after)
{
*pcr_after = this->pcr_after;
}
return this->has_pcr_info;
}
METHOD(pts_comp_evidence_t, set_pcr_info, void,
private_pts_comp_evidence_t *this, chunk_t pcr_before, chunk_t pcr_after)
{
this->has_pcr_info = TRUE;
this->pcr_before = pcr_before;
this->pcr_after = pcr_after;
DBG2(DBG_PTS, "PCR %2d before value : %#B", this->extended_pcr, &pcr_before);
DBG2(DBG_PTS, "PCR %2d after value : %#B", this->extended_pcr, &pcr_after);
}
METHOD(pts_comp_evidence_t, get_validation, pts_comp_evid_validation_t,
private_pts_comp_evidence_t *this, chunk_t *uri)
{
if (uri)
{
*uri = this->policy_uri;
}
return this->validation;
}
METHOD(pts_comp_evidence_t, set_validation, void,
private_pts_comp_evidence_t *this, pts_comp_evid_validation_t validation,
chunk_t uri)
{
this->validation = validation;
this->policy_uri = chunk_clone(uri);
}
METHOD(pts_comp_evidence_t, destroy, void,
private_pts_comp_evidence_t *this)
{
this->name->destroy(this->name);
free(this->measurement.ptr);
free(this->pcr_before.ptr);
free(this->pcr_after.ptr);
free(this->policy_uri.ptr);
free(this);
}
/**
* See header
*/
pts_comp_evidence_t *pts_comp_evidence_create(pts_comp_func_name_t *name,
u_int32_t depth,
u_int32_t extended_pcr,
pts_meas_algorithms_t algo,
pts_pcr_transform_t transform,
time_t measurement_time,
chunk_t measurement)
{
private_pts_comp_evidence_t *this;
INIT(this,
.public = {
.get_comp_func_name = _get_comp_func_name,
.get_extended_pcr = _get_extended_pcr,
.get_measurement = _get_measurement,
.get_pcr_info = _get_pcr_info,
.set_pcr_info = _set_pcr_info,
.get_validation = _get_validation,
.set_validation = _set_validation,
.destroy = _destroy,
},
.name = name->clone(name),
.depth = depth,
.extended_pcr = extended_pcr,
.hash_algorithm = algo,
.transform = transform,
.measurement_time = measurement_time,
.measurement = measurement,
);
name->log(name, "");
DBG2(DBG_PTS, "PCR %2d extended with: %#B", extended_pcr, &measurement);
return &this->public;
}
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2011 Sansar Choinyambuu, Andreas Steffen
* 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 pts_comp_evidence pts_comp_evidence
* @{ @ingroup pts
*/
#ifndef PTS_COMP_EVIDENCE_H_
#define PTS_COMP_EVIDENCE_H_
typedef struct pts_comp_evidence_t pts_comp_evidence_t;
typedef enum pts_pcr_transform_t pts_pcr_transform_t;
typedef enum pts_comp_evid_validation_t pts_comp_evid_validation_t;
#include "pts/pts_meas_algo.h"
#include "pts/components/pts_comp_func_name.h"
#include <library.h>
/**
* PTS PCR Transformations
*/
enum pts_pcr_transform_t {
/** No Transformation */
PTS_PCR_TRANSFORM_NO = 0,
/** Hash Value matched PCR size */
PTS_PCR_TRANSFORM_MATCH = 1,
/** Hash value shorter than PCR size */
PTS_PCR_TRANSFORM_SHORT = 2,
/** Hash value longer than PCR size */
PTS_PCR_TRANSFORM_LONG = 3,
};
/**
* PTS Component Evidence Validation Result Flags
*/
enum pts_comp_evid_validation_t {
/** No Validation was attempted */
PTS_COMP_EVID_VALIDATION_NONE = 0x00,
/** Attempted validation, unable to verify */
PTS_COMP_EVID_VALIDATION_UNABLE = 0x20,
/** Attempted validation, verification failed */
PTS_COMP_EVID_VALIDATION_FAILED = 0x40,
/** Attempted validation, verification passed */
PTS_COMP_EVID_VALIDATION_PASSED = 0x60,
};
/**
* PTS Functional Component Interface
*/
struct pts_comp_evidence_t {
/**
* Gets the Component Functional Name and Sub-Component Depth
*
* @param depth Sub-Component Depth
* @result Component Functional Name
*/
pts_comp_func_name_t* (*get_comp_func_name)(pts_comp_evidence_t *this,
u_int32_t *depth);
/**
* Gets the PCR the measurement was extended into
*
* @result PCR the measurement was extended into
*/
u_int32_t (*get_extended_pcr)(pts_comp_evidence_t *this);
/**
* Gets the measurement and the algorithms used
*
* @param extended_pcr PCR the measurement was extended into
* @param algo Measurement hash algorithm
* @param transform Transformation used for PCR extension
* @param measurement_time Time the measurement was taken
* @result Measurement hash value
*/
chunk_t (*get_measurement)(pts_comp_evidence_t *this,
u_int32_t *extended_pcr,
pts_meas_algorithms_t *algo,
pts_pcr_transform_t *transform,
time_t *measurement_time);
/**
* Gets the PCR information if available
*
* @param pcr_before PCR value before extension
* @param pcr_after PCR value after extension
* @result TRUE if PCR information is available
*/
bool (*get_pcr_info)(pts_comp_evidence_t *this, chunk_t *pcr_before,
chunk_t *pcr_after);
/**
* Sets PCR information if available
*
* @param pcr_before PCR value before extension
* @param pcr_after PCR value after extension
*/
void (*set_pcr_info)(pts_comp_evidence_t *this, chunk_t pcr_before,
chunk_t pcr_after);
/**
* Gets Validation Result if available
*
* @param uri Verification Policy URI
* @return validation Validation Result
*/
pts_comp_evid_validation_t (*get_validation)(pts_comp_evidence_t *this,
chunk_t *uri);
/**
* Sets Validation Result if available
*
* @param validation Validation Result
* @param uri Verification Policy URI
*/
void (*set_validation)(pts_comp_evidence_t *this,
pts_comp_evid_validation_t validation, chunk_t uri);
/**
* Destroys a pts_comp_evidence_t object.
*/
void (*destroy)(pts_comp_evidence_t *this);
};
/**
* Creates a pts_comp_evidence_t object
*
* @param name Component Functional Name
* @param depth Sub-component depth
* @param extended_pcr PCR the measurement was extended into
* @param algo Measurement hash algorithm
* @param transform Transformation used for PCR extension
* @param measurement_time Time the measurement was taken, 0 if unknown
* @param measurement Measurement hash value
*/
pts_comp_evidence_t* pts_comp_evidence_create(pts_comp_func_name_t *name,
u_int32_t depth,
u_int32_t extended_pcr,
pts_meas_algorithms_t algo,
pts_pcr_transform_t transform,
time_t measurement_time,
chunk_t measurement);
#endif /** PTS_COMP_EVIDENCE_H_ @}*/
+17 -6
View File
@@ -23,7 +23,10 @@
typedef struct pts_component_t pts_component_t;
#include "pts/pts.h"
#include "pts/pts_database.h"
#include "pts/components/pts_comp_func_name.h"
#include "pts/components/pts_comp_evidence.h"
#include <library.h>
@@ -47,18 +50,26 @@ struct pts_component_t {
u_int8_t (*get_evidence_flags)(pts_component_t *this);
/**
* Do measurements on the PTS Functional Component
* Do evidence measurements on the PTS Functional Component
*
* @return TRUE if component measurements are successful
* @param pts PTS interface
* @param evidence returns component evidence measureemt
* @return status return code
*/
bool (*measure)(pts_component_t *this);
status_t (*measure)(pts_component_t *this, pts_t *pts,
pts_comp_evidence_t** evidence);
/**
* Verify the measurements of the PTS Functional Component
* Verify the evidence measurements of the PTS Functional Component
*
* @return TRUE if verification is successful
* @param pts PTS interface
* @param pts_db PTS measurement database
* @param evidence component evidence measurement to be verified
* @return status return code
*/
bool (*verify)(pts_component_t *this);
status_t (*verify)(pts_component_t *this, pts_t *pts,
pts_database_t *pts_db,
pts_comp_evidence_t *evidence);
/**
* Destroys a pts_component_t object.