Merged PR 1418: Add versioned event data to PCR entries
All PCR events will provide event data and some will provide versioned event data. Related work items: #606, #638
This commit is contained in:
Родитель
8232c86b7a
Коммит
9557d29158
|
@ -21,8 +21,8 @@ static void host_processor_observer_pcr_update (struct host_processor_observer *
|
|||
int status;
|
||||
|
||||
*host->state = event;
|
||||
status = pcr_store_update_buffer (host->store, host->hash, host->pcr, (uint8_t*) host->state,
|
||||
sizeof (uint32_t), true);
|
||||
status = pcr_store_update_versioned_buffer (host->store, host->hash, host->pcr,
|
||||
(uint8_t*) host->state, sizeof (uint32_t), true, 0);
|
||||
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,8 @@ 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), true);
|
||||
status = pcr_store_update_versioned_buffer (store, hash, pcr, (uint8_t*) init_state,
|
||||
sizeof (uint32_t), true, 0);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -48,10 +48,11 @@ int cfm_manager_remove_observer (struct cfm_manager *manager, struct cfm_observe
|
|||
* Initialize the base CFM manager.
|
||||
*
|
||||
* @param manager The manager to initialize.
|
||||
* @param hash The hash engine to generate measurement data.
|
||||
*
|
||||
* @return 0 if the CFM manager was initialized successfully or an error code.
|
||||
*/
|
||||
int cfm_manager_init (struct cfm_manager *manager)
|
||||
int cfm_manager_init (struct cfm_manager *manager, struct hash_engine *hash)
|
||||
{
|
||||
int status;
|
||||
|
||||
|
@ -62,7 +63,7 @@ int cfm_manager_init (struct cfm_manager *manager)
|
|||
return status;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return manifest_manager_init (&manager->base, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,3 +200,38 @@ int cfm_manager_get_platform_id_measured_data (struct cfm_manager *manager, size
|
|||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data used for CFM measurement. The CFM instance must be released with the
|
||||
* manager.
|
||||
*
|
||||
* @param manager The PFM manager to query.
|
||||
* @param offset The offset to read data from
|
||||
* @param buffer The output buffer to be filled with measured data
|
||||
* @param length Maximum length of the buffer.
|
||||
*
|
||||
* @return Length of the measured data if successfully retrieved or an error code.
|
||||
*/
|
||||
int cfm_manager_get_cfm_measured_data (struct cfm_manager *manager, size_t offset, uint8_t *buffer,
|
||||
size_t length)
|
||||
{
|
||||
int status;
|
||||
struct cfm *active;
|
||||
|
||||
if (manager == NULL) {
|
||||
return MANIFEST_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
active = manager->get_active_cfm (manager);
|
||||
if (active == NULL) {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, NULL, offset, buffer,
|
||||
length);
|
||||
}
|
||||
else {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, &active->base, offset,
|
||||
buffer, length);
|
||||
manager->free_cfm (manager, active);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ int cfm_manager_add_observer (struct cfm_manager *manager, struct cfm_observer *
|
|||
int cfm_manager_remove_observer (struct cfm_manager *manager, struct cfm_observer *observer);
|
||||
|
||||
/* Internal functions for use by derived types. */
|
||||
int cfm_manager_init (struct cfm_manager *manager);
|
||||
int cfm_manager_init (struct cfm_manager *manager, struct hash_engine *hash);
|
||||
void cfm_manager_release (struct cfm_manager *manager);
|
||||
|
||||
void cfm_manager_on_cfm_verified (struct cfm_manager *manager);
|
||||
|
@ -64,6 +64,8 @@ int cfm_manager_get_id_measured_data (struct cfm_manager *manager, size_t offset
|
|||
size_t length);
|
||||
int cfm_manager_get_platform_id_measured_data (struct cfm_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
int cfm_manager_get_cfm_measured_data (struct cfm_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
|
||||
|
||||
#endif /* CFM_MANAGER_H_ */
|
||||
|
|
|
@ -149,7 +149,7 @@ int cfm_manager_flash_init (struct cfm_manager_flash *manager, struct cfm_flash
|
|||
|
||||
memset (manager, 0, sizeof (struct cfm_manager_flash));
|
||||
|
||||
status = cfm_manager_init (&manager->base);
|
||||
status = cfm_manager_init (&manager->base, hash);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,25 @@
|
|||
#include "platform.h"
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the manifest manager.
|
||||
*
|
||||
* @param manager The manager to initialize.
|
||||
* @param hash The hash engine to generate measurement data.
|
||||
*
|
||||
* @return 0 if the manifest manager was initialized successfully or an error code.
|
||||
*/
|
||||
int manifest_manager_init (struct manifest_manager *manager, struct hash_engine *hash)
|
||||
{
|
||||
if ((manager == NULL) || (hash == NULL)) {
|
||||
return MANIFEST_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
manager->hash = hash;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the port identifier for a manifest manager.
|
||||
*
|
||||
|
@ -127,3 +146,43 @@ exit:
|
|||
}
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data used for manifest ID measurement.
|
||||
*
|
||||
* @param manager The manifest manager instance to query.
|
||||
* @param active The manifest to query
|
||||
* @param offset The offset to read data from
|
||||
* @param buffer The output buffer to be filled with measured data
|
||||
* @param length Maximum length of the buffer
|
||||
*
|
||||
*@return length of the measured data if successfully retrieved or an error code.
|
||||
*/
|
||||
int manifest_manager_get_manifest_measured_data (struct manifest_manager *manager,
|
||||
struct manifest *active, size_t offset, uint8_t *buffer, size_t length)
|
||||
{
|
||||
uint8_t hash_out[SHA256_HASH_LENGTH] = {0};
|
||||
size_t bytes_read;
|
||||
int status;
|
||||
|
||||
if ((buffer == NULL) || (manager == NULL)) {
|
||||
return MANIFEST_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (offset > (SHA256_HASH_LENGTH - 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (active) {
|
||||
status = active->get_hash (active, manager->hash, hash_out, SHA256_HASH_LENGTH);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
bytes_read = ((SHA256_HASH_LENGTH - offset) > length) ? length : (SHA256_HASH_LENGTH - offset);
|
||||
|
||||
memcpy (buffer, hash_out + offset, bytes_read);
|
||||
|
||||
return bytes_read;
|
||||
}
|
||||
|
|
|
@ -66,10 +66,13 @@ struct manifest_manager {
|
|||
*/
|
||||
int (*clear_all_manifests) (struct manifest_manager *manager);
|
||||
|
||||
int port; /**< Port identifier for the manager. */
|
||||
int port; /**< Port identifier for the manager. */
|
||||
struct hash_engine *hash; /**< The hash engine for generating measurement data. */
|
||||
};
|
||||
|
||||
|
||||
int manifest_manager_init (struct manifest_manager *manager, struct hash_engine *hash);
|
||||
|
||||
void manifest_manager_set_port (struct manifest_manager *manager, int port);
|
||||
int manifest_manager_get_port (struct manifest_manager *manager);
|
||||
|
||||
|
@ -77,6 +80,8 @@ int manifest_manager_get_id_measured_data (struct manifest *active, size_t offse
|
|||
uint8_t *buffer, size_t length);
|
||||
int manifest_manager_get_platform_id_measured_data (struct manifest *active, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
int manifest_manager_get_manifest_measured_data (struct manifest_manager *manager,
|
||||
struct manifest *active, size_t offset, uint8_t *buffer, size_t length);
|
||||
|
||||
|
||||
#define MANIFEST_MANAGER_ERROR(code) ROT_ERROR (ROT_MODULE_MANIFEST_MANAGER, code)
|
||||
|
|
|
@ -82,10 +82,11 @@ void manifest_pcr_record_manifest_measurement (struct manifest_pcr *pcr, struct
|
|||
uint8_t id[5];
|
||||
char *platform_id = NULL;
|
||||
char empty_string = '\0';
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
int status;
|
||||
|
||||
if (active == NULL) {
|
||||
status = pcr->hash->calculate_sha256 (pcr->hash, NULL, 0, manifest_measurement,
|
||||
status = pcr->hash->calculate_sha256 (pcr->hash, zero, sizeof (zero), manifest_measurement,
|
||||
sizeof (manifest_measurement));
|
||||
}
|
||||
else {
|
||||
|
@ -98,9 +99,9 @@ void manifest_pcr_record_manifest_measurement (struct manifest_pcr *pcr, struct
|
|||
MANIFEST_LOGGING_GET_MEASUREMENT_FAIL, pcr->manifest_measurement, status);
|
||||
return;
|
||||
}
|
||||
|
||||
status = pcr_store_update_digest (pcr->store, pcr->manifest_measurement, manifest_measurement,
|
||||
SHA256_HASH_LENGTH);
|
||||
|
||||
status = pcr_store_update_versioned_buffer (pcr->store, pcr->hash, pcr->manifest_measurement,
|
||||
manifest_measurement, SHA256_HASH_LENGTH, true, 0);
|
||||
if (status != 0) {
|
||||
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_MANIFEST,
|
||||
MANIFEST_LOGGING_RECORD_MEASUREMENT_FAIL, pcr->manifest_measurement, status);
|
||||
|
@ -120,8 +121,8 @@ 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), true);
|
||||
status = pcr_store_update_versioned_buffer (pcr->store, pcr->hash, pcr->manifest_id_measurement,
|
||||
id, sizeof (id), true, 0);
|
||||
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);
|
||||
|
@ -140,8 +141,9 @@ 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, true);
|
||||
status = pcr_store_update_versioned_buffer (pcr->store, pcr->hash,
|
||||
pcr->manifest_platform_id_measurement, (uint8_t*) platform_id, strlen (platform_id) + 1,
|
||||
true, 0);
|
||||
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);
|
||||
|
|
|
@ -48,10 +48,11 @@ int pcd_manager_remove_observer (struct pcd_manager *manager, struct pcd_observe
|
|||
* Initialize the base PCD manager.
|
||||
*
|
||||
* @param manager The manager to initialize.
|
||||
* @param hash The hash engine to generate measurement data.
|
||||
*
|
||||
* @return 0 if the PCD manager was initialized successfully or an error code.
|
||||
*/
|
||||
int pcd_manager_init (struct pcd_manager *manager)
|
||||
int pcd_manager_init (struct pcd_manager *manager, struct hash_engine *hash)
|
||||
{
|
||||
int status;
|
||||
|
||||
|
@ -62,7 +63,7 @@ int pcd_manager_init (struct pcd_manager *manager)
|
|||
return status;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return manifest_manager_init (&manager->base, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,3 +198,38 @@ int pcd_manager_get_platform_id_measured_data (struct pcd_manager *manager, size
|
|||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data used for PCD measurement. The PCD instance must be released with the
|
||||
* manager.
|
||||
*
|
||||
* @param manager The PCD manager to query.
|
||||
* @param offset The offset to read data from
|
||||
* @param buffer The output buffer to be filled with measured data
|
||||
* @param length Maximum length of the buffer.
|
||||
*
|
||||
* @return Length of the measured data if successfully retrieved or an error code.
|
||||
*/
|
||||
int pcd_manager_get_pcd_measured_data (struct pcd_manager *manager, size_t offset, uint8_t *buffer,
|
||||
size_t length)
|
||||
{
|
||||
int status;
|
||||
struct pcd *active;
|
||||
|
||||
if (manager == NULL) {
|
||||
return MANIFEST_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
active = manager->get_active_pcd (manager);
|
||||
if (active == NULL) {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, NULL, offset, buffer,
|
||||
length);
|
||||
}
|
||||
else {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, &active->base, offset,
|
||||
buffer, length);
|
||||
manager->free_pcd (manager, active);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ int pcd_manager_add_observer (struct pcd_manager *manager, struct pcd_observer *
|
|||
int pcd_manager_remove_observer (struct pcd_manager *manager, struct pcd_observer *observer);
|
||||
|
||||
/* Internal functions for use by derived types. */
|
||||
int pcd_manager_init (struct pcd_manager *manager);
|
||||
int pcd_manager_init (struct pcd_manager *manager, struct hash_engine *hash);
|
||||
void pcd_manager_release (struct pcd_manager *manager);
|
||||
|
||||
void pcd_manager_on_pcd_verified (struct pcd_manager *manager);
|
||||
|
@ -53,6 +53,8 @@ int pcd_manager_get_id_measured_data (struct pcd_manager *manager, size_t offset
|
|||
size_t length);
|
||||
int pcd_manager_get_platform_id_measured_data (struct pcd_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
int pcd_manager_get_pcd_measured_data (struct pcd_manager *manager, size_t offset, uint8_t *buffer,
|
||||
size_t length);
|
||||
|
||||
|
||||
#endif /* PCD_MANAGER_H_ */
|
||||
|
|
|
@ -189,7 +189,7 @@ int pcd_manager_flash_init (struct pcd_manager_flash *manager, struct pcd_flash
|
|||
|
||||
memset (manager, 0, sizeof (struct pcd_manager_flash));
|
||||
|
||||
status = pcd_manager_init (&manager->base);
|
||||
status = pcd_manager_init (&manager->base, hash);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -49,25 +49,26 @@ int pfm_manager_remove_observer (struct pfm_manager *manager, struct pfm_observe
|
|||
*
|
||||
* @param manager The manager to initialize.
|
||||
* @param port The port identifier for the manager. A negative value will use the default ID.
|
||||
* @param hash The hash engine to generate measurement data.
|
||||
*
|
||||
* @return 0 if the PFM manager was initialized successfully or an error code.
|
||||
*/
|
||||
int pfm_manager_init (struct pfm_manager *manager, int port)
|
||||
int pfm_manager_init (struct pfm_manager *manager, struct hash_engine *hash, int port)
|
||||
{
|
||||
int status;
|
||||
|
||||
memset (manager, 0, sizeof (struct pfm_manager));
|
||||
|
||||
if (port > 0) {
|
||||
manifest_manager_set_port (&manager->base, port);
|
||||
}
|
||||
|
||||
status = observable_init (&manager->observable);
|
||||
status = manifest_manager_init (&manager->base, hash);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (port > 0) {
|
||||
manifest_manager_set_port (&manager->base, port);
|
||||
}
|
||||
|
||||
return observable_init (&manager->observable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,5 +204,40 @@ int pfm_manager_get_platform_id_measured_data (struct pfm_manager *manager, size
|
|||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data used for PFM measurement. The PFM instance must be released with the
|
||||
* manager.
|
||||
*
|
||||
* @param manager The PFM manager to query.
|
||||
* @param offset The offset to read data from
|
||||
* @param buffer The output buffer to be filled with measured data
|
||||
* @param length Maximum length of the buffer.
|
||||
*
|
||||
* @return Length of the measured data if successfully retrieved or an error code.
|
||||
*/
|
||||
int pfm_manager_get_pfm_measured_data (struct pfm_manager *manager, size_t offset, uint8_t *buffer,
|
||||
size_t length)
|
||||
{
|
||||
int status;
|
||||
struct pfm *active;
|
||||
|
||||
if (manager == NULL) {
|
||||
return MANIFEST_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
active = manager->get_active_pfm (manager);
|
||||
if (active == NULL) {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, NULL, offset, buffer,
|
||||
length);
|
||||
}
|
||||
else {
|
||||
status = manifest_manager_get_manifest_measured_data (&manager->base, &active->base, offset,
|
||||
buffer, length);
|
||||
manager->free_pfm (manager, active);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ int pfm_manager_add_observer (struct pfm_manager *manager, struct pfm_observer *
|
|||
int pfm_manager_remove_observer (struct pfm_manager *manager, struct pfm_observer *observer);
|
||||
|
||||
/* Internal functions for use by derived types. */
|
||||
int pfm_manager_init (struct pfm_manager *manager, int port);
|
||||
int pfm_manager_init (struct pfm_manager *manager, struct hash_engine *hash, int port);
|
||||
void pfm_manager_release (struct pfm_manager *manager);
|
||||
|
||||
void pfm_manager_on_pfm_verified (struct pfm_manager *manager);
|
||||
|
@ -65,6 +65,8 @@ int pfm_manager_get_id_measured_data (struct pfm_manager *manager, size_t offset
|
|||
size_t length);
|
||||
int pfm_manager_get_platform_id_measured_data (struct pfm_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
int pfm_manager_get_pfm_measured_data (struct pfm_manager *manager, size_t offset, uint8_t *buffer,
|
||||
size_t length);
|
||||
|
||||
|
||||
#endif /* PFM_MANAGER_H_ */
|
||||
|
|
|
@ -265,7 +265,7 @@ int pfm_manager_flash_init_port (struct pfm_manager_flash *manager, struct pfm_f
|
|||
|
||||
memset (manager, 0, sizeof (struct pfm_manager_flash));
|
||||
|
||||
status = pfm_manager_init (&manager->base, port);
|
||||
status = pfm_manager_init (&manager->base, hash, port);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -600,3 +600,49 @@ int recovery_image_manager_get_port (struct recovery_image_manager *manager)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data used for recovery image measurement. The recovery image instance must be released
|
||||
* with the manager.
|
||||
*
|
||||
* @param manager The recovery image manager to query.
|
||||
* @param offset The offset to read data from
|
||||
* @param buffer The output buffer to be filled with measured data
|
||||
* @param length Maximum length of the buffer.
|
||||
*
|
||||
* @return Length of the measured data if successfully retrieved or an error code.
|
||||
*/
|
||||
int recovery_image_manager_get_measured_data (struct recovery_image_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length)
|
||||
{
|
||||
uint8_t hash_out[SHA256_HASH_LENGTH] = {0};
|
||||
int status = 0;
|
||||
struct recovery_image *active;
|
||||
size_t bytes_read;
|
||||
|
||||
if ((buffer == NULL) || (manager == NULL)) {
|
||||
return RECOVERY_IMAGE_MANAGER_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (offset > (SHA256_HASH_LENGTH - 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
active = manager->get_active_recovery_image (manager);
|
||||
if (active) {
|
||||
status = active->get_hash (active, manager->hash, hash_out, sizeof (hash_out));
|
||||
if (status != 0) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
bytes_read = ((SHA256_HASH_LENGTH - offset) > length) ? length : (SHA256_HASH_LENGTH - offset);
|
||||
|
||||
memcpy (buffer, hash_out + offset, bytes_read);
|
||||
|
||||
exit:
|
||||
if (active) {
|
||||
manager->free_recovery_image (manager, active);
|
||||
}
|
||||
|
||||
return (status == 0) ? bytes_read : status;
|
||||
}
|
||||
|
|
|
@ -152,6 +152,9 @@ int recovery_image_manager_remove_observer (struct recovery_image_manager *manag
|
|||
void recovery_image_manager_set_port (struct recovery_image_manager *manager, int port);
|
||||
int recovery_image_manager_get_port (struct recovery_image_manager *manager);
|
||||
|
||||
int recovery_image_manager_get_measured_data (struct recovery_image_manager *manager, size_t offset,
|
||||
uint8_t *buffer, size_t length);
|
||||
|
||||
|
||||
#define RECOVERY_IMAGE_MANAGER_ERROR(code) ROT_ERROR (ROT_MODULE_RECOVERY_IMAGE_MANAGER, code)
|
||||
|
||||
|
|
|
@ -14,17 +14,25 @@ static void recovery_image_observer_pcr_on_recovery_image_activated (
|
|||
{
|
||||
struct recovery_image_observer_pcr *pcr = (struct recovery_image_observer_pcr*) observer;
|
||||
uint8_t measurement[SHA256_HASH_LENGTH];
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
int status;
|
||||
|
||||
status = active->get_hash (active, pcr->hash, measurement, sizeof (measurement));
|
||||
if (active == NULL) {
|
||||
status = pcr->hash->calculate_sha256 (pcr->hash, zero, SHA256_HASH_LENGTH, measurement,
|
||||
sizeof (measurement));
|
||||
}
|
||||
else {
|
||||
status = active->get_hash (active, pcr->hash, measurement, sizeof (measurement));
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_RECOVERY_IMAGE,
|
||||
RECOVERY_IMAGE_LOGGING_GET_MEASUREMENT_FAIL, pcr->measurement_id, status);
|
||||
return;
|
||||
}
|
||||
|
||||
status = pcr_store_update_digest (pcr->store, pcr->measurement_id, measurement,
|
||||
SHA256_HASH_LENGTH);
|
||||
status = pcr_store_update_versioned_buffer (pcr->store, pcr->hash, pcr->measurement_id, measurement,
|
||||
SHA256_HASH_LENGTH, true, 0);
|
||||
if (status != 0) {
|
||||
debug_log_create_entry (DEBUG_LOG_SEVERITY_ERROR, DEBUG_LOG_COMPONENT_RECOVERY_IMAGE,
|
||||
RECOVERY_IMAGE_LOGGING_RECORD_MEASUREMENT_FAIL, pcr->measurement_id, status);
|
||||
|
@ -108,8 +116,8 @@ void recovery_image_observer_pcr_record_measurement (struct recovery_image_obser
|
|||
}
|
||||
|
||||
active = manager->get_active_recovery_image (manager);
|
||||
recovery_image_observer_pcr_on_recovery_image_activated (&observer->base, active);
|
||||
if (active) {
|
||||
recovery_image_observer_pcr_on_recovery_image_activated (&observer->base, active);
|
||||
manager->free_recovery_image (manager, active);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,14 @@ const uint8_t CFM_HASH[] = {
|
|||
0x0f,0xa4,0xeb,0xb4,0xdf,0x50,0x5a,0xed,0x89,0xcb,0xee,0xb1,0x07,0xb4,0x90,0x86
|
||||
};
|
||||
|
||||
/**
|
||||
* CFM_DATA hash digest for testing.
|
||||
*/
|
||||
const uint8_t CFM_HASH_DIGEST[] = {
|
||||
0x69,0x8e,0x6a,0xbd,0x62,0xdd,0xa6,0x16,0x2e,0xaf,0x15,0xc6,0x0a,0x69,0xbe,0x6e,
|
||||
0x3f,0xb9,0xbc,0xad,0xbf,0x61,0xd1,0xba,0xb9,0x9a,0xc1,0x07,0x8d,0x6d,0xab,0x02
|
||||
};
|
||||
|
||||
/**
|
||||
* Length of the test CFM hash.
|
||||
*/
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mock/cfm_mock.h"
|
||||
#include "mock/cfm_manager_mock.h"
|
||||
#include "mock/cfm_observer_mock.h"
|
||||
#include "cfm_testing.h"
|
||||
|
||||
|
||||
static const char *SUITE = "cfm_manager";
|
||||
|
@ -847,6 +848,209 @@ static void cfm_manager_test_get_platform_id_measured_data_fail (CuTest *test)
|
|||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data (CuTest *test)
|
||||
{
|
||||
struct cfm_mock cfm;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_mock_init (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_cfm, &manager,
|
||||
(intptr_t) &cfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_cfm, &manager,
|
||||
0, MOCK_ARG (&cfm.base));
|
||||
|
||||
status |= mock_expect (&cfm.mock, cfm.base.base.get_hash, &cfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&cfm.mock, 1, CFM_HASH, CFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, CFM_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, buffer, CFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_mock_validate_and_release (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data_offset (CuTest *test)
|
||||
{
|
||||
struct cfm_mock cfm;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_mock_init (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_cfm, &manager,
|
||||
(intptr_t) &cfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_cfm, &manager,
|
||||
0, MOCK_ARG (&cfm.base));
|
||||
|
||||
status |= mock_expect (&cfm.mock, cfm.base.base.get_hash, &cfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&cfm.mock, 1, CFM_HASH, CFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (&manager.base, offset, buffer, length);
|
||||
CuAssertIntEquals (test, CFM_HASH_LEN - offset, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH + 2, buffer, CFM_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_mock_validate_and_release (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data_small_buffer (CuTest *test)
|
||||
{
|
||||
struct cfm_mock cfm;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_mock_init (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_cfm, &manager,
|
||||
(intptr_t) &cfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_cfm, &manager,
|
||||
0, MOCK_ARG (&cfm.base));
|
||||
|
||||
status |= mock_expect (&cfm.mock, cfm.base.base.get_hash, &cfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&cfm.mock, 1, CFM_HASH, CFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (&manager.base, 0, buffer,
|
||||
SHA256_HASH_LENGTH - 2);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - 2, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, buffer, CFM_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_mock_validate_and_release (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data_no_active_cfm (CuTest *test)
|
||||
{
|
||||
struct cfm_mock cfm;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_mock_init (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_cfm, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, sizeof (zero));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_mock_validate_and_release (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data_null (CuTest *test)
|
||||
{
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (NULL, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
}
|
||||
|
||||
static void cfm_manager_test_get_cfm_measured_data_fail (CuTest *test)
|
||||
{
|
||||
struct cfm_mock cfm;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = cfm_mock_init (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_cfm, &manager,
|
||||
(intptr_t) &cfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_cfm, &manager,
|
||||
0, MOCK_ARG (&cfm.base));
|
||||
|
||||
status |= mock_expect (&cfm.mock, cfm.base.base.get_hash, &cfm, MANIFEST_GET_HASH_FAILED,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_get_cfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_GET_HASH_FAILED, status);
|
||||
|
||||
status = cfm_mock_validate_and_release (&cfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = cfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
|
||||
CuSuite* get_cfm_manager_suite ()
|
||||
{
|
||||
|
@ -876,6 +1080,12 @@ CuSuite* get_cfm_manager_suite ()
|
|||
SUITE_ADD_TEST (suite, cfm_manager_test_get_platform_id_measured_data_no_active_cfm);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_platform_id_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_platform_id_measured_data_fail);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data_offset);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data_small_buffer);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data_no_active_cfm);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, cfm_manager_test_get_cfm_measured_data_fail);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ static const char *SUITE = "cfm_observer_pcr";
|
|||
|
||||
|
||||
/**
|
||||
* CFM_PLATFORM_ID hash for testing.
|
||||
* Hash for CFM platform ID "CFM Test1", event type 0xaabbccdd, and version 0x0 for testing.
|
||||
*/
|
||||
static const uint8_t CFM_PLATFORM_ID_HASH[] = {
|
||||
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
|
||||
0xe8,0xe0,0xf5,0x96,0x6a,0x87,0x44,0xf0,0x74,0x24,0xaa,0xec,0x0d,0xcb,0xac,0xc6,
|
||||
0x32,0xce,0x3f,0xe3,0x6b,0x55,0xe8,0xd7,0x19,0x6f,0x15,0xb3,0x69,0x53,0x87,0xbb
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -201,6 +201,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -243,7 +246,7 @@ static void cfm_observer_pcr_test_on_cfm_activated (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, CFM_HASH_LEN);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, CFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -356,6 +359,7 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_id_error (CuTest *test)
|
|||
struct pcr_measurement id_measurement;
|
||||
struct pcr_measurement platform_id_measurement;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -372,6 +376,9 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -398,7 +405,7 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -446,6 +453,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -485,7 +495,7 @@ static void cfm_observer_pcr_test_on_cfm_activated_get_platform_id_error (CuTest
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, CFM_HASH_LEN);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, CFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -542,6 +552,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -597,7 +610,7 @@ static void cfm_observer_pcr_test_record_measurement (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, CFM_HASH_LEN);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, CFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -648,6 +661,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -689,7 +705,8 @@ static void cfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (EMPTY_BUFFER_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (ZERO_BUFFER_HASH_DIGEST, measurement.digest,
|
||||
SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -875,6 +892,7 @@ static void cfm_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
struct pcr_measurement id_measurement;
|
||||
struct cfm_manager_mock manager;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -894,6 +912,9 @@ static void cfm_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -923,7 +944,7 @@ static void cfm_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -967,6 +988,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -1012,7 +1036,7 @@ static void cfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (CFM_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (CFM_HASH_DIGEST, measurement.digest, SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
|
|
@ -20,6 +20,7 @@ extern const uint32_t CFM2_DATA_LEN;
|
|||
extern const uint8_t *CFM2_SIGNATURE;
|
||||
|
||||
extern const uint8_t CFM_HASH[];
|
||||
extern const uint8_t CFM_HASH_DIGEST[];
|
||||
extern const uint8_t CFM2_HASH[];
|
||||
extern const uint32_t CFM_HASH_LEN;
|
||||
|
||||
|
|
|
@ -16,35 +16,36 @@
|
|||
static const char *SUITE = "host_processor_observer_pcr";
|
||||
|
||||
/**
|
||||
* Digest of the number 0. This indicates valid FW in active mode.
|
||||
* Digest of the number 0 with event type 0xaabbccdd and version 0x0. This indicates valid FW in
|
||||
* active mode.
|
||||
*/
|
||||
static const uint8_t DIGEST_ZERO[] = {
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
/**
|
||||
* Digest of the state indicating bypass mode.
|
||||
* Digest of the state indicating bypass mode with event type 0xaabbccdd and version 0x0.
|
||||
*/
|
||||
static const uint8_t DIGEST_BYPASS[] = {
|
||||
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
|
||||
0xa2,0xe2,0x43,0x21,0x71,0x34,0x36,0xa7,0xa8,0xa2,0xb0,0x06,0x0f,0x18,0xb8,0x1a,
|
||||
0xb2,0xb1,0x8f,0xa5,0x4d,0x19,0x76,0xea,0xa7,0xfe,0x45,0xda,0x02,0x00,0x4e,0xe6
|
||||
};
|
||||
|
||||
/**
|
||||
* Digest of the state indicating recovery mode.
|
||||
* Digest of the state indicating recovery mode with event type 0xaabbccdd and version 0x0.
|
||||
*/
|
||||
static const uint8_t DIGEST_RECOVERY[] = {
|
||||
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
|
||||
0xe7,0xf4,0x3e,0x01,0xe6,0x52,0x1b,0xcc,0x6a,0x7d,0x4a,0xa0,0x7d,0x6a,0x02,0xdb,
|
||||
0x8f,0x39,0x12,0x06,0x44,0xc3,0x07,0x84,0xf4,0xd0,0x13,0x2f,0x8b,0x1d,0xfb,0xc6
|
||||
};
|
||||
|
||||
/**
|
||||
* Digest of the initial state.
|
||||
* Digest of the initial state with event type 0xaabbccdd and version 0x0 for testing.
|
||||
*/
|
||||
static const uint8_t DIGEST_INIT[] = {
|
||||
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
|
||||
0x74,0x47,0xfb,0x73,0xef,0xb5,0x87,0xea,0x5f,0xb1,0x69,0xc3,0xae,0xa0,0xcc,0xd1,
|
||||
0x69,0x8a,0xe2,0x28,0x52,0x4d,0xe9,0xd2,0xb7,0x4c,0xc0,0x55,0xa0,0x17,0x76,0x48
|
||||
};
|
||||
|
||||
|
||||
|
@ -274,6 +275,7 @@ static void host_processor_observer_pcr_test_on_bypass_mode_error (CuTest *test)
|
|||
.arg2 = HASH_ENGINE_UPDATE_FAILED
|
||||
};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
uint8_t version = 0;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -292,6 +294,8 @@ static void host_processor_observer_pcr_test_on_bypass_mode_error (CuTest *test)
|
|||
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_NOT_NULL,
|
||||
MOCK_ARG (sizeof (uint32_t)));
|
||||
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
|
||||
|
@ -396,6 +400,7 @@ static void host_processor_observer_pcr_test_on_active_mode_error (CuTest *test)
|
|||
.arg2 = HASH_ENGINE_UPDATE_FAILED
|
||||
};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
uint8_t version = 0;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -414,6 +419,8 @@ static void host_processor_observer_pcr_test_on_active_mode_error (CuTest *test)
|
|||
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_NOT_NULL,
|
||||
MOCK_ARG (sizeof (uint32_t)));
|
||||
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
|
||||
|
@ -518,6 +525,7 @@ static void host_processor_observer_pcr_test_on_recovery_error (CuTest *test)
|
|||
.arg2 = HASH_ENGINE_UPDATE_FAILED
|
||||
};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
uint8_t version = 0;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -536,6 +544,8 @@ static void host_processor_observer_pcr_test_on_recovery_error (CuTest *test)
|
|||
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_NOT_NULL,
|
||||
MOCK_ARG (sizeof (uint32_t)));
|
||||
status |= mock_expect (&hash.mock, hash.base.finish, &hash, 0, MOCK_ARG_NOT_NULL,
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "testing.h"
|
||||
#include "manifest/manifest_manager.h"
|
||||
#include "mock/manifest_mock.h"
|
||||
#include "mock/hash_mock.h"
|
||||
#include "pfm_testing.h"
|
||||
|
||||
|
||||
static const char *SUITE = "manifest_manager";
|
||||
|
@ -16,6 +18,45 @@ static const char *SUITE = "manifest_manager";
|
|||
* Test cases
|
||||
*******************/
|
||||
|
||||
static void manifest_manager_test_init (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_init_null (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (NULL, &hash.base);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
status = manifest_manager_init (&manager, NULL);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_set_port (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
|
@ -43,6 +84,413 @@ static void manifest_manager_test_get_port_null (CuTest *test)
|
|||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manifest.mock, manifest.base.get_hash, &manifest, 0,
|
||||
MOCK_ARG (&hash.base), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&manifest.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base, 0, buffer,
|
||||
length);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, buffer, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_with_offset (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manifest.mock, manifest.base.get_hash, &manifest, 0,
|
||||
MOCK_ARG (&hash.base), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&manifest.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base, offset, buffer,
|
||||
length);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN - offset, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH + offset, buffer, PFM_HASH_LEN - offset);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_small_buffer (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manifest.mock, manifest.base.get_hash, &manifest, 0,
|
||||
MOCK_ARG (&hash.base), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&manifest.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base, 0, buffer,
|
||||
length - 2);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN - 2, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, buffer, PFM_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer + PFM_HASH_LEN - 2, sizeof (zero));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_small_buffer_with_offset (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[4] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manifest.mock, manifest.base.get_hash, &manifest, 0,
|
||||
MOCK_ARG (&hash.base), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&manifest.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base, offset, buffer,
|
||||
length - 4);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN - 4, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH + offset, buffer, PFM_HASH_LEN - 4);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer + PFM_HASH_LEN - 4, sizeof (zero));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_no_active (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, NULL, 0, buffer, length);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_no_active_with_offset (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, NULL, offset, buffer, length);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - offset, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, SHA256_HASH_LENGTH - offset);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_no_active_small_buffer (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, NULL, 0, buffer, length - 2);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - 2, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, SHA256_HASH_LENGTH - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_no_active_small_buffer_with_offset (
|
||||
CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH] = {0};
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 4] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, NULL, offset, buffer,
|
||||
length - 4);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - 4, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, SHA256_HASH_LENGTH - 4);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_invalid_offset (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base,
|
||||
SHA256_HASH_LENGTH, buffer, length);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_no_active_invalid_offset (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, NULL, SHA256_HASH_LENGTH,
|
||||
buffer, length);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_measured_data_null (CuTest *test)
|
||||
{
|
||||
struct manifest_manager manager;
|
||||
struct hash_engine_mock hash;
|
||||
struct manifest_mock manifest;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = hash_mock_init (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_init (&manager, &hash.base);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_mock_init (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (NULL, &manifest.base, SHA256_HASH_LENGTH,
|
||||
buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
status = manifest_manager_get_manifest_measured_data (&manager, &manifest.base, SHA256_HASH_LENGTH,
|
||||
NULL, length);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
status = manifest_mock_validate_and_release (&manifest);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = hash_mock_validate_and_release (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void manifest_manager_test_get_manifest_id_measured_data (CuTest *test)
|
||||
{
|
||||
struct manifest_mock manifest;
|
||||
|
@ -592,9 +1040,25 @@ CuSuite* get_manifest_manager_suite ()
|
|||
{
|
||||
CuSuite *suite = CuSuiteNew ();
|
||||
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_init);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_init_null);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_set_port);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_set_port_null);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_port_null);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_with_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_small_buffer);
|
||||
SUITE_ADD_TEST (suite,
|
||||
manifest_manager_test_get_manifest_measured_data_small_buffer_with_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_no_active);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_no_active_with_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_no_active_small_buffer);
|
||||
SUITE_ADD_TEST (suite,
|
||||
manifest_manager_test_get_manifest_measured_data_no_active_small_buffer_with_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_invalid_offset);
|
||||
SUITE_ADD_TEST (suite,
|
||||
manifest_manager_test_get_manifest_measured_data_no_active_invalid_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_id_measured_data);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_id_measured_data_with_offset);
|
||||
SUITE_ADD_TEST (suite, manifest_manager_test_get_manifest_id_measured_data_small_buffer);
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
|
||||
/**
|
||||
* Hash for manifest with ID 0x1 for testing.
|
||||
* Hash for manifest with ID 0x1, event type 0xaabbccdd, and version 0x0 for testing.
|
||||
*/
|
||||
const uint8_t MANIFEST_ID_HASH[] = {
|
||||
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
|
||||
0x32,0x9a,0x30,0xcd,0xad,0x71,0xf3,0xee,0x8d,0xc6,0xf7,0x6c,0xf2,0xf9,0x6a,0x16,
|
||||
0xce,0x2b,0x56,0xa7,0x77,0x70,0xe5,0x29,0xd2,0xc9,0x46,0x71,0x09,0x52,0xcd,0x9a
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -19,11 +19,11 @@ const uint8_t MANIFEST_ID_HASH[] = {
|
|||
const uint32_t MANIFEST_ID_HASH_LEN = sizeof (MANIFEST_ID_HASH);
|
||||
|
||||
/**
|
||||
* Hash for testing no manifest.
|
||||
* Hash for testing no manifest with event type 0xaabbccdd and version 0x0.
|
||||
*/
|
||||
const uint8_t NO_MANIFEST_ID_HASH[] = {
|
||||
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
|
||||
0xbf,0xa1,0x8b,0xeb,0x32,0x20,0xbe,0x09,0xd8,0xb6,0x62,0xa7,0xd9,0x08,0x8e,0x21,
|
||||
0x7b,0x4e,0x0e,0x96,0x32,0x37,0x98,0x72,0x0c,0xc5,0xe6,0x5c,0xba,0xf8,0x3c,0x65
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -39,17 +39,47 @@ const uint8_t EMPTY_BUFFER_HASH[] = {
|
|||
0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55
|
||||
};
|
||||
|
||||
/**
|
||||
* Hash digest for testing an empty buffer with event type 0xaabbccdd and version 0x0.
|
||||
*/
|
||||
const uint8_t EMPTY_BUFFER_HASH_DIGEST[] = {
|
||||
0x9e,0x31,0x88,0xc5,0x96,0x4b,0xc0,0x22,0x7f,0x09,0x30,0x4e,0x3e,0xde,0x84,0xb8,
|
||||
0x1e,0xe8,0x8d,0x55,0x2d,0xa1,0x35,0x59,0x35,0xfb,0x32,0xe5,0x56,0xf7,0xab,0xc7
|
||||
};
|
||||
|
||||
/**
|
||||
* Length of an empty buffer hash.
|
||||
*/
|
||||
const uint32_t EMPTY_BUFFER_HASH_LEN = sizeof (EMPTY_BUFFER_HASH);
|
||||
|
||||
/**
|
||||
* Hash for testing a manifest with an empty string platform identifier.
|
||||
* Hash for testing a zero buffer.
|
||||
*/
|
||||
const uint8_t ZERO_BUFFER_HASH[] = {
|
||||
0x66,0x68,0x7a,0xad,0xf8,0x62,0xbd,0x77,0x6c,0x8f,0xc1,0x8b,0x8e,0x9f,0x8e,0x20,
|
||||
0x08,0x97,0x14,0x85,0x6e,0xe2,0x33,0xb3,0x90,0x2a,0x59,0x1d,0x0d,0x5f,0x29,0x25
|
||||
};
|
||||
|
||||
/**
|
||||
* Hash digest for testing a zero buffer with event type 0xaabbccdd and version 0x0.
|
||||
*/
|
||||
const uint8_t ZERO_BUFFER_HASH_DIGEST[] = {
|
||||
0x79,0x66,0xdb,0x4e,0xd9,0xad,0x6c,0x60,0xbb,0xa3,0xf6,0xff,0x62,0xc5,0x04,0x57,
|
||||
0x81,0x62,0xbb,0xd6,0xa2,0x42,0x9f,0x18,0xba,0x21,0x05,0x92,0x7c,0x0b,0xd7,0x3d
|
||||
};
|
||||
|
||||
/**
|
||||
* Length of a zero buffer hash.
|
||||
*/
|
||||
const uint32_t ZERO_BUFFER_HASH_LEN = sizeof (ZERO_BUFFER_HASH);
|
||||
|
||||
/**
|
||||
* Hash for testing a manifest with an empty string platform identifier, event type 0xaabbccdd, and
|
||||
* version 0x0.
|
||||
*/
|
||||
const uint8_t EMPTY_STRING_HASH[] = {
|
||||
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
|
||||
0x6f,0x61,0x6e,0xe6,0xbb,0xe4,0x0b,0xeb,0xf4,0xf8,0x00,0x6b,0xba,0x55,0xb2,0x36,
|
||||
0x65,0xde,0x39,0xcb,0xf2,0xdc,0x5e,0xef,0x76,0xb2,0x6e,0x4b,0xec,0xf3,0x4b,0x61
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,10 +12,15 @@ extern const uint8_t NO_MANIFEST_ID_HASH[];
|
|||
extern const uint32_t NO_MANIFEST_ID_HASH_LEN;
|
||||
|
||||
extern const uint8_t EMPTY_BUFFER_HASH[];
|
||||
extern const uint32_t EMPTY_BUFFER_ID_HASH_LEN;
|
||||
extern const uint8_t EMPTY_BUFFER_HASH_DIGEST[];
|
||||
extern const uint32_t EMPTY_BUFFER_HASH_LEN;
|
||||
|
||||
extern const uint8_t EMPTY_STRING_HASH[];
|
||||
extern const uint32_t EMPTY_STRING_HASH_LEN;
|
||||
|
||||
extern const uint8_t ZERO_BUFFER_HASH[];
|
||||
extern const uint8_t ZERO_BUFFER_HASH_DIGEST[];
|
||||
extern const uint32_t ZERO_BUFFER_HASH_LEN;
|
||||
|
||||
|
||||
#endif /* MANIFEST_OBSERVER_PCR_TESTING_H_ */
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "cfm_manager_mock.h"
|
||||
#include "testing/engines/hash_testing_engine.h"
|
||||
|
||||
|
||||
static struct cfm* cfm_manager_mock_get_active_cfm (struct cfm_manager *manager)
|
||||
|
@ -178,6 +179,7 @@ static const char* cfm_manager_mock_arg_name_map (void *func, int arg)
|
|||
*/
|
||||
int cfm_manager_mock_init (struct cfm_manager_mock *mock)
|
||||
{
|
||||
HASH_TESTING_ENGINE *hash;
|
||||
int status;
|
||||
|
||||
if (mock == NULL) {
|
||||
|
@ -186,13 +188,26 @@ int cfm_manager_mock_init (struct cfm_manager_mock *mock)
|
|||
|
||||
memset (mock, 0, sizeof (struct cfm_manager_mock));
|
||||
|
||||
status = cfm_manager_init (&mock->base);
|
||||
hash = platform_malloc (sizeof (HASH_TESTING_ENGINE));
|
||||
if (hash == NULL) {
|
||||
return MOCK_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (hash);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = cfm_manager_init (&mock->base, &hash->base);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = mock_init (&mock->mock);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
cfm_manager_release (&mock->base);
|
||||
return status;
|
||||
}
|
||||
|
@ -223,6 +238,8 @@ int cfm_manager_mock_init (struct cfm_manager_mock *mock)
|
|||
void cfm_manager_mock_release (struct cfm_manager_mock *mock)
|
||||
{
|
||||
if (mock) {
|
||||
HASH_TESTING_ENGINE_RELEASE ((HASH_TESTING_ENGINE*) mock->base.base.hash);
|
||||
platform_free (mock->base.base.hash);
|
||||
cfm_manager_release (&mock->base);
|
||||
mock_release (&mock->mock);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "pcd_manager_mock.h"
|
||||
#include "testing/engines/hash_testing_engine.h"
|
||||
|
||||
|
||||
static struct pcd* pcd_manager_mock_get_active_pcd (struct pcd_manager *manager)
|
||||
|
@ -150,6 +151,7 @@ static const char* pcd_manager_mock_arg_name_map (void *func, int arg)
|
|||
*/
|
||||
int pcd_manager_mock_init (struct pcd_manager_mock *mock)
|
||||
{
|
||||
HASH_TESTING_ENGINE *hash;
|
||||
int status;
|
||||
|
||||
if (mock == NULL) {
|
||||
|
@ -158,13 +160,26 @@ int pcd_manager_mock_init (struct pcd_manager_mock *mock)
|
|||
|
||||
memset (mock, 0, sizeof (struct pcd_manager_mock));
|
||||
|
||||
status = pcd_manager_init (&mock->base);
|
||||
hash = platform_malloc (sizeof (HASH_TESTING_ENGINE));
|
||||
if (hash == NULL) {
|
||||
return MOCK_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (hash);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = pcd_manager_init (&mock->base, &hash->base);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = mock_init (&mock->mock);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
pcd_manager_release (&mock->base);
|
||||
return status;
|
||||
}
|
||||
|
@ -193,6 +208,8 @@ int pcd_manager_mock_init (struct pcd_manager_mock *mock)
|
|||
void pcd_manager_mock_release (struct pcd_manager_mock *mock)
|
||||
{
|
||||
if (mock) {
|
||||
HASH_TESTING_ENGINE_RELEASE ((HASH_TESTING_ENGINE*) mock->base.base.hash);
|
||||
platform_free (mock->base.base.hash);
|
||||
pcd_manager_release (&mock->base);
|
||||
mock_release (&mock->mock);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "pfm_manager_mock.h"
|
||||
#include "testing/engines/hash_testing_engine.h"
|
||||
|
||||
|
||||
static struct pfm* pfm_manager_mock_get_active_pfm (struct pfm_manager *manager)
|
||||
|
@ -180,6 +181,7 @@ static const char* pfm_manager_mock_arg_name_map (void *func, int arg)
|
|||
*/
|
||||
int pfm_manager_mock_init (struct pfm_manager_mock *mock)
|
||||
{
|
||||
HASH_TESTING_ENGINE *hash;
|
||||
int status;
|
||||
|
||||
if (mock == NULL) {
|
||||
|
@ -188,13 +190,26 @@ int pfm_manager_mock_init (struct pfm_manager_mock *mock)
|
|||
|
||||
memset (mock, 0, sizeof (struct pfm_manager_mock));
|
||||
|
||||
status = pfm_manager_init (&mock->base, -1);
|
||||
hash = platform_malloc (sizeof (HASH_TESTING_ENGINE));
|
||||
if (hash == NULL) {
|
||||
return MOCK_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (hash);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = pfm_manager_init (&mock->base, &hash->base, -1);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = mock_init (&mock->mock);
|
||||
if (status != 0) {
|
||||
platform_free (hash);
|
||||
pfm_manager_release (&mock->base);
|
||||
return status;
|
||||
}
|
||||
|
@ -225,6 +240,8 @@ int pfm_manager_mock_init (struct pfm_manager_mock *mock)
|
|||
void pfm_manager_mock_release (struct pfm_manager_mock *mock)
|
||||
{
|
||||
if (mock) {
|
||||
HASH_TESTING_ENGINE_RELEASE ((HASH_TESTING_ENGINE*) mock->base.base.hash);
|
||||
platform_free (mock->base.base.hash);
|
||||
pfm_manager_release (&mock->base);
|
||||
mock_release (&mock->mock);
|
||||
}
|
||||
|
|
|
@ -176,6 +176,14 @@ const uint8_t PCD_HASH[] = {
|
|||
0xe5,0x09,0xe0,0x89,0x3a,0x35,0x4c,0xa2,0x67,0x2c,0x17,0x09,0xc9,0xf7,0xfe,0x02
|
||||
};
|
||||
|
||||
/**
|
||||
* PCD_DATA hash digest for testing.
|
||||
*/
|
||||
const uint8_t PCD_HASH_DIGEST[] = {
|
||||
0x28,0x7e,0x97,0x09,0x8f,0xc6,0x6f,0xd3,0xd6,0x3f,0x42,0xfb,0x71,0xff,0x96,0xb7,
|
||||
0xf3,0x15,0xff,0xcc,0xd8,0xf4,0xb6,0x90,0x0b,0xe0,0x03,0xc0,0xb0,0x93,0x8e,0x4b
|
||||
};
|
||||
|
||||
/**
|
||||
* PCD2_DATA hash for testing.
|
||||
*/
|
||||
|
|
|
@ -795,6 +795,209 @@ static void pcd_manager_test_get_platform_id_measured_data_fail (CuTest *test)
|
|||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data (CuTest *test)
|
||||
{
|
||||
struct pcd_mock pcd;
|
||||
struct pcd_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_mock_init (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager,
|
||||
(intptr_t) &pcd.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pcd, &manager,
|
||||
0, MOCK_ARG (&pcd.base));
|
||||
|
||||
status |= mock_expect (&pcd.mock, pcd.base.base.get_hash, &pcd, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pcd.mock, 1, PCD_HASH, PCD_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, PCD_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, buffer, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_mock_validate_and_release (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data_offset (CuTest *test)
|
||||
{
|
||||
struct pcd_mock pcd;
|
||||
struct pcd_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_mock_init (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager,
|
||||
(intptr_t) &pcd.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pcd, &manager,
|
||||
0, MOCK_ARG (&pcd.base));
|
||||
|
||||
status |= mock_expect (&pcd.mock, pcd.base.base.get_hash, &pcd, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pcd.mock, 1, PCD_HASH, PCD_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (&manager.base, offset, buffer, length);
|
||||
CuAssertIntEquals (test, PCD_HASH_LEN - offset, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH + 2, buffer, PCD_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_mock_validate_and_release (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data_small_buffer (CuTest *test)
|
||||
{
|
||||
struct pcd_mock pcd;
|
||||
struct pcd_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_mock_init (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager,
|
||||
(intptr_t) &pcd.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pcd, &manager,
|
||||
0, MOCK_ARG (&pcd.base));
|
||||
|
||||
status |= mock_expect (&pcd.mock, pcd.base.base.get_hash, &pcd, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pcd.mock, 1, PCD_HASH, PCD_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (&manager.base, 0, buffer,
|
||||
SHA256_HASH_LENGTH - 2);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - 2, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, buffer, PCD_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_mock_validate_and_release (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data_no_active_pcd (CuTest *test)
|
||||
{
|
||||
struct pcd_mock pcd;
|
||||
struct pcd_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_mock_init (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, sizeof (zero));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_mock_validate_and_release (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data_null (CuTest *test)
|
||||
{
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (NULL, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
}
|
||||
|
||||
static void pcd_manager_test_get_pcd_measured_data_fail (CuTest *test)
|
||||
{
|
||||
struct pcd_mock pcd;
|
||||
struct pcd_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pcd_mock_init (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pcd, &manager,
|
||||
(intptr_t) &pcd.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pcd, &manager,
|
||||
0, MOCK_ARG (&pcd.base));
|
||||
|
||||
status |= mock_expect (&pcd.mock, pcd.base.base.get_hash, &pcd, MANIFEST_GET_HASH_FAILED,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_get_pcd_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_GET_HASH_FAILED, status);
|
||||
|
||||
status = pcd_mock_validate_and_release (&pcd);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcd_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
|
||||
CuSuite* get_pcd_manager_suite ()
|
||||
{
|
||||
|
@ -823,6 +1026,12 @@ CuSuite* get_pcd_manager_suite ()
|
|||
SUITE_ADD_TEST (suite, pcd_manager_test_get_platform_id_measured_data_no_active_pcd);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_platform_id_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_platform_id_measured_data_fail);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data_offset);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data_small_buffer);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data_no_active_pcd);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, pcd_manager_test_get_pcd_measured_data_fail);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ static const char *SUITE = "pcd_observer_pcr";
|
|||
|
||||
|
||||
/**
|
||||
* PCD_PLATFORM_ID hash for testing.
|
||||
* Hash for PCD_PLATFORM_ID, event type 0xaabbccdd, and version 0x0 for testing.
|
||||
*/
|
||||
static const uint8_t PCD_PLATFORM_ID_HASH[] = {
|
||||
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
|
||||
0x1d,0x48,0x95,0x10,0xd2,0xba,0x63,0xbe,0x08,0x60,0x65,0xba,0xa5,0x22,0x85,0x31,
|
||||
0xea,0x6f,0xef,0x81,0x84,0xed,0x06,0x09,0x47,0x8d,0xbd,0x04,0x76,0x7d,0x97,0xd3
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -200,6 +200,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -250,7 +253,7 @@ static void pcd_observer_pcr_test_on_pcd_activated (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -372,6 +375,7 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_id_error (CuTest *test)
|
|||
struct pcr_measurement id_measurement;
|
||||
struct pcr_measurement platform_id_measurement;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -388,6 +392,9 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -422,7 +429,7 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -470,6 +477,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -516,7 +526,7 @@ static void pcd_observer_pcr_test_on_pcd_activated_get_platform_id_error (CuTest
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -572,6 +582,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -626,7 +639,7 @@ static void pcd_observer_pcr_test_record_measurement (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -677,6 +690,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -717,7 +733,8 @@ static void pcd_observer_pcr_test_record_measurement_no_active (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (EMPTY_BUFFER_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (ZERO_BUFFER_HASH_DIGEST, measurement.digest,
|
||||
SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -932,6 +949,7 @@ static void pcd_observer_pcr_test_record_measurement_get_id_error (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;
|
||||
|
||||
|
@ -951,6 +969,9 @@ static void pcd_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -986,7 +1007,7 @@ static void pcd_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -1039,6 +1060,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -1091,7 +1115,7 @@ static void pcd_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PCD_HASH, measurement.digest, PCD_HASH_LEN);
|
||||
status = testing_validate_array (PCD_HASH_DIGEST, measurement.digest, PCD_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
|
|
@ -19,6 +19,7 @@ extern const uint8_t PCD2_DATA[];
|
|||
extern const uint32_t PCD2_DATA_LEN;
|
||||
|
||||
extern const uint8_t PCD_HASH[];
|
||||
extern const uint8_t PCD_HASH_DIGEST[];
|
||||
extern const uint8_t PCD2_HASH[];
|
||||
extern const uint32_t PCD_HASH_LEN;
|
||||
|
||||
|
|
|
@ -91,6 +91,14 @@ const uint8_t PFM_HASH[] = {
|
|||
0x09,0x49,0x72,0xb4,0x23,0xad,0xbc,0x7e,0xa1,0xe6,0x03,0x8d,0xe9,0x54,0x47,0xc2
|
||||
};
|
||||
|
||||
/**
|
||||
* PFM_DATA hash digest for testing.
|
||||
*/
|
||||
const uint8_t PFM_HASH_DIGEST[] = {
|
||||
0xaa,0xaa,0x53,0xe2,0x27,0x6c,0x19,0xaf,0x43,0x08,0x1a,0xdc,0xbf,0x92,0xda,0x65,
|
||||
0x08,0x15,0x0a,0xae,0x98,0xf2,0xf5,0x59,0x4b,0x08,0x8c,0x9f,0x09,0xb8,0x60,0xc8
|
||||
};
|
||||
|
||||
/**
|
||||
* Length of the test PFM hash.
|
||||
*/
|
||||
|
|
|
@ -846,6 +846,209 @@ static void pfm_manager_test_get_platform_id_measured_data_fail (CuTest *test)
|
|||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data (CuTest *test)
|
||||
{
|
||||
struct pfm_mock pfm;
|
||||
struct pfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_mock_init (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pfm, &manager,
|
||||
(intptr_t) &pfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pfm, &manager,
|
||||
0, MOCK_ARG (&pfm.base));
|
||||
|
||||
status |= mock_expect (&pfm.mock, pfm.base.base.get_hash, &pfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pfm.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, buffer, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_mock_validate_and_release (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data_offset (CuTest *test)
|
||||
{
|
||||
struct pfm_mock pfm;
|
||||
struct pfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_mock_init (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pfm, &manager,
|
||||
(intptr_t) &pfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pfm, &manager,
|
||||
0, MOCK_ARG (&pfm.base));
|
||||
|
||||
status |= mock_expect (&pfm.mock, pfm.base.base.get_hash, &pfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pfm.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (&manager.base, offset, buffer, length);
|
||||
CuAssertIntEquals (test, PFM_HASH_LEN - offset, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH + 2, buffer, PFM_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_mock_validate_and_release (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data_small_buffer (CuTest *test)
|
||||
{
|
||||
struct pfm_mock pfm;
|
||||
struct pfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_mock_init (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pfm, &manager,
|
||||
(intptr_t) &pfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pfm, &manager,
|
||||
0, MOCK_ARG (&pfm.base));
|
||||
|
||||
status |= mock_expect (&pfm.mock, pfm.base.base.get_hash, &pfm, 0,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&pfm.mock, 1, PFM_HASH, PFM_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (&manager.base, 0, buffer,
|
||||
SHA256_HASH_LENGTH - 2);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH - 2, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, buffer, PFM_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_mock_validate_and_release (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data_no_active_pfm (CuTest *test)
|
||||
{
|
||||
struct pfm_mock pfm;
|
||||
struct pfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_mock_init (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pfm, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, SHA256_HASH_LENGTH, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, sizeof (zero));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_mock_validate_and_release (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data_null (CuTest *test)
|
||||
{
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (NULL, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_MANAGER_INVALID_ARGUMENT, status);
|
||||
}
|
||||
|
||||
static void pfm_manager_test_get_pfm_measured_data_fail (CuTest *test)
|
||||
{
|
||||
struct pfm_mock pfm;
|
||||
struct pfm_manager_mock manager;
|
||||
uint8_t buffer[4224];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = pfm_mock_init (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_pfm, &manager,
|
||||
(intptr_t) &pfm.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_pfm, &manager,
|
||||
0, MOCK_ARG (&pfm.base));
|
||||
|
||||
status |= mock_expect (&pfm.mock, pfm.base.base.get_hash, &pfm, MANIFEST_GET_HASH_FAILED,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_get_pfm_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, MANIFEST_GET_HASH_FAILED, status);
|
||||
|
||||
status = pfm_mock_validate_and_release (&pfm);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
|
||||
CuSuite* get_pfm_manager_suite ()
|
||||
{
|
||||
|
@ -875,6 +1078,12 @@ CuSuite* get_pfm_manager_suite ()
|
|||
SUITE_ADD_TEST (suite, pfm_manager_test_get_platform_id_measured_data_no_active_pfm);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_platform_id_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_platform_id_measured_data_fail);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data_offset);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data_small_buffer);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data_no_active_pfm);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, pfm_manager_test_get_pfm_measured_data_fail);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ static const char *SUITE = "pfm_observer_pcr";
|
|||
|
||||
|
||||
/**
|
||||
* PFM_PLATFORM_ID hash for testing.
|
||||
* Hash for PFM platform ID PFM_PLATFORM_ID, event type 0xaabbccdd, and version 0x0 for testing.
|
||||
*/
|
||||
static const uint8_t PFM_PLATFORM_ID_HASH[] = {
|
||||
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
|
||||
0x5e,0x29,0x9f,0x2e,0x68,0x12,0x44,0x62,0x8c,0x51,0x7c,0x9a,0x21,0x0e,0x26,0x93,
|
||||
0x69,0x2b,0x08,0x64,0x5b,0xbb,0x84,0x5c,0x00,0x94,0x65,0x54,0xca,0xb8,0x14,0xdc
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -200,6 +200,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -251,7 +254,7 @@ static void pfm_observer_pcr_test_on_pfm_activated (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &manifest_measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, manifest_measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, manifest_measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &manifest_id_measurement);
|
||||
|
@ -371,6 +374,7 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_id_error (CuTest *test)
|
|||
struct pcr_measurement id_measurement;
|
||||
struct pcr_measurement platform_id_measurement;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -387,6 +391,9 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -413,7 +420,7 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -461,6 +468,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -507,7 +517,7 @@ static void pfm_observer_pcr_test_on_pfm_activated_get_platform_id_error (CuTest
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -563,6 +573,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -619,7 +632,7 @@ static void pfm_observer_pcr_test_record_measurement (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -670,6 +683,9 @@ 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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -711,7 +727,8 @@ static void pfm_observer_pcr_test_record_measurement_no_active (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (EMPTY_BUFFER_HASH, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (ZERO_BUFFER_HASH_DIGEST, measurement.digest,
|
||||
SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -932,6 +949,7 @@ static void pfm_observer_pcr_test_record_measurement_get_id_error (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;
|
||||
|
||||
|
@ -951,6 +969,9 @@ static void pfm_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 1), PCR_MEASUREMENT (0, 2));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -988,7 +1009,7 @@ static void pfm_observer_pcr_test_record_measurement_get_id_error (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
@ -1041,6 +1062,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], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 1, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -1094,7 +1118,7 @@ static void pfm_observer_pcr_test_record_measurement_get_platform_id_error (CuTe
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (PFM_HASH, measurement.digest, PFM_HASH_LEN);
|
||||
status = testing_validate_array (PFM_HASH_DIGEST, measurement.digest, PFM_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 1), &id_measurement);
|
||||
|
|
|
@ -35,6 +35,7 @@ extern const char *PFM_PLATFORM_ID;
|
|||
extern const size_t PFM_PLATFORM_ID_LEN;
|
||||
|
||||
extern const uint8_t PFM_HASH[];
|
||||
extern const uint8_t PFM_HASH_DIGEST[];
|
||||
extern const uint8_t PFM2_HASH[];
|
||||
extern const uint8_t PFM_PLATFORM2_HASH[];
|
||||
extern const uint32_t PFM_HASH_LEN;
|
||||
|
|
|
@ -15856,6 +15856,553 @@ static void recovery_image_manager_test_get_flash_update_manager_after_activate_
|
|||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&image.mock, image.base.get_hash, &image, 0, MOCK_ARG (&hash.base),
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&image.mock, 1, RECOVERY_IMAGE_HASH, RECOVERY_IMAGE_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, 0, buffer, length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH, buffer, RECOVERY_IMAGE_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_with_offset (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&image.mock, image.base.get_hash, &image, 0, MOCK_ARG (&hash.base),
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&image.mock, 1, RECOVERY_IMAGE_HASH, RECOVERY_IMAGE_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, offset, buffer, length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - offset, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH + 2, buffer, RECOVERY_IMAGE_HASH_LEN - offset);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_small_buffer (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&image.mock, image.base.get_hash, &image, 0, MOCK_ARG (&hash.base),
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&image.mock, 1, RECOVERY_IMAGE_HASH, RECOVERY_IMAGE_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, 0, buffer, length - 4);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - 4, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH, buffer, RECOVERY_IMAGE_HASH_LEN - 4);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_small_buffer_with_offset (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&image.mock, image.base.get_hash, &image, 0, MOCK_ARG (&hash.base),
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
status |= mock_expect_output (&image.mock, 1, RECOVERY_IMAGE_HASH, RECOVERY_IMAGE_HASH_LEN, 2);
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, offset, buffer, length - 4);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - 4, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH + offset, buffer,
|
||||
RECOVERY_IMAGE_HASH_LEN - 4);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_no_active (CuTest *test)
|
||||
{
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
uint8_t zero[SHA256_HASH_LENGTH] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_recovery_image, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, RECOVERY_IMAGE_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_no_active_with_offset (CuTest *test)
|
||||
{
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_recovery_image, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager.base, offset, buffer, length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - 2, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, RECOVERY_IMAGE_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_no_active_small_buffer (CuTest *test)
|
||||
{
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_recovery_image, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager.base, 0, buffer, length - 2);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - 2, status);
|
||||
|
||||
status = testing_validate_array (zero, buffer, RECOVERY_IMAGE_HASH_LEN - 2);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_no_active_small_buffer_with_offset (
|
||||
CuTest *test)
|
||||
{
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
uint8_t zero[SHA256_HASH_LENGTH - 2] = {0};
|
||||
size_t length = sizeof (buffer);
|
||||
size_t offset = 2;
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_recovery_image, &manager,
|
||||
(intptr_t) NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager.base, offset, buffer, length - 4);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_HASH_LEN - 4, status);
|
||||
|
||||
status = testing_validate_array (zero + offset, buffer, RECOVERY_IMAGE_HASH_LEN - 4);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_invalid_offset (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, SHA256_HASH_LENGTH, buffer,
|
||||
length);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_null (CuTest *test)
|
||||
{
|
||||
HASH_TESTING_ENGINE hash;
|
||||
struct recovery_image_manager manager;
|
||||
struct recovery_image_mock image;
|
||||
struct signature_verification_mock verification;
|
||||
struct pfm_manager_mock pfm_manager;
|
||||
struct flash_mock flash;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = HASH_TESTING_ENGINE_INIT (&hash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_init (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_init (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = signature_verification_mock_init (&verification);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
image.base.flash = &flash.base;
|
||||
image.base.addr = 0x10000;
|
||||
|
||||
status = mock_expect (&image.mock, image.base.verify, &image, 0, MOCK_ARG_NOT_NULL,
|
||||
MOCK_ARG_NOT_NULL, MOCK_ARG ((uintptr_t) NULL), MOCK_ARG (0), MOCK_ARG_NOT_NULL);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_init (&manager, &image.base, &hash.base,
|
||||
&verification.base, &pfm_manager.base, RECOVERY_IMAGE_MANAGER_IMAGE_MAX_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (NULL, SHA256_HASH_LENGTH, buffer,
|
||||
length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager, SHA256_HASH_LENGTH, NULL,
|
||||
length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_MANAGER_INVALID_ARGUMENT, status);
|
||||
|
||||
signature_verification_mock_release (&verification);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pfm_manager_mock_validate_and_release (&pfm_manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = flash_mock_validate_and_release (&flash);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
recovery_image_manager_release (&manager);
|
||||
|
||||
HASH_TESTING_ENGINE_RELEASE (&hash);
|
||||
}
|
||||
|
||||
static void recovery_image_manager_test_get_measured_data_fail (CuTest *test)
|
||||
{
|
||||
struct recovery_image_manager_mock manager;
|
||||
struct recovery_image_mock image;
|
||||
uint8_t buffer[SHA256_HASH_LENGTH];
|
||||
size_t length = sizeof (buffer);
|
||||
int status;
|
||||
|
||||
TEST_START;
|
||||
|
||||
status = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_mock_init (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&manager.mock, manager.base.get_active_recovery_image, &manager,
|
||||
(intptr_t) &image.base);
|
||||
status |= mock_expect (&manager.mock, manager.base.free_recovery_image, &manager,
|
||||
0, MOCK_ARG (&image.base));
|
||||
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = mock_expect (&image.mock, image.base.get_hash, &image, RECOVERY_IMAGE_GET_HASH_FAILED,
|
||||
MOCK_ARG (manager.base.hash), MOCK_ARG_NOT_NULL, MOCK_ARG (SHA256_HASH_LENGTH));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_get_measured_data (&manager.base, 0, buffer, length);
|
||||
CuAssertIntEquals (test, RECOVERY_IMAGE_GET_HASH_FAILED, status);
|
||||
|
||||
status = recovery_image_mock_validate_and_release (&image);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
}
|
||||
|
||||
|
||||
CuSuite* get_recovery_image_manager_suite ()
|
||||
{
|
||||
|
@ -16158,5 +16705,18 @@ CuSuite* get_recovery_image_manager_suite ()
|
|||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_flash_update_manager_null);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_flash_update_manager_after_activate_fail);
|
||||
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_with_offset);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_small_buffer);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_small_buffer_with_offset);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_no_active);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_no_active_with_offset);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_no_active_small_buffer);
|
||||
SUITE_ADD_TEST (suite,
|
||||
recovery_image_manager_test_get_measured_data_no_active_small_buffer_with_offset);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_invalid_offset);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_null);
|
||||
SUITE_ADD_TEST (suite, recovery_image_manager_test_get_measured_data_fail);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mock/recovery_image_manager_mock.h"
|
||||
#include "recovery_image_testing.h"
|
||||
#include "state_manager/state_manager.h"
|
||||
#include "manifest_observer_pcr_testing.h"
|
||||
|
||||
|
||||
static const char *SUITE = "recovery_image_observer_pcr";
|
||||
|
@ -116,6 +117,7 @@ static void recovery_image_observer_pcr_test_on_recovery_image_activated (CuTest
|
|||
struct recovery_image_mock image;
|
||||
struct pcr_measurement measurement;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -132,6 +134,9 @@ static void recovery_image_observer_pcr_test_on_recovery_image_activated (CuTest
|
|||
PCR_MEASUREMENT (0, 0));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -149,7 +154,7 @@ static void recovery_image_observer_pcr_test_on_recovery_image_activated (CuTest
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH, measurement.digest,
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH_DIGEST, measurement.digest,
|
||||
RECOVERY_IMAGE_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -227,6 +232,7 @@ static void recovery_image_observer_pcr_test_record_measurement (CuTest *test)
|
|||
struct pcr_measurement measurement;
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -246,6 +252,9 @@ static void recovery_image_observer_pcr_test_record_measurement (CuTest *test)
|
|||
PCR_MEASUREMENT (0, 0));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -269,7 +278,7 @@ static void recovery_image_observer_pcr_test_record_measurement (CuTest *test)
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH, measurement.digest,
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH_DIGEST, measurement.digest,
|
||||
RECOVERY_IMAGE_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -295,6 +304,7 @@ static void recovery_image_observer_pcr_test_record_measurement_no_active (CuTes
|
|||
struct pcr_measurement measurement;
|
||||
struct recovery_image_manager_mock manager;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -304,6 +314,9 @@ static void recovery_image_observer_pcr_test_record_measurement_no_active (CuTes
|
|||
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 = recovery_image_manager_mock_init (&manager);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -326,7 +339,7 @@ static void recovery_image_observer_pcr_test_record_measurement_no_active (CuTes
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (invalid_measurement, measurement.digest, SHA256_HASH_LENGTH);
|
||||
status = testing_validate_array (ZERO_BUFFER_HASH_DIGEST, measurement.digest, SHA256_HASH_LENGTH);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = recovery_image_manager_mock_validate_and_release (&manager);
|
||||
|
@ -466,6 +479,7 @@ static void recovery_image_observer_pcr_test_on_recovery_image_deactivated (CuTe
|
|||
struct recovery_image_mock image;
|
||||
struct pcr_measurement measurement;
|
||||
uint8_t invalid_measurement[SHA256_HASH_LENGTH] = {0};
|
||||
uint32_t event = 0xaabbccdd;
|
||||
|
||||
TEST_START;
|
||||
|
||||
|
@ -482,6 +496,9 @@ static void recovery_image_observer_pcr_test_on_recovery_image_deactivated (CuTe
|
|||
PCR_MEASUREMENT (0, 0));
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_update_event_type (&store.banks[0], 0, event);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
@ -499,7 +516,7 @@ static void recovery_image_observer_pcr_test_on_recovery_image_deactivated (CuTe
|
|||
status = pcr_store_get_measurement (&store, PCR_MEASUREMENT (0, 0), &measurement);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH, measurement.digest,
|
||||
status = testing_validate_array (RECOVERY_IMAGE_HASH_DIGEST, measurement.digest,
|
||||
RECOVERY_IMAGE_HASH_LEN);
|
||||
CuAssertIntEquals (test, 0, status);
|
||||
|
||||
|
|
|
@ -213,6 +213,14 @@ const uint8_t RECOVERY_IMAGE_HASH[] = {
|
|||
0xd5,0x64,0xce,0x87,0x2e,0xec,0x0b,0xc8,0x0c,0x55,0x00,0xdc,0xd6,0xae,0xc5,0x34
|
||||
};
|
||||
|
||||
/**
|
||||
* The SHA256 hash digest of the test recovery image data, not including the signature.
|
||||
*/
|
||||
const uint8_t RECOVERY_IMAGE_HASH_DIGEST[] = {
|
||||
0x8b,0xe6,0xf7,0x2d,0x68,0x38,0xf1,0xcc,0xb5,0x7b,0xc1,0xb9,0x9e,0xb3,0xe0,0x2a,
|
||||
0xb3,0xb1,0x75,0x1a,0xb3,0xdc,0x40,0xdf,0x8b,0x80,0x1e,0xfc,0x6b,0x06,0xd2,0xc5
|
||||
};
|
||||
|
||||
const uint8_t RECOVERY_IMAGE_HASH2[] = {
|
||||
0x87,0x44,0xfb,0x32,0x67,0x81,0xd7,0x26,0xc5,0xef,0x29,0x45,0xad,0xe4,0xdc,0xa2,
|
||||
0x26,0x0c,0x6c,0x1f,0x1f,0x81,0x24,0x1a,0x13,0xde,0x9e,0x69,0x2a,0x88,0x47,0xee,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
extern const uint8_t RECOVERY_IMAGE_DATA[];
|
||||
extern const uint32_t RECOVERY_IMAGE_DATA_LEN;
|
||||
extern const uint8_t RECOVERY_IMAGE_HASH[];
|
||||
extern const uint8_t RECOVERY_IMAGE_HASH_DIGEST[];
|
||||
extern const uint32_t RECOVERY_IMAGE_HASH_LEN;
|
||||
extern const uint32_t RECOVERY_IMAGE_SIGNATURE_OFFSET;
|
||||
extern const uint8_t *RECOVERY_IMAGE_SIGNATURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче