Merged PR 1405: Include event ID and versioning to TCG event data

Related work items: #622, #627
This commit is contained in:
Van Bui 2020-07-22 19:42:31 +00:00 коммит произвёл Chris Weimer
Родитель 7e2b7ac5ec
Коммит 5b89c62d30
14 изменённых файлов: 13847 добавлений и 189 удалений

Просмотреть файл

@ -9,6 +9,146 @@
#include "pcr.h"
/**
* Common function to update digest in PCR bank's list of measurements
*
* @param pcr PCR bank to update
* @param measurement_index The index of measurement being updated
* @param digest Buffer holding digest to add
* @param digest_len Length of digest buffer
* @param measurement_config Indicates data included in measurement calculation
* @param version Version to associate with the measurement data
*
* @return 0 if successful or an error code
*/
static int pcr_update_digest_common (struct pcr_bank *pcr, uint8_t measurement_index,
const uint8_t *digest, size_t digest_len, uint8_t measurement_config, uint8_t version)
{
if ((pcr == NULL) || (digest == NULL) || (digest_len == 0)) {
return PCR_INVALID_ARGUMENT;
}
if (digest_len != PCR_DIGEST_LENGTH) {
return PCR_UNSUPPORTED_ALGO;
}
if (measurement_index >= pcr->num_measurements) {
return PCR_INVALID_INDEX;
}
platform_mutex_lock (&pcr->lock);
memcpy (pcr->measurement_list[measurement_index].digest, digest, digest_len);
pcr->measurement_list[measurement_index].measurement_config = measurement_config;
pcr->measurement_list[measurement_index].version = version;
platform_mutex_unlock (&pcr->lock);
return 0;
}
/**
* Common function to compute digest of buffer and update the PCR bank's list of measurements
*
* @param pcr PCR bank to update measurement in
* @param hash Hashing engine to utilize
* @param measurement_index The index of measurement being updated
* @param buf Buffer holding data to compute measurement of
* @param buf_len Length of data buffer
* @param include_event Flag that indicates whether to include the event type in measurement
* calculations
* @param include_version Flag that indicates whether to include the version in measurement
* calculations
* @param version The version associated with the measurement data
*
* @return Completion status, 0 if success or an error code
*/
static int pcr_update_buffer_common (struct pcr_bank *pcr, struct hash_engine *hash,
uint8_t measurement_index, const uint8_t *buf, size_t buf_len, bool include_event,
bool include_version, uint8_t version)
{
uint8_t digest[PCR_DIGEST_LENGTH];
int status;
status = hash->start_sha256 (hash);
if (status != 0) {
return status;
}
if (include_event) {
status = hash->update (hash,
(uint8_t*) &pcr->measurement_list[measurement_index].event_type,
sizeof (pcr->measurement_list[measurement_index].event_type));
if (status != 0) {
goto hash_cancel;
}
}
if (include_version) {
status = hash->update (hash, &version, sizeof (version));
if (status != 0) {
goto hash_cancel;
}
}
status = hash->update (hash, buf, buf_len);
if (status != 0) {
goto hash_cancel;
}
status = hash->finish (hash, digest, sizeof (digest));
if (status != 0) {
goto hash_cancel;
}
if (include_version && include_event) {
return pcr_update_digest_common (pcr, measurement_index, digest, sizeof (digest),
PCR_MEASUREMENT_FLAG_VERSION | PCR_MEASUREMENT_FLAG_EVENT, version);
}
else if (include_version && !include_event) {
return pcr_update_digest_common (pcr, measurement_index, digest, sizeof (digest),
PCR_MEASUREMENT_FLAG_VERSION, version);
}
else if (!include_version && include_event) {
return pcr_update_digest_common (pcr, measurement_index, digest, sizeof (digest),
PCR_MEASUREMENT_FLAG_EVENT, 0);
}
else {
return pcr_update_digest_common (pcr, measurement_index, digest, sizeof (digest), 0, 0);
}
hash_cancel:
hash->cancel (hash);
return status;
}
/**
* Read the measurement data bytes and copy the data to the provided buffer
*
* @param buffer Output buffer containing the measured data
* @param buffer_len Maximum length of the buffer
* @param data Buffer storing the measurement data to be read
* @param data_len Size in bytes of the measurement data
* @param offset The offset index to read from
*
* @return total number of bytes read
*/
static int pcr_read_measurement_data_bytes (uint8_t *buffer, size_t buffer_len, const uint8_t *data,
size_t data_len, size_t offset)
{
int bytes_read;
if ((buffer_len == 0) || (offset > data_len - 1)) {
return 0;
}
bytes_read = ((data_len - offset) > buffer_len) ? buffer_len : (data_len - offset);
memcpy (buffer, data + offset, bytes_read);
return bytes_read;
}
/**
* Initialize PCR bank to support the required number of measurements
*
@ -86,7 +226,7 @@ int pcr_check_measurement_index (struct pcr_bank *pcr, uint8_t measurement_index
}
/**
* Update digest in PCR bank's list of measurements
* Update digest in PCR bank's list of measurements and reset measurement configuration
*
* @param pcr PCR bank to update
* @param measurement_index The index of measurement being updated
@ -98,25 +238,7 @@ int pcr_check_measurement_index (struct pcr_bank *pcr, uint8_t measurement_index
int pcr_update_digest (struct pcr_bank *pcr, uint8_t measurement_index, const uint8_t *digest,
size_t digest_len)
{
if ((pcr == NULL) || (digest == NULL) || (digest_len == 0)) {
return PCR_INVALID_ARGUMENT;
}
if (digest_len != PCR_DIGEST_LENGTH) {
return PCR_UNSUPPORTED_ALGO;
}
if (measurement_index >= pcr->num_measurements) {
return PCR_INVALID_INDEX;
}
platform_mutex_lock (&pcr->lock);
memcpy (pcr->measurement_list[measurement_index].digest, digest, digest_len);
platform_mutex_unlock (&pcr->lock);
return 0;
return pcr_update_digest_common (pcr, measurement_index, digest, digest_len, 0, 0);
}
/**
@ -127,25 +249,46 @@ int pcr_update_digest (struct pcr_bank *pcr, uint8_t measurement_index, const ui
* @param measurement_index The index of measurement being updated
* @param buf Buffer holding data to compute measurement of
* @param buf_len Length of data buffer
* @param include_event Flag that indicates whether to include the event type in measurement
* calculations
*
* @return Completion status, 0 if success or an error code
*/
int pcr_update_buffer (struct pcr_bank *pcr, struct hash_engine *hash, uint8_t measurement_index,
const uint8_t *buf, size_t buf_len)
const uint8_t *buf, size_t buf_len, bool include_event)
{
uint8_t digest[PCR_DIGEST_LENGTH];
int status;
if ((pcr == NULL) || (buf == NULL) || (buf_len == 0) || (hash == NULL)) {
return PCR_INVALID_ARGUMENT;
}
status = hash->calculate_sha256 (hash, buf, buf_len, digest, sizeof (digest));
if (status != 0) {
return status;
return pcr_update_buffer_common (pcr, hash, measurement_index, buf, buf_len, include_event,
false, 0);
}
/**
* Compute digest of versioned buffer and update the PCR bank's list of measurements
*
* @param pcr PCR bank to update measurement in
* @param hash Hashing engine to utilize
* @param measurement_index The index of measurement being updated
* @param buf Buffer holding data to compute measurement of
* @param buf_len Length of data buffer
* @param include_event Flag that indicates whether to include the event type in measurement
* calculations
* @param version The version associated with the measurement data
*
* @return Completion status, 0 if success or an error code
*/
int pcr_update_versioned_buffer (struct pcr_bank *pcr, struct hash_engine *hash,
uint8_t measurement_index, const uint8_t *buf, size_t buf_len, bool include_event,
uint8_t version)
{
if ((pcr == NULL) || (buf == NULL) || (buf_len == 0) || (hash == NULL)) {
return PCR_INVALID_ARGUMENT;
}
return pcr_update_digest (pcr, measurement_index, digest, sizeof (digest));
return pcr_update_buffer_common (pcr, hash, measurement_index, buf, buf_len,
include_event, true, version);
}
/**
@ -153,7 +296,7 @@ int pcr_update_buffer (struct pcr_bank *pcr, struct hash_engine *hash, uint8_t m
*
* @param pcr PCR bank to update measurement in
* @param measurement_index The index of measurement being updated
* @param event_type Event type to associate with measurment
* @param event_type Event type to associate with measurement
*
* @return Completion status, 0 if success or an error code
*/
@ -176,6 +319,30 @@ int pcr_update_event_type (struct pcr_bank *pcr, uint8_t measurement_index, uint
return 0;
}
/**
* Get the event type for a measurement in the PCR bank
*
* @param pcr PCR bank to retrieve measurement data
* @param measurement_index The index of measurement being accessed
* @param event_type Output buffer to store the event type
*
* @return Completion status, 0 if success or an error code
*/
int pcr_get_event_type (struct pcr_bank *pcr, uint8_t measurement_index, uint32_t *event_type)
{
if ((pcr == NULL) || (event_type == NULL)) {
return PCR_INVALID_ARGUMENT;
}
if (measurement_index >= pcr->num_measurements) {
return PCR_INVALID_INDEX;
}
*event_type = pcr->measurement_list[measurement_index].event_type;
return 0;
}
/**
* Compute aggregate of all measurements that have added to PCR bank
*
@ -325,97 +492,130 @@ int pcr_get_measurement_data (struct pcr_bank *pcr, uint8_t measurement_index, s
uint8_t *buffer, size_t length)
{
struct pcr_measured_data *measured_data;
bool include_event;
bool include_version;
size_t bytes_read;
size_t total_bytes = 0;
int status = 0;
if ((pcr == NULL) || (buffer == NULL)) {
return PCR_INVALID_ARGUMENT;
}
if (measurement_index >= pcr->num_measurements) {
return PCR_INVALID_INDEX;
status = PCR_INVALID_INDEX;
goto exit;
}
if (pcr->measurement_list[measurement_index].measured_data == NULL) {
return 0;
}
platform_mutex_lock (&pcr->lock);
measured_data = pcr->measurement_list[measurement_index].measured_data;
if (measured_data == NULL) {
goto exit;
}
include_event = pcr->measurement_list[measurement_index].measurement_config &
PCR_MEASUREMENT_FLAG_EVENT;
include_version = pcr->measurement_list[measurement_index].measurement_config &
PCR_MEASUREMENT_FLAG_VERSION;
if (include_event) {
if (offset < 4) {
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
(uint8_t*) &pcr->measurement_list[measurement_index].event_type, 4, offset);
offset = 0;
length -= bytes_read;
buffer = buffer + bytes_read;
total_bytes += bytes_read;
}
else {
offset -= 4;
}
}
if (include_version) {
if (offset < 1) {
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
&pcr->measurement_list[measurement_index].version, 1, offset);
offset = 0;
length -= bytes_read;
buffer = buffer + bytes_read;
total_bytes += bytes_read;
}
else {
offset -= 1;
}
}
switch (measured_data->type) {
case PCR_DATA_TYPE_1BYTE:
if ((offset > 0) || (length == 0)) {
return 0;
}
*buffer = measured_data->data.value_1byte;
return 1;
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
&measured_data->data.value_1byte, 1, offset);
status = bytes_read + total_bytes;
break;
case PCR_DATA_TYPE_2BYTE:
if (offset > 1) {
return 0;
}
bytes_read = ((2 - offset) > length) ? length : (2 - offset);
memcpy (buffer, (uint8_t*) &measured_data->data.value_2byte + offset, bytes_read);
return bytes_read;
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
(uint8_t*) &measured_data->data.value_2byte, 2, offset);
status = bytes_read + total_bytes;
break;
case PCR_DATA_TYPE_4BYTE:
if (offset > 3) {
return 0;
}
bytes_read = ((4 - offset) > length) ? length : (4 - offset);
memcpy (buffer, (uint8_t*) &measured_data->data.value_4byte + offset, bytes_read);
return bytes_read;
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
(uint8_t*) &measured_data->data.value_4byte, 4, offset);
status = bytes_read + total_bytes;
break;
case PCR_DATA_TYPE_8BYTE:
if (offset > 7) {
return 0;
}
bytes_read = ((8 - offset) > length) ? length : (8 - offset);
memcpy (buffer, (uint8_t*) &measured_data->data.value_8byte + offset, bytes_read);
return bytes_read;
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
(uint8_t*) &measured_data->data.value_8byte, 8, offset);
status = bytes_read + total_bytes;
break;
case PCR_DATA_TYPE_MEMORY:
if (offset > (measured_data->data.memory.length - 1)) {
return 0;
}
bytes_read = ((measured_data->data.memory.length - offset) > length) ?
length : (measured_data->data.memory.length - offset);
memcpy (buffer, &measured_data->data.memory.buffer[offset], bytes_read);
return bytes_read;
bytes_read = pcr_read_measurement_data_bytes (buffer, length,
measured_data->data.memory.buffer, measured_data->data.memory.length, offset);
status = bytes_read + total_bytes;
break;
case PCR_DATA_TYPE_FLASH: {
struct flash *flash_device = measured_data->data.flash.flash;
size_t read_addr = measured_data->data.flash.addr + offset;
int status;
if (offset > (measured_data->data.flash.length - 1)) {
return 0;
status = total_bytes;
break;
}
bytes_read = ((measured_data->data.flash.length - offset) > length ? length :
(measured_data->data.flash.length - offset));
status = flash_device->read (flash_device, read_addr, buffer, bytes_read);
if (status == 0) {
status = bytes_read + total_bytes;
}
return (status == 0 ? bytes_read : status);
break;
}
case PCR_DATA_TYPE_CALLBACK:
return measured_data->data.callback.get_data (measured_data->data.callback.context,
case PCR_DATA_TYPE_CALLBACK: {
status = measured_data->data.callback.get_data (measured_data->data.callback.context,
offset, buffer, length);
if (!ROT_IS_ERROR (status)) {
status = status + total_bytes;
}
break;
}
default:
return PCR_INVALID_DATA_TYPE;
status = PCR_INVALID_DATA_TYPE;
}
exit:
platform_mutex_unlock (&pcr->lock);
return status;
}
/**

Просмотреть файл

@ -13,6 +13,9 @@
#define PCR_DIGEST_LENGTH SHA256_HASH_LENGTH
/* PCR flag to include data in measurement calculations */
#define PCR_MEASUREMENT_FLAG_EVENT (1U << 0)
#define PCR_MEASUREMENT_FLAG_VERSION (1U << 1)
/**
* Container for a PCR measurement
@ -22,6 +25,8 @@ struct pcr_measurement {
uint8_t measurement[PCR_DIGEST_LENGTH]; /**< Aggregated measurement buffer */
struct pcr_measured_data *measured_data; /**< Raw data used for measurement */
uint32_t event_type; /**< TCG event type */
uint8_t version; /**< Version associated with the measurement data */
uint8_t measurement_config; /**< Indicates data to include in measurement calculations */
};
/**
@ -43,8 +48,13 @@ int pcr_check_measurement_index (struct pcr_bank *pcr, uint8_t measurement_index
int pcr_update_digest (struct pcr_bank *pcr, uint8_t measurement_index, const uint8_t *digest,
size_t digest_len);
int pcr_update_buffer (struct pcr_bank *pcr, struct hash_engine *hash, uint8_t measurement_index,
const uint8_t *buf, size_t buf_len);
const uint8_t *buf, size_t buf_len, bool include_event);
int pcr_update_versioned_buffer (struct pcr_bank *pcr, struct hash_engine *hash,
uint8_t measurement_index, const uint8_t *buf, size_t buf_len, bool include_event,
uint8_t version);
int pcr_update_event_type (struct pcr_bank *pcr, uint8_t measurement_index, uint32_t event_type);
int pcr_get_event_type (struct pcr_bank *pcr, uint8_t measurement_index, uint32_t *event_type);
int pcr_compute (struct pcr_bank *pcr, struct hash_engine *hash, uint8_t *measurement, bool lock);
int pcr_get_measurement (struct pcr_bank *pcr, uint8_t measurement_index,

Просмотреть файл

@ -27,7 +27,7 @@ enum pcr_data_type {
*
* @param context The context to query for measured data.
* @param offset The offset to read data from.
* @param buffer Output buffer to filled in with measured data.
* @param buffer Output buffer to be filled in with measured data.
* @param length Maximum length of the buffer
*
* @return length of the measured data if successfully read or an error code.
@ -44,7 +44,7 @@ struct pcr_measured_data {
uint8_t value_1byte; /**< Value for 1 byte measured data type */
uint16_t value_2byte; /**< Value for 2 bytes measured data type */
uint32_t value_4byte; /**< Value for 4 bytes measured data type */
uint64_t value_8byte; /**< Value for 4 bytes measured data type */
uint64_t value_8byte; /**< Value for 8 bytes measured data type */
struct {
const uint8_t *buffer; /**< Buffer containing the measured data */

Просмотреть файл

@ -144,13 +144,15 @@ int pcr_store_update_digest (struct pcr_store *store, uint16_t measurement_type,
* @param measurement_type The type of measurement being updated
* @param buf Buffer holding data to compute measurement of
* @param buf_len Length of data buffer
* @param include_event Flag that indicates whether to include the event type in measurement
* calculations.
*
* @return Completion status, 0 if success or an error code
*/
int pcr_store_update_buffer (struct pcr_store *store, struct hash_engine *hash,
uint16_t measurement_type, const uint8_t *buf, size_t buf_len)
uint16_t measurement_type, const uint8_t *buf, size_t buf_len, bool include_event)
{
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t pcr_bank = (uint8_t) (measurement_type >> 8);
uint8_t measurement_index = (uint8_t) measurement_type;
if (store == NULL) {
@ -161,7 +163,41 @@ int pcr_store_update_buffer (struct pcr_store *store, struct hash_engine *hash,
return PCR_INVALID_PCR;
}
return pcr_update_buffer (&store->banks[pcr_bank], hash, measurement_index, buf, buf_len);
return pcr_update_buffer (&store->banks[pcr_bank], hash, measurement_index, buf, buf_len,
include_event);
}
/**
* Compute digest of the versioned buffer and update the PCR bank's list of measurements
*
* @param store PCR store containing PCR to be updated
* @param hash Hashing engine to utilize in PCR bank operations
* @param measurement_type The type of measurement being updated
* @param buf Buffer holding data to compute measurement of
* @param buf_len Length of data buffer
* @param include_event Flag that indicates whether to include the event type in measurement
* calculations
* @param version The version associated with the measurement data.
*
* @return Completion status, 0 if success or an error code
*/
int pcr_store_update_versioned_buffer (struct pcr_store *store, struct hash_engine *hash,
uint16_t measurement_type, const uint8_t *buf, size_t buf_len, bool include_event,
uint8_t version)
{
uint8_t pcr_bank = (uint8_t) (measurement_type >> 8);
uint8_t measurement_index = (uint8_t) measurement_type;
if (store == NULL) {
return PCR_INVALID_ARGUMENT;
}
if (pcr_bank >= store->num_pcr_banks) {
return PCR_INVALID_PCR;
}
return pcr_update_versioned_buffer (&store->banks[pcr_bank], hash, measurement_index, buf,
buf_len, include_event, version);
}
/**

Просмотреть файл

@ -58,7 +58,10 @@ int pcr_store_get_num_banks (struct pcr_store *store);
int pcr_store_update_digest (struct pcr_store *store, uint16_t measurement_type,
const uint8_t *digest, size_t digest_len);
int pcr_store_update_buffer (struct pcr_store *store, struct hash_engine *hash,
uint16_t measurement_type, const uint8_t *buf, size_t buf_len);
uint16_t measurement_type, const uint8_t *buf, size_t buf_len, bool include_event);
int pcr_store_update_versioned_buffer (struct pcr_store *store, struct hash_engine *hash,
uint16_t measurement_type, const uint8_t *buf, size_t buf_len, bool include_event,
uint8_t version);
int pcr_store_update_event_type (struct pcr_store *store, uint16_t measurement_type,
uint32_t event_type);

Просмотреть файл

@ -22,7 +22,7 @@ static void host_processor_observer_pcr_update (struct host_processor_observer *
*host->state = event;
status = pcr_store_update_buffer (host->store, host->hash, host->pcr, (uint8_t*) host->state,
sizeof (uint32_t));
sizeof (uint32_t), true);
if (status != 0) {
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_HOST_FW,
HOST_LOGGING_PCR_UPDATE_ERROR, host->pcr, status);
@ -66,7 +66,7 @@ int host_processor_observer_pcr_init (struct host_processor_observer_pcr *host,
return HOST_PROCESSOR_OBSERVER_INVALID_ARGUMENT;
}
status = pcr_store_update_buffer (store, hash, pcr, (uint8_t*) init_state, sizeof (uint32_t));
status = pcr_store_update_buffer (store, hash, pcr, (uint8_t*) init_state, sizeof (uint32_t), true);
if (status != 0) {
return status;
}

Просмотреть файл

@ -71,7 +71,7 @@ void manifest_pcr_release (struct manifest_pcr *pcr)
}
/**
* Record the measurement for the provide manifest.
* Record the measurement for the provided manifest.
*
* @param pcr The PCR manager that will record the measurement.
* @param active The manifest to measure.
@ -121,7 +121,7 @@ void manifest_pcr_record_manifest_measurement (struct manifest_pcr *pcr, struct
}
status = pcr_store_update_buffer (pcr->store, pcr->hash, pcr->manifest_id_measurement, id,
sizeof (id));
sizeof (id), true);
if (status != 0) {
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_MANIFEST,
MANIFEST_LOGGING_RECORD_MEASUREMENT_FAIL, pcr->manifest_id_measurement, status);
@ -141,7 +141,7 @@ void manifest_pcr_record_manifest_measurement (struct manifest_pcr *pcr, struct
}
status = pcr_store_update_buffer (pcr->store, pcr->hash, pcr->manifest_platform_id_measurement,
(uint8_t*) platform_id, strlen (platform_id) + 1);
(uint8_t*) platform_id, strlen (platform_id) + 1, true);
if (status != 0) {
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_MANIFEST,
MANIFEST_LOGGING_RECORD_MEASUREMENT_FAIL, pcr->manifest_platform_id_measurement, status);

Просмотреть файл

@ -21,8 +21,8 @@ static const char *SUITE = "cfm_observer_pcr";
* CFM_PLATFORM_ID hash for testing.
*/
static const uint8_t CFM_PLATFORM_ID_HASH[] = {
0x45,0xe3,0x91,0x1b,0xe3,0x17,0xb3,0xbd,0xfc,0x9a,0x50,0x6f,0xa9,0x3f,0x84,0xd5,
0x9f,0x9d,0xa5,0x2d,0xcf,0xf3,0x17,0x67,0xa2,0x2b,0xe0,0x0e,0x9c,0xa4,0xe6,0x11
0x2c,0xb7,0xfd,0xd1,0x24,0x56,0x3e,0x5e,0xd0,0x53,0x36,0x76,0xf7,0xae,0x5b,0x6c,
0x38,0x84,0xc8,0xdd,0x05,0x8e,0xd6,0x04,0xaf,0xf5,0xab,0xec,0xab,0xf2,0x06,0xfb
};
/**
@ -186,6 +186,7 @@ static void cfm_observer_pcr_test_on_cfm_activated (CuTest *test)
uint32_t id = 0x1;
char *cfm_platform_id = "CFM Test1";
char *platform_id;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -200,6 +201,12 @@ static void cfm_observer_pcr_test_on_cfm_activated (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = cfm_mock_init (&cfm);
CuAssertIntEquals (test, 0, status);
@ -242,7 +249,8 @@ static void cfm_observer_pcr_test_on_cfm_activated (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -428,6 +436,7 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_platform_id_error (CuTest
struct pcr_measurement platform_id_measurement;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -437,6 +446,9 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_platform_id_error (CuTest
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = cfm_mock_init (&cfm);
CuAssertIntEquals (test, 0, status);
@ -479,7 +491,8 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_platform_id_error (CuTest
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -514,6 +527,7 @@ static void cfm_observer_pcr_test_record_measurement (CuTest *test)
uint32_t id = 0x1;
char *cfm_platform_id = "CFM Test1";
char *platform_id;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -528,6 +542,12 @@ static void cfm_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = cfm_mock_init (&cfm);
CuAssertIntEquals (test, 0, status);
@ -583,7 +603,8 @@ static void cfm_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -617,6 +638,7 @@ static void cfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
struct pcr_measurement component_id_measurement;
struct cfm_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -626,6 +648,12 @@ static void cfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = cfm_manager_mock_init (&manager);
CuAssertIntEquals (test, 0, status);
@ -667,7 +695,8 @@ static void cfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &component_id_measurement);
@ -928,6 +957,7 @@ static void cfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
struct cfm_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -937,6 +967,9 @@ static void cfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = cfm_mock_init (&cfm);
CuAssertIntEquals (test, 0, status);
@ -985,7 +1018,8 @@ static void cfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = cfm_mock_validate_and_release (&cfm);

Просмотреть файл

@ -19,32 +19,32 @@ static const char *SUITE = "host_processor_observer_pcr";
* Digest of the number 0. This indicates valid FW in active mode.
*/
static const uint8_t DIGEST_ZERO[] = {
0xdf,0x3f,0x61,0x98,0x04,0xa9,0x2f,0xdb,0x40,0x57,0x19,0x2d,0xc4,0x3d,0xd7,0x48,
0xea,0x77,0x8a,0xdc,0x52,0xbc,0x49,0x8c,0xe8,0x05,0x24,0xc0,0x14,0xb8,0x11,0x19
0x47,0x40,0x56,0x46,0xe6,0x3c,0x9f,0x11,0xb4,0xc9,0xc5,0x80,0x03,0x82,0x7f,0xdb,
0x51,0x14,0xfa,0x50,0x1e,0xab,0x92,0xe5,0xf0,0xc1,0xc4,0xb5,0x0b,0xc0,0x2d,0x8b
};
/**
* Digest of the state indicating bypass mode.
*/
static const uint8_t DIGEST_BYPASS[] = {
0x67,0xab,0xdd,0x72,0x10,0x24,0xf0,0xff,0x4e,0x0b,0x3f,0x4c,0x2f,0xc1,0x3b,0xc5,
0xba,0xd4,0x2d,0x0b,0x78,0x51,0xd4,0x56,0xd8,0x8d,0x20,0x3d,0x15,0xaa,0xa4,0x50
0xb1,0xde,0x2f,0x62,0x8f,0xb6,0x8c,0x28,0xc1,0x2b,0x1f,0xee,0xad,0x61,0xe6,0x0c,
0x5a,0x4b,0x0b,0x20,0x49,0xa9,0x12,0x34,0x82,0x72,0x62,0xf2,0x12,0x3c,0xa4,0xb0
};
/**
* Digest of the state indicating recovery mode.
*/
static const uint8_t DIGEST_RECOVERY[] = {
0x26,0xb2,0x5d,0x45,0x75,0x97,0xa7,0xb0,0x46,0x3f,0x96,0x20,0xf6,0x66,0xdd,0x10,
0xaa,0x2c,0x43,0x73,0xa5,0x05,0x96,0x7c,0x7c,0x8d,0x70,0x92,0x2a,0x2d,0x6e,0xce
0xfa,0xb6,0x6f,0x51,0x96,0x05,0x96,0x9a,0x1a,0xa0,0xd2,0x87,0x00,0xee,0x25,0x84,
0x8a,0x27,0x39,0x80,0xe2,0xcc,0x45,0xda,0x53,0x2d,0xb3,0xad,0xc8,0xc0,0xf7,0x37
};
/**
* Digest of the initial state.
*/
static const uint8_t DIGEST_INIT[] = {
0xad,0x95,0x13,0x1b,0xc0,0xb7,0x99,0xc0,0xb1,0xaf,0x47,0x7f,0xb1,0x4f,0xcf,0x26,
0xa6,0xa9,0xf7,0x60,0x79,0xe4,0x8b,0xf0,0x90,0xac,0xb7,0xe8,0x36,0x7b,0xfd,0x0e
0x8f,0xce,0x49,0xc6,0x07,0xe3,0xf4,0xad,0x60,0x9f,0x37,0xb3,0xc8,0x7f,0x31,0xd9,
0x53,0x25,0xc4,0xe5,0xb7,0x6d,0x49,0x9e,0x9a,0x4a,0x95,0x5b,0x51,0x64,0x3f,0x30
};
@ -71,6 +71,7 @@ static void host_processor_observer_pcr_test_init (CuTest *test)
struct host_processor_observer_pcr observer;
int status;
struct pcr_measurement measurement;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -80,6 +81,9 @@ static void host_processor_observer_pcr_test_init (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
PCR_MEASUREMENT (0, 0), &state);
CuAssertIntEquals (test, 0, status);
@ -110,6 +114,7 @@ static void host_processor_observer_pcr_test_init_valid (CuTest *test)
struct host_processor_observer_pcr observer;
int status;
struct pcr_measurement measurement;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -119,6 +124,9 @@ static void host_processor_observer_pcr_test_init_valid (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
PCR_MEASUREMENT (0, 2), &state);
CuAssertIntEquals (test, 0, status);
@ -215,6 +223,7 @@ static void host_processor_observer_pcr_test_on_bypass_mode (CuTest *test)
struct host_processor_observer_pcr observer;
int status;
struct pcr_measurement measurement;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -224,6 +233,9 @@ static void host_processor_observer_pcr_test_on_bypass_mode (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
PCR_MEASUREMENT (0, 0), &state);
CuAssertIntEquals (test, 0, status);
@ -259,8 +271,9 @@ static void host_processor_observer_pcr_test_on_bypass_mode_error (CuTest *test)
.component = DEBUG_LOG_COMPONENT_HOST_FW,
.msg_index = HOST_LOGGING_PCR_UPDATE_ERROR,
.arg1 = PCR_MEASUREMENT (0, 0),
.arg2 = HASH_ENGINE_SHA256_FAILED
.arg2 = HASH_ENGINE_UPDATE_FAILED
};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -273,8 +286,16 @@ static void host_processor_observer_pcr_test_on_bypass_mode_error (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
@ -284,9 +305,10 @@ static void host_processor_observer_pcr_test_on_bypass_mode_error (CuTest *test)
status = mock_validate (&hash.mock);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, HASH_ENGINE_SHA256_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, HASH_ENGINE_UPDATE_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.cancel, &hash, 0);
status |= mock_expect (&logger.mock, logger.base.create_entry, &logger, 0,
MOCK_ARG_PTR_CONTAINS ((uint8_t*) &entry, sizeof (entry)), MOCK_ARG (sizeof (entry)));
@ -323,6 +345,7 @@ static void host_processor_observer_pcr_test_on_active_mode (CuTest *test)
struct host_processor_observer_pcr observer;
int status;
struct pcr_measurement measurement;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -332,6 +355,9 @@ static void host_processor_observer_pcr_test_on_active_mode (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
PCR_MEASUREMENT (0, 0), &state);
CuAssertIntEquals (test, 0, status);
@ -367,8 +393,9 @@ static void host_processor_observer_pcr_test_on_active_mode_error (CuTest *test)
.component = DEBUG_LOG_COMPONENT_HOST_FW,
.msg_index = HOST_LOGGING_PCR_UPDATE_ERROR,
.arg1 = PCR_MEASUREMENT (0, 0),
.arg2 = HASH_ENGINE_SHA256_FAILED
.arg2 = HASH_ENGINE_UPDATE_FAILED
};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -381,8 +408,16 @@ static void host_processor_observer_pcr_test_on_active_mode_error (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
@ -392,9 +427,10 @@ static void host_processor_observer_pcr_test_on_active_mode_error (CuTest *test)
status = mock_validate (&hash.mock);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, HASH_ENGINE_SHA256_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, HASH_ENGINE_UPDATE_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.cancel, &hash, 0);
status |= mock_expect (&logger.mock, logger.base.create_entry, &logger, 0,
MOCK_ARG_PTR_CONTAINS ((uint8_t*) &entry, sizeof (entry)), MOCK_ARG (sizeof (entry)));
@ -431,6 +467,7 @@ static void host_processor_observer_pcr_test_on_recovery (CuTest *test)
struct host_processor_observer_pcr observer;
int status;
struct pcr_measurement measurement;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -440,6 +477,9 @@ static void host_processor_observer_pcr_test_on_recovery (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
PCR_MEASUREMENT (0, 0), &state);
CuAssertIntEquals (test, 0, status);
@ -475,8 +515,9 @@ static void host_processor_observer_pcr_test_on_recovery_error (CuTest *test)
.component = DEBUG_LOG_COMPONENT_HOST_FW,
.msg_index = HOST_LOGGING_PCR_UPDATE_ERROR,
.arg1 = PCR_MEASUREMENT (0, 0),
.arg2 = HASH_ENGINE_SHA256_FAILED
.arg2 = HASH_ENGINE_UPDATE_FAILED
};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -489,8 +530,16 @@ static void host_processor_observer_pcr_test_on_recovery_error (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
status = pcr_update_event_type (&store.banks[0], 0, event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
CuAssertIntEquals (test, 0, status);
status = host_processor_observer_pcr_init (&observer, &hash.base, &store,
@ -500,9 +549,10 @@ static void host_processor_observer_pcr_test_on_recovery_error (CuTest *test)
status = mock_validate (&hash.mock);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, HASH_ENGINE_SHA256_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)), MOCK_ARG_NOT_NULL,
MOCK_ARG (SHA256_HASH_LENGTH));
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, HASH_ENGINE_UPDATE_FAILED,
MOCK_ARG_NOT_NULL, MOCK_ARG (sizeof (uint32_t)));
status |= mock_expect (&hash.mock, hash.base.cancel, &hash, 0);
status |= mock_expect (&logger.mock, logger.base.create_entry, &logger, 0,
MOCK_ARG_PTR_CONTAINS ((uint8_t*) &entry, sizeof (entry)), MOCK_ARG (sizeof (entry)));

Просмотреть файл

@ -6,15 +6,15 @@
/**
* Hash for manifest with ID 1 for testing.
* Hash for manifest with ID 0x1 for testing.
*/
const uint8_t MANIFEST_ID_HASH[] = {
0xb3,0x84,0x46,0x34,0x76,0x2d,0x8e,0x07,0x54,0x73,0xfc,0x1c,0xd7,0x74,0xd0,0xf2,
0x51,0xc6,0x51,0x2e,0x27,0xe6,0x7e,0x43,0xe7,0xb9,0xae,0x69,0xef,0xff,0x56,0xf3
0x6e,0x29,0x71,0xca,0xb8,0xab,0x24,0x64,0x68,0xe3,0x92,0x91,0xfd,0x06,0x8a,0x90,
0xf9,0x84,0x68,0xbf,0x5e,0x1c,0xd7,0xcf,0xe7,0x69,0x76,0x97,0xf2,0xd2,0x91,0x97
};
/**
* Length of the test manifest hash with ID 1.
* Length of the test manifest hash with ID 0x1.
*/
const uint32_t MANIFEST_ID_HASH_LEN = sizeof (MANIFEST_ID_HASH);
@ -22,8 +22,8 @@ const uint32_t MANIFEST_ID_HASH_LEN = sizeof (MANIFEST_ID_HASH);
* Hash for testing no manifest.
*/
const uint8_t NO_MANIFEST_ID_HASH[] = {
0x88,0x55,0x50,0x8a,0xad,0xe1,0x6e,0xc5,0x73,0xd2,0x1e,0x6a,0x48,0x5d,0xfd,0x0a,
0x76,0x24,0x08,0x5c,0x1a,0x14,0xb5,0xec,0xdd,0x64,0x85,0xde,0x0c,0x68,0x39,0xa4
0x91,0xc2,0x06,0x73,0x18,0x55,0x21,0x12,0xdf,0xc2,0x77,0x4c,0xc2,0xa7,0xb4,0xc2,
0x3b,0xd5,0xe8,0x1c,0xe8,0x15,0x57,0x53,0xf7,0xb8,0x01,0xf4,0x5d,0x6a,0x34,0x84
};
/**
@ -45,14 +45,14 @@ const uint8_t EMPTY_BUFFER_HASH[] = {
const uint32_t EMPTY_BUFFER_HASH_LEN = sizeof (EMPTY_BUFFER_HASH);
/**
* Hash for testing an empty string.
* Hash for testing a manifest with an empty string platform identifier.
*/
const uint8_t EMPTY_STRING_HASH[] = {
0x6e,0x34,0x0b,0x9c,0xff,0xb3,0x7a,0x98,0x9c,0xa5,0x44,0xe6,0xbb,0x78,0x0a,0x2c,
0x78,0x90,0x1d,0x3f,0xb3,0x37,0x38,0x76,0x85,0x11,0xa3,0x06,0x17,0xaf,0xa0,0x1d
0xc6,0xc0,0xe8,0x2d,0xd0,0x8e,0xab,0x6d,0x70,0x7e,0xcc,0xad,0x37,0x72,0x21,0xdd,
0x1f,0x2e,0xf0,0x0c,0x1b,0x01,0xa0,0x79,0xb6,0x7c,0xa7,0x8a,0x19,0xc9,0xbc,0xb9
};
/**
* Length of an empty string hash.
* Length of the hash for a manifest with an empty string platform identifier.
*/
const uint32_t EMPTY_STRING_HASH_LEN = sizeof (EMPTY_STRING_HASH);

Просмотреть файл

@ -21,8 +21,8 @@ static const char *SUITE = "pcd_observer_pcr";
* PCD_PLATFORM_ID hash for testing.
*/
static const uint8_t PCD_PLATFORM_ID_HASH[] = {
0xcd,0x50,0xf5,0x5e,0x65,0xf7,0x3e,0x4f,0x44,0x89,0xdf,0x0d,0x8d,0xa9,0x27,0xc4,
0x93,0x20,0x27,0x86,0x3d,0x37,0x78,0xf7,0x04,0x43,0x56,0xc8,0xe6,0x9d,0xb2,0x62
0x1c,0xde,0xf3,0x40,0xc0,0xfb,0xa7,0xd5,0x46,0x3c,0x3c,0xc0,0xc4,0x54,0x86,0x4b,
0xe2,0x5d,0xd2,0xdc,0xe7,0xdf,0xb0,0x3f,0x70,0x28,0xbb,0x14,0x81,0xad,0x24,0xe6
};
/**
@ -185,6 +185,7 @@ static void pcd_observer_pcr_test_on_pcd_activated (CuTest *test)
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
char *platform_id;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -199,6 +200,12 @@ static void pcd_observer_pcr_test_on_pcd_activated (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pcd_mock_init (&pcd);
CuAssertIntEquals (test, 0, status);
@ -249,7 +256,8 @@ static void pcd_observer_pcr_test_on_pcd_activated (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -452,6 +460,7 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_platform_id_error (CuTest
struct pcr_measurement platform_id_measurement;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -461,6 +470,9 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_platform_id_error (CuTest
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcd_mock_init (&pcd);
CuAssertIntEquals (test, 0, status);
@ -545,6 +557,7 @@ static void pcd_observer_pcr_test_record_measurement (CuTest *test)
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
char *platform_id;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -559,6 +572,12 @@ static void pcd_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pcd_mock_init (&pcd);
CuAssertIntEquals (test, 0, status);
@ -613,7 +632,8 @@ static void pcd_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -647,6 +667,7 @@ static void pcd_observer_pcr_test_record_measurement_no_active (CuTest *test)
struct pcr_measurement platform_id_measurement;
struct pcd_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -656,6 +677,12 @@ static void pcd_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pcd_manager_mock_init (&manager);
CuAssertIntEquals (test, 0, status);
@ -696,13 +723,15 @@ static void pcd_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (EMPTY_STRING_HASH, platform_id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (EMPTY_STRING_HASH, platform_id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = pcd_manager_mock_validate_and_release (&manager);
@ -1000,6 +1029,7 @@ static void pcd_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
struct pcd_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -1009,6 +1039,9 @@ static void pcd_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcd_mock_init (&pcd);
CuAssertIntEquals (test, 0, status);
@ -1034,7 +1067,8 @@ static void pcd_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (invalid_measurement, platform_id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (invalid_measurement, platform_id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager, (intptr_t) &pcd);
@ -1063,7 +1097,8 @@ static void pcd_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);

Просмотреть файл

@ -295,22 +295,29 @@ static void pcr_store_test_update_buffer (CuTest *test)
0x38,0x38,0x38,0x4f,0x7f,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0xfc
};
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)),
MOCK_ARG_NOT_NULL, MOCK_ARG (32));
status |= mock_expect_output (&hash.mock, 2, digest, sizeof (digest), -1);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, 5, buffer, sizeof (buffer));
status = pcr_store_update_buffer (&store, &hash.base, measurement_type, buffer, sizeof (buffer),
false);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[0], 5, &measurement);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
@ -333,7 +340,7 @@ static void pcr_store_test_update_buffer_invalid_arg (CuTest *test)
setup_pcr_store_mock_test (test, &store, &hash, 3, 0);
status = pcr_store_update_buffer (NULL, &hash.base, 5, buffer, sizeof (buffer));
status = pcr_store_update_buffer (NULL, &hash.base, 5, buffer, sizeof (buffer), false);
CuAssertIntEquals (test, PCR_INVALID_ARGUMENT, status);
complete_pcr_store_mock_test (test, &store, &hash);
@ -354,7 +361,7 @@ static void pcr_store_test_update_buffer_invalid_pcr (CuTest *test)
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_buffer (&store, &hash.base, (((uint16_t)4 << 8) | 1), buffer,
sizeof (buffer));
sizeof (buffer), false);
CuAssertIntEquals (test, PCR_INVALID_PCR, status);
complete_pcr_store_mock_test (test, &store, &hash);
@ -374,13 +381,377 @@ static void pcr_store_test_update_buffer_update_fail (CuTest *test)
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = mock_expect (&hash.mock, hash.base.calculate_sha256, &hash, HASH_ENGINE_SHA256_FAILED,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)),
MOCK_ARG_NOT_NULL, MOCK_ARG (32));
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash,
HASH_ENGINE_START_SHA256_FAILED);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, 5, buffer, sizeof (buffer));
CuAssertIntEquals (test, HASH_ENGINE_SHA256_FAILED, status);
status = pcr_store_update_buffer (&store, &hash.base, 5, buffer, sizeof (buffer), false);
CuAssertIntEquals (test, HASH_ENGINE_START_SHA256_FAILED, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_buffer_with_event (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
struct pcr_measurement measurement;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint8_t digest[] = {
0x38,0x38,0x38,0x4f,0x7f,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0xfc
};
uint32_t event = 0xaabbccdd;
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_event_type (&store, PCR_MEASUREMENT (pcr_bank, index), event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, measurement_type, buffer, sizeof (buffer),
true);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, PCR_MEASUREMENT_FLAG_EVENT,
store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
CuAssertIntEquals (test, 0, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_buffer_with_event_without_event (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
struct pcr_measurement measurement;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint8_t digest[] = {
0x38,0x38,0x38,0x4f,0x7f,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0xfc
};
uint32_t event = 0xaabbccdd;
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_event_type (&store, PCR_MEASUREMENT (pcr_bank, index), event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, measurement_type, buffer, sizeof (buffer),
true);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, PCR_MEASUREMENT_FLAG_EVENT,
store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, measurement_type, buffer, sizeof (buffer),
false);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
CuAssertIntEquals (test, 0, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_buffer_with_event_update_fail (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint32_t event = 0xaabbccdd;
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t) (measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_event_type (&store, PCR_MEASUREMENT (pcr_bank, index), event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash,
HASH_ENGINE_START_SHA256_FAILED);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_buffer (&store, &hash.base, measurement_type, buffer, sizeof (buffer),
true);
CuAssertIntEquals (test, HASH_ENGINE_START_SHA256_FAILED, status);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].measurement_config);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
struct pcr_measurement measurement;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint8_t digest[] = {
0x38,0x38,0x38,0x4f,0x7f,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0xfc
};
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
uint8_t version = 0x24;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&version, sizeof (version)), MOCK_ARG (sizeof (version)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_versioned_buffer (&store, &hash.base, measurement_type, buffer,
sizeof (buffer), false, version);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, version, store.banks[pcr_bank].measurement_list[index].version);
CuAssertIntEquals (test, PCR_MEASUREMENT_FLAG_VERSION,
store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
CuAssertIntEquals (test, 0, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer_with_event (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
struct pcr_measurement measurement;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint8_t digest[] = {
0x38,0x38,0x38,0x4f,0x7f,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0xfc
};
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
uint8_t version = 0x24;
uint32_t event = 0xaabbccdd;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_event_type (&store, PCR_MEASUREMENT (pcr_bank, index), event);
CuAssertIntEquals (test, 0, status);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash, 0);
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&event, sizeof (event)), MOCK_ARG (sizeof (event)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (&version, sizeof (version)), MOCK_ARG (sizeof (version)));
status |= mock_expect (&hash.mock, hash.base.update, &hash, 0,
MOCK_ARG_PTR_CONTAINS (buffer, sizeof (buffer)), MOCK_ARG (sizeof (buffer)));
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
MOCK_ARG (PCR_DIGEST_LENGTH));
status |= mock_expect_output (&hash.mock, 0, digest, sizeof (digest), -1);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_versioned_buffer (&store, &hash.base, measurement_type, buffer,
sizeof (buffer), true, version);
CuAssertIntEquals (test, 0, status);
CuAssertIntEquals (test, version, store.banks[pcr_bank].measurement_list[index].version);
CuAssertIntEquals (test, PCR_MEASUREMENT_FLAG_VERSION | PCR_MEASUREMENT_FLAG_EVENT,
store.banks[pcr_bank].measurement_list[index].measurement_config);
status = pcr_get_measurement (&store.banks[pcr_bank], index, &measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (digest, measurement.digest, sizeof (digest));
CuAssertIntEquals (test, 0, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer_invalid_arg (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint16_t measurement_type = 5;
uint8_t version = 0x24;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_versioned_buffer (NULL, &hash.base, measurement_type, buffer,
sizeof (buffer), false, version);
CuAssertIntEquals (test, PCR_INVALID_ARGUMENT, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer_invalid_pcr (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint8_t version = 0x24;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = pcr_store_update_versioned_buffer (&store, &hash.base, (((uint16_t)4 << 8) | 1),
buffer, sizeof (buffer), false, version);
CuAssertIntEquals (test, PCR_INVALID_PCR, status);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer_update_fail (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
uint8_t version = 0x24;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash,
HASH_ENGINE_START_SHA256_FAILED);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_versioned_buffer (&store, &hash.base, measurement_type, buffer,
sizeof (buffer), false, version);
CuAssertIntEquals (test, HASH_ENGINE_START_SHA256_FAILED, status);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].version);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].measurement_config);
complete_pcr_store_mock_test (test, &store, &hash);
}
static void pcr_store_test_update_versioned_buffer_with_event_update_fail (CuTest *test)
{
struct pcr_store store;
struct hash_engine_mock hash;
uint8_t buffer[] = {
0xfc,0x3d,0x91,0xe6,0xc1,0x13,0xd6,0x82,0x18,0x33,0xf6,0x5b,0x12,0xc7,0xe7,0x6e,
0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f,0x7f,0x38,0x9c,0x4f
};
uint16_t measurement_type = 5;
uint8_t pcr_bank = (uint8_t)(measurement_type >> 8);
uint8_t index = (uint8_t) measurement_type;
uint8_t version = 0x24;
int status;
TEST_START;
setup_pcr_store_mock_test (test, &store, &hash, 6, 6);
status = mock_expect (&hash.mock, hash.base.start_sha256, &hash,
HASH_ENGINE_START_SHA256_FAILED);
CuAssertIntEquals (test, 0, status);
status = pcr_store_update_versioned_buffer (&store, &hash.base, measurement_type, buffer,
sizeof (buffer), true, version);
CuAssertIntEquals (test, HASH_ENGINE_START_SHA256_FAILED, status);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].version);
CuAssertIntEquals (test, 0, store.banks[pcr_bank].measurement_list[index].measurement_config);
complete_pcr_store_mock_test (test, &store, &hash);
}
@ -2381,6 +2752,15 @@ CuSuite* get_pcr_store_suite ()
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_invalid_arg);
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_invalid_pcr);
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_update_fail);
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_with_event);
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_with_event_without_event);
SUITE_ADD_TEST (suite, pcr_store_test_update_buffer_with_event_update_fail);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer_with_event);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer_invalid_arg);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer_invalid_pcr);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer_update_fail);
SUITE_ADD_TEST (suite, pcr_store_test_update_versioned_buffer_with_event_update_fail);
SUITE_ADD_TEST (suite, pcr_store_test_update_event_type);
SUITE_ADD_TEST (suite, pcr_store_test_update_event_type_invalid_arg);
SUITE_ADD_TEST (suite, pcr_store_test_update_event_type_invalid_pcr);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -21,8 +21,8 @@ static const char *SUITE = "pfm_observer_pcr";
* PFM_PLATFORM_ID hash for testing.
*/
static const uint8_t PFM_PLATFORM_ID_HASH[] = {
0xd0,0x4c,0x96,0x51,0x7c,0x74,0x9d,0x78,0x38,0xc2,0x76,0xc5,0x87,0x5f,0x05,0x57,
0xd0,0xd5,0xfe,0x89,0xbf,0xb8,0x62,0x61,0x48,0x81,0x99,0x96,0x30,0x02,0x83,0x12
0xb5,0x6e,0xec,0xa9,0x7a,0x3a,0x98,0xe8,0x3e,0x8c,0x33,0xb5,0x05,0xd3,0xa7,0x77,
0x56,0x61,0x6e,0x5b,0x1d,0xea,0x2f,0x2f,0x7b,0x4b,0xc3,0x03,0xdf,0x97,0x30,0x94
};
/**
@ -184,6 +184,7 @@ static void pfm_observer_pcr_test_on_pfm_activated (CuTest *test)
struct pcr_measurement platform_id_measurement;
uint8_t invalid_manifest_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
uint32_t event = 0xaabbccdd;
char *platform_id;
TEST_START;
@ -199,6 +200,12 @@ static void pfm_observer_pcr_test_on_pfm_activated (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pfm_mock_init (&pfm);
CuAssertIntEquals (test, 0, status);
@ -250,7 +257,8 @@ static void pfm_observer_pcr_test_on_pfm_activated (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &manifest_id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, manifest_id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, manifest_id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -443,6 +451,7 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_platform_id_error (CuTest
struct pcr_measurement platform_id_measurement;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -452,6 +461,9 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_platform_id_error (CuTest
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pfm_mock_init (&pfm);
CuAssertIntEquals (test, 0, status);
@ -501,7 +513,8 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_platform_id_error (CuTest
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -535,6 +548,7 @@ static void pfm_observer_pcr_test_record_measurement (CuTest *test)
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
char *platform_id;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -549,6 +563,12 @@ static void pfm_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pfm_mock_init (&pfm);
CuAssertIntEquals (test, 0, status);
@ -605,7 +625,8 @@ static void pfm_observer_pcr_test_record_measurement (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest, MANIFEST_ID_HASH_LEN);
status = testing_validate_array (MANIFEST_ID_HASH, id_measurement.digest,
MANIFEST_ID_HASH_LEN);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -639,6 +660,7 @@ static void pfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
struct pcr_measurement platform_id_measurement;
struct pfm_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t event = 0xaabbccdd;
TEST_START;
@ -648,6 +670,12 @@ static void pfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 2, event);
CuAssertIntEquals (test, 0, status);
status = pfm_manager_mock_init (&manager);
CuAssertIntEquals (test, 0, status);
@ -689,7 +717,8 @@ static void pfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
CuAssertIntEquals (test, 0, status);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest, SHA256_HASH_LENGTH);
status = testing_validate_array (NO_MANIFEST_ID_HASH, id_measurement.digest,
SHA256_HASH_LENGTH);
CuAssertIntEquals (test, 0, status);
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 2), &platform_id_measurement);
@ -1002,6 +1031,7 @@ static void pfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
struct pfm_manager_mock manager;
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
uint32_t id = 0x1;
uint32_t event = 0xaabbccdd;
TEST_START;
@ -1011,6 +1041,9 @@ static void pfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
status = pcr_store_init (&store, num_pcr_measurements, sizeof (num_pcr_measurements));
CuAssertIntEquals (test, 0, status);
status = pcr_update_event_type (&store.banks[0], 1, event);
CuAssertIntEquals (test, 0, status);
status = pfm_mock_init (&pfm);
CuAssertIntEquals (test, 0, status);