mirror of https://github.com/ARMmbed/mbed-os.git
parent
fcf60ec683
commit
a62b3591d9
|
@ -7,12 +7,12 @@ int mbed_default_seed_read(unsigned char *buf, size_t buf_len)
|
|||
{
|
||||
size_t actual_size;
|
||||
psa_status_t rc = psa_its_get(PSA_CRYPTO_ITS_RANDOM_SEED_UID, 0, buf_len, buf, &actual_size);
|
||||
return ( rc );
|
||||
return (rc);
|
||||
}
|
||||
|
||||
int mbed_default_seed_write(unsigned char *buf, size_t buf_len)
|
||||
{
|
||||
psa_status_t rc = psa_its_set(PSA_CRYPTO_ITS_RANDOM_SEED_UID, buf_len, buf, 0);
|
||||
return ( rc );
|
||||
return (rc);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,22 +29,21 @@ int32_t pal_attestation_function(int type, va_list valist)
|
|||
uint8_t *challenge, *token;
|
||||
uint32_t challenge_size, *token_size, verify_token_size;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case PAL_INITIAL_ATTEST_GET_TOKEN:
|
||||
challenge = va_arg(valist, uint8_t*);
|
||||
challenge = va_arg(valist, uint8_t *);
|
||||
challenge_size = va_arg(valist, uint32_t);
|
||||
token = va_arg(valist, uint8_t*);
|
||||
token_size = va_arg(valist, uint32_t*);
|
||||
token = va_arg(valist, uint8_t *);
|
||||
token_size = va_arg(valist, uint32_t *);
|
||||
return psa_initial_attest_get_token(challenge, challenge_size, token, token_size);
|
||||
case PAL_INITIAL_ATTEST_GET_TOKEN_SIZE:
|
||||
challenge_size = va_arg(valist, uint32_t);
|
||||
token_size = va_arg(valist, uint32_t*);
|
||||
token_size = va_arg(valist, uint32_t *);
|
||||
return psa_initial_attest_get_token_size(challenge_size, token_size);
|
||||
case PAL_INITIAL_ATTEST_VERIFY_TOKEN:
|
||||
challenge = va_arg(valist, uint8_t*);
|
||||
challenge = va_arg(valist, uint8_t *);
|
||||
challenge_size = va_arg(valist, uint32_t);
|
||||
token = va_arg(valist, uint8_t*);
|
||||
token = va_arg(valist, uint8_t *);
|
||||
verify_token_size = va_arg(valist, uint32_t);
|
||||
return pal_initial_attest_verify_token(challenge, challenge_size,
|
||||
token, verify_token_size);
|
||||
|
|
|
@ -41,8 +41,7 @@ typedef uint32_t cfg_id_t;
|
|||
|
||||
#define PAL_STATUS_UNSUPPORTED_FUNC 0xFF
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
PAL_STATUS_SUCCESS = 0x0,
|
||||
PAL_STATUS_ERROR = 0x80
|
||||
} pal_status_t;
|
||||
|
|
|
@ -40,19 +40,18 @@ uint32_t pal_its_function(int type, va_list valist)
|
|||
*/
|
||||
size_t actual_size;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case PAL_ITS_SET:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
data_length = va_arg(valist, uint32_t);
|
||||
p_write_data = va_arg(valist, const void*);
|
||||
p_write_data = va_arg(valist, const void *);
|
||||
its_create_flags = va_arg(valist, psa_storage_create_flags_t);
|
||||
return psa_its_set(uid, data_length, p_write_data, its_create_flags);
|
||||
case PAL_ITS_GET:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
offset = va_arg(valist, uint32_t);
|
||||
data_length = va_arg(valist, uint32_t);
|
||||
p_read_data = va_arg(valist, void*);
|
||||
p_read_data = va_arg(valist, void *);
|
||||
/* TODO: Actual size argument is currently not supported by the testing framework.
|
||||
* Changes need to be implemented in the actual tests.
|
||||
* Should be fixed by the next import of the tests.
|
||||
|
@ -60,7 +59,7 @@ uint32_t pal_its_function(int type, va_list valist)
|
|||
return psa_its_get(uid, offset, data_length, p_read_data, &actual_size);
|
||||
case PAL_ITS_GET_INFO:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
its_p_info = va_arg(valist, struct psa_its_info_t*);
|
||||
its_p_info = va_arg(valist, struct psa_its_info_t *);
|
||||
return psa_its_get_info(uid, (struct psa_storage_info_t *)its_p_info);
|
||||
case PAL_ITS_REMOVE:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
|
|
|
@ -108,16 +108,11 @@ void main_wrapper(void)
|
|||
|
||||
void pal_mbed_os_compliance_test_initialize(void)
|
||||
{
|
||||
if (COMPLIANCE_TEST_CRYPTO == type_g)
|
||||
{
|
||||
if (COMPLIANCE_TEST_CRYPTO == type_g) {
|
||||
inject_entropy();
|
||||
}
|
||||
else if (COMPLIANCE_TEST_STORAGE == type_g)
|
||||
{
|
||||
} else if (COMPLIANCE_TEST_STORAGE == type_g) {
|
||||
reset_storage_for_compliance_test();
|
||||
}
|
||||
else if (COMPLIANCE_TEST_ATTESTATION == type_g)
|
||||
{
|
||||
} else if (COMPLIANCE_TEST_ATTESTATION == type_g) {
|
||||
reset_storage_for_compliance_test();
|
||||
inject_entropy();
|
||||
psa_crypto_init();
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum _compliance_test_type{
|
||||
typedef enum _compliance_test_type {
|
||||
COMPLIANCE_TEST_UNDEFINED,
|
||||
COMPLIANCE_TEST_START = COMPLIANCE_TEST_UNDEFINED,
|
||||
COMPLIANCE_TEST_CRYPTO,
|
||||
COMPLIANCE_TEST_ATTESTATION,
|
||||
COMPLIANCE_TEST_STORAGE,
|
||||
COMPLIANCE_TEST_END
|
||||
}compliance_test_type;
|
||||
} compliance_test_type;
|
||||
|
||||
typedef void (*test_entry_f)(val_api_t *val_api, psa_api_t *psa_api);
|
||||
int test_start(test_entry_f test_f, compliance_test_type type);
|
||||
|
|
|
@ -34,23 +34,22 @@ uint32_t pal_ps_function(int type, va_list valist)
|
|||
psa_storage_create_flags_t ps_create_flags;
|
||||
struct psa_ps_info_t *ps_p_info;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case PAL_PS_SET:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
data_length = va_arg(valist, uint32_t);
|
||||
p_write_data = va_arg(valist, const void*);
|
||||
p_write_data = va_arg(valist, const void *);
|
||||
ps_create_flags = va_arg(valist, psa_storage_create_flags_t);
|
||||
return psa_ps_set(uid, data_length, p_write_data, ps_create_flags);
|
||||
case PAL_PS_GET:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
offset = va_arg(valist, uint32_t);
|
||||
data_length = va_arg(valist, uint32_t);
|
||||
p_read_data = va_arg(valist, void*);
|
||||
p_read_data = va_arg(valist, void *);
|
||||
return psa_ps_get(uid, offset, data_length, p_read_data, &actual_length);
|
||||
case PAL_PS_GET_INFO:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
ps_p_info = va_arg(valist, struct psa_ps_info_t*);
|
||||
ps_p_info = va_arg(valist, struct psa_ps_info_t *);
|
||||
return psa_ps_get_info(uid, ps_p_info);
|
||||
case PAL_PS_REMOVE:
|
||||
uid = va_arg(valist, psa_storage_uid_t);
|
||||
|
|
|
@ -28,34 +28,27 @@ static int get_items_in_map(QCBORDecodeContext *decode_context,
|
|||
struct items_to_get_t *item_ptr = item_list;
|
||||
|
||||
/* initialize the data type of all items in the list */
|
||||
while (item_ptr->label != 0)
|
||||
{
|
||||
while (item_ptr->label != 0) {
|
||||
item_ptr->item.uDataType = QCBOR_TYPE_NONE;
|
||||
item_ptr++;
|
||||
}
|
||||
|
||||
QCBORDecode_GetNext(decode_context, &item);
|
||||
if (item.uDataType != QCBOR_TYPE_MAP)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_MAP) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
for (item_index = item.val.uCount; item_index != 0; item_index--)
|
||||
{
|
||||
if (QCBORDecode_GetNext(decode_context, &item) != QCBOR_SUCCESS)
|
||||
{
|
||||
for (item_index = item.val.uCount; item_index != 0; item_index--) {
|
||||
if (QCBORDecode_GetNext(decode_context, &item) != QCBOR_SUCCESS) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
if (item.uLabelType != QCBOR_TYPE_INT64)
|
||||
{
|
||||
if (item.uLabelType != QCBOR_TYPE_INT64) {
|
||||
continue;
|
||||
}
|
||||
|
||||
item_ptr = item_list;
|
||||
while (item_ptr->label != 0)
|
||||
{
|
||||
if (item.label.int64 == item_ptr->label)
|
||||
{
|
||||
while (item_ptr->label != 0) {
|
||||
if (item.label.int64 == item_ptr->label) {
|
||||
item_ptr->item = item;
|
||||
}
|
||||
item_ptr++;
|
||||
|
@ -74,13 +67,11 @@ static int get_item_in_map(QCBORDecodeContext *decode_context,
|
|||
item_list[0].label = label;
|
||||
item_list[1].label = 0;
|
||||
|
||||
if (get_items_in_map(decode_context, item_list))
|
||||
{
|
||||
if (get_items_in_map(decode_context, item_list)) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
if (item_list[0].item.uDataType == QCBOR_TYPE_NONE)
|
||||
{
|
||||
if (item_list[0].item.uDataType == QCBOR_TYPE_NONE) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
|
@ -100,18 +91,15 @@ static int parse_unprotected_headers(QCBORDecodeContext *decode_context,
|
|||
item_list[2].label = 0;
|
||||
*loop_back = false;
|
||||
|
||||
if (get_items_in_map(decode_context, item_list))
|
||||
{
|
||||
if (get_items_in_map(decode_context, item_list)) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
if (item_list[1].item.uDataType == QCBOR_TYPE_TRUE)
|
||||
{
|
||||
if (item_list[1].item.uDataType == QCBOR_TYPE_TRUE) {
|
||||
*loop_back = true;
|
||||
}
|
||||
|
||||
if (item_list[0].item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
{
|
||||
if (item_list[0].item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
|
@ -128,18 +116,15 @@ static int parse_protected_headers(struct useful_buf_c protected_headers,
|
|||
|
||||
QCBORDecode_Init(&decode_context, protected_headers, 0);
|
||||
|
||||
if (get_item_in_map(&decode_context, COSE_HEADER_PARAM_ALG, &item))
|
||||
{
|
||||
if (get_item_in_map(&decode_context, COSE_HEADER_PARAM_ALG, &item)) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
if (QCBORDecode_Finish(&decode_context))
|
||||
{
|
||||
if (QCBORDecode_Finish(&decode_context)) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
if ((item.uDataType != QCBOR_TYPE_INT64) || (item.val.int64 > INT32_MAX))
|
||||
{
|
||||
if ((item.uDataType != QCBOR_TYPE_INT64) || (item.val.int64 > INT32_MAX)) {
|
||||
return PAL_ATTEST_ERROR;
|
||||
}
|
||||
|
||||
|
@ -162,112 +147,100 @@ static int parse_claims(QCBORDecodeContext *decode_context, QCBORItem item,
|
|||
int status = PAL_ATTEST_SUCCESS;
|
||||
|
||||
/* Parse each claim and validate their data type */
|
||||
while (status == PAL_ATTEST_SUCCESS)
|
||||
{
|
||||
while (status == PAL_ATTEST_SUCCESS) {
|
||||
status = QCBORDecode_GetNext(decode_context, &item);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
mandatory_claims |= 1 << (EAT_CBOR_ARM_RANGE_BASE - item.label.int64);
|
||||
if (item.uLabelType == QCBOR_TYPE_INT64)
|
||||
{
|
||||
if (item.label.int64 == EAT_CBOR_ARM_LABEL_NONCE)
|
||||
{
|
||||
if (item.uDataType == QCBOR_TYPE_BYTE_STRING)
|
||||
{
|
||||
if (item.uLabelType == QCBOR_TYPE_INT64) {
|
||||
if (item.label.int64 == EAT_CBOR_ARM_LABEL_NONCE) {
|
||||
if (item.uDataType == QCBOR_TYPE_BYTE_STRING) {
|
||||
/* Given challenge vs challenge in token */
|
||||
if (UsefulBuf_Compare(item.val.string, completed_challenge))
|
||||
if (UsefulBuf_Compare(item.val.string, completed_challenge)) {
|
||||
return PAL_ATTEST_TOKEN_CHALLENGE_MISMATCH;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return PAL_ATTEST_TOKEN_NOT_SUPPORTED;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_ARM_LABEL_BOOT_SEED ||
|
||||
} else if (item.label.int64 == EAT_CBOR_ARM_LABEL_BOOT_SEED ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_IMPLEMENTATION_ID ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_UEID)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_UEID) {
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_ARM_LABEL_ORIGINATION ||
|
||||
} else if (item.label.int64 == EAT_CBOR_ARM_LABEL_ORIGINATION ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_PROFILE_DEFINITION ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_HW_VERSION)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING)
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_HW_VERSION) {
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_ARM_LABEL_CLIENT_ID ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_SECURITY_LIFECYCLE)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_INT64)
|
||||
} else if (item.label.int64 == EAT_CBOR_ARM_LABEL_CLIENT_ID ||
|
||||
item.label.int64 == EAT_CBOR_ARM_LABEL_SECURITY_LIFECYCLE) {
|
||||
if (item.uDataType != QCBOR_TYPE_INT64) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_ARM_LABEL_SW_COMPONENTS)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_ARRAY)
|
||||
} else if (item.label.int64 == EAT_CBOR_ARM_LABEL_SW_COMPONENTS) {
|
||||
if (item.uDataType != QCBOR_TYPE_ARRAY) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
sw_component_present = 1;
|
||||
status = QCBORDecode_GetNext(decode_context, &item);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count = item.val.uCount;
|
||||
for (i = 0; i <= count; i++)
|
||||
{
|
||||
for (i = 0; i <= count; i++) {
|
||||
mandaroty_sw_components |= 1 << item.label.int64;
|
||||
|
||||
if (item.label.int64 == EAT_CBOR_SW_COMPONENT_MEASUREMENT)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
if (item.label.int64 == EAT_CBOR_SW_COMPONENT_MEASUREMENT) {
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_MEASUREMENT_DESC)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING)
|
||||
} else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_MEASUREMENT_DESC) {
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_VERSION)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING)
|
||||
} else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_VERSION) {
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_SIGNER_ID)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
} else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_SIGNER_ID) {
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_EPOCH)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_INT64)
|
||||
} else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_EPOCH) {
|
||||
if (item.uDataType != QCBOR_TYPE_INT64) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_TYPE)
|
||||
{
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING)
|
||||
} else if (item.label.int64 == EAT_CBOR_SW_COMPONENT_TYPE) {
|
||||
if (item.uDataType != QCBOR_TYPE_TEXT_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < count)
|
||||
{
|
||||
if (i < count) {
|
||||
status = QCBORDecode_GetNext(decode_context, &item);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* ToDo: Add other claim types */
|
||||
}
|
||||
}
|
||||
|
||||
if (status == QCBOR_ERR_HIT_END)
|
||||
if (status == QCBOR_ERR_HIT_END) {
|
||||
return PAL_ATTEST_SUCCESS;
|
||||
else
|
||||
} else {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -300,7 +273,7 @@ int32_t pal_initial_attest_verify_token(uint8_t *challenge, uint32_t challenge_s
|
|||
completed_challenge.ptr = challenge;
|
||||
completed_challenge.len = challenge_size;
|
||||
|
||||
/*
|
||||
/*
|
||||
-------------------------
|
||||
| CBOR Array Type |
|
||||
-------------------------
|
||||
|
@ -312,7 +285,7 @@ int32_t pal_initial_attest_verify_token(uint8_t *challenge, uint32_t challenge_s
|
|||
-------------------------
|
||||
| Signature |
|
||||
-------------------------
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Initialize the decorder */
|
||||
QCBORDecode_Init(&decode_context, completed_token, QCBOR_DECODE_MODE_NORMAL);
|
||||
|
@ -324,60 +297,67 @@ int32_t pal_initial_attest_verify_token(uint8_t *challenge, uint32_t challenge_s
|
|||
* Only COSE_SIGN1 is supported now.
|
||||
*/
|
||||
if (item.uDataType != QCBOR_TYPE_ARRAY || item.val.uCount != 4 ||
|
||||
!QCBORDecode_IsTagged(&decode_context, &item, CBOR_TAG_COSE_SIGN1))
|
||||
!QCBORDecode_IsTagged(&decode_context, &item, CBOR_TAG_COSE_SIGN1)) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
/* Get the next headers */
|
||||
QCBORDecode_GetNext(&decode_context, &item);
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
protected_headers = item.val.string;
|
||||
|
||||
/* Parse the protected headers and check the data type and value*/
|
||||
status = parse_protected_headers(protected_headers, &cose_algorithm_id);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Parse the unprotected headers and check the data type and value */
|
||||
short_circuit = false;
|
||||
status = parse_unprotected_headers(&decode_context, &kid, &short_circuit);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Get the payload */
|
||||
QCBORDecode_GetNext(&decode_context, &item);
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
payload = item.val.string;
|
||||
|
||||
/* Get the digital signature */
|
||||
QCBORDecode_GetNext(&decode_context, &item);
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING)
|
||||
if (item.uDataType != QCBOR_TYPE_BYTE_STRING) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
/* Initialize the Decoder and validate the payload format */
|
||||
QCBORDecode_Init(&decode_context, payload, QCBOR_DECODE_MODE_NORMAL);
|
||||
status = QCBORDecode_GetNext(&decode_context, &item);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (item.uDataType != QCBOR_TYPE_MAP)
|
||||
if (item.uDataType != QCBOR_TYPE_MAP) {
|
||||
return PAL_ATTEST_TOKEN_ERR_CBOR_FORMATTING;
|
||||
}
|
||||
|
||||
/* Parse the payload and check the data type of each claim */
|
||||
status = parse_claims(&decode_context, item, completed_challenge);
|
||||
if (status != PAL_ATTEST_SUCCESS)
|
||||
if (status != PAL_ATTEST_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((mandatory_claims & MANDATORY_CLAIM_WITH_SW_COMP) == MANDATORY_CLAIM_WITH_SW_COMP)
|
||||
{
|
||||
if ((mandaroty_sw_components & MANDATORY_SW_COMP) != MANDATORY_SW_COMP)
|
||||
if ((mandatory_claims & MANDATORY_CLAIM_WITH_SW_COMP) == MANDATORY_CLAIM_WITH_SW_COMP) {
|
||||
if ((mandaroty_sw_components & MANDATORY_SW_COMP) != MANDATORY_SW_COMP) {
|
||||
return PAL_ATTEST_TOKEN_NOT_ALL_MANDATORY_CLAIMS;
|
||||
}
|
||||
else if ((mandatory_claims & MANDATORY_CLAIM_NO_SW_COMP) != MANDATORY_CLAIM_NO_SW_COMP)
|
||||
{
|
||||
} else if ((mandatory_claims & MANDATORY_CLAIM_NO_SW_COMP) != MANDATORY_CLAIM_NO_SW_COMP) {
|
||||
return PAL_ATTEST_TOKEN_NOT_ALL_MANDATORY_CLAIMS;
|
||||
}
|
||||
|
||||
|
|
|
@ -253,10 +253,10 @@ typedef struct {
|
|||
} boot_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t pass_cnt:8;
|
||||
uint32_t skip_cnt:8;
|
||||
uint32_t fail_cnt:8;
|
||||
uint32_t sim_error_cnt:8;
|
||||
uint32_t pass_cnt: 8;
|
||||
uint32_t skip_cnt: 8;
|
||||
uint32_t fail_cnt: 8;
|
||||
uint32_t sim_error_cnt: 8;
|
||||
} test_count_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
void pal_mbed_os_compliance_test_initialize(void);
|
||||
void pal_mbed_os_compliance_test_destroy(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -31,12 +33,9 @@ void mbed_val_test_exit(void)
|
|||
uint32_t status = mbed_val_get_status();
|
||||
pal_mbed_os_compliance_test_destroy();
|
||||
/* return if test skipped or failed */
|
||||
if (IS_TEST_FAIL(status) || IS_TEST_SKIP(status))
|
||||
{
|
||||
if (IS_TEST_FAIL(status) || IS_TEST_SKIP(status)) {
|
||||
GREENTEA_TESTSUITE_RESULT(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
GREENTEA_TESTSUITE_RESULT(true);
|
||||
mbed_val_set_status(RESULT_END(VAL_STATUS_SUCCESS));
|
||||
}
|
||||
|
@ -64,25 +63,20 @@ val_status_t mbed_val_execute_non_secure_tests(uint32_t test_num, client_test_t
|
|||
test_info.test_num = test_num;
|
||||
|
||||
mbed_val_print(PRINT_TEST, "[Info] Executing tests from non-secure\n", 0);
|
||||
while (tests_list[i] != NULL)
|
||||
{
|
||||
while (tests_list[i] != NULL) {
|
||||
memset(testcase_name, 0, 100);
|
||||
sprintf(testcase_name, "Check%" PRIu32, i);
|
||||
GREENTEA_TESTCASE_START(testcase_name);
|
||||
if (server_hs == TRUE)
|
||||
{
|
||||
if (server_hs == TRUE) {
|
||||
/* Handshake with server tests */
|
||||
test_info.block_num = i;
|
||||
status = mbed_val_execute_secure_test_func(&handle, test_info,
|
||||
SERVER_TEST_DISPATCHER_SID);
|
||||
if (VAL_ERROR(status))
|
||||
{
|
||||
if (VAL_ERROR(status)) {
|
||||
mbed_val_set_status(RESULT_FAIL(status));
|
||||
mbed_val_print(PRINT_ERROR, "[Check%d] START\n", i);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mbed_val_print(PRINT_DEBUG, "[Check%d] START\n", i);
|
||||
}
|
||||
}
|
||||
|
@ -90,42 +84,36 @@ val_status_t mbed_val_execute_non_secure_tests(uint32_t test_num, client_test_t
|
|||
/* Execute client tests */
|
||||
test_status = tests_list[i](CALLER_NONSECURE);
|
||||
|
||||
if (server_hs == TRUE)
|
||||
{
|
||||
if (server_hs == TRUE) {
|
||||
/* Retrive Server test status */
|
||||
status = mbed_val_get_secure_test_result(&handle);
|
||||
}
|
||||
|
||||
if (test_status != VAL_STATUS_SUCCESS)
|
||||
{
|
||||
if (test_status != VAL_STATUS_SUCCESS) {
|
||||
status = VAL_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if (IS_TEST_SKIP(status))
|
||||
{
|
||||
if (IS_TEST_SKIP(status)) {
|
||||
mbed_val_set_status(status);
|
||||
mbed_val_print(PRINT_DEBUG, "[Check%d] SKIPPED\n", i);
|
||||
GREENTEA_TESTCASE_FINISH(testcase_name, 1, 0);
|
||||
continue_test = false;
|
||||
}
|
||||
else if (VAL_ERROR(status))
|
||||
{
|
||||
} else if (VAL_ERROR(status)) {
|
||||
mbed_val_set_status(RESULT_FAIL(status));
|
||||
if (server_hs == TRUE)
|
||||
if (server_hs == TRUE) {
|
||||
mbed_val_print(PRINT_ERROR, "[Check%d] FAILED\n", i);
|
||||
}
|
||||
GREENTEA_TESTCASE_FINISH(testcase_name, 0, 1);
|
||||
continue_test = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (server_hs == TRUE)
|
||||
} else {
|
||||
if (server_hs == TRUE) {
|
||||
mbed_val_print(PRINT_DEBUG, "[Check%d] PASSED\n", i);
|
||||
}
|
||||
GREENTEA_TESTCASE_FINISH(testcase_name, 1, 0);
|
||||
continue_test = true;
|
||||
}
|
||||
|
||||
if (!continue_test)
|
||||
{
|
||||
if (!continue_test) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -172,8 +160,7 @@ val_status_t mbed_val_execute_secure_test_func(psa_handle_t *handle, test_info_t
|
|||
psa_status_t status_of_call = PSA_SUCCESS;
|
||||
|
||||
*handle = pal_ipc_connect(sid, 0);
|
||||
if (*handle < 0)
|
||||
{
|
||||
if (*handle < 0) {
|
||||
mbed_val_print(PRINT_ERROR, "Could not connect SID. Handle=%x\n", *handle);
|
||||
return VAL_STATUS_CONNECTION_FAILED;
|
||||
}
|
||||
|
@ -182,8 +169,7 @@ val_status_t mbed_val_execute_secure_test_func(psa_handle_t *handle, test_info_t
|
|||
psa_invec data[1] = {{&test_data, sizeof(test_data)}};
|
||||
|
||||
status_of_call = pal_ipc_call(*handle, data, 1, NULL, 0);
|
||||
if (status_of_call != PSA_SUCCESS)
|
||||
{
|
||||
if (status_of_call != PSA_SUCCESS) {
|
||||
status = VAL_STATUS_CALL_FAILED;
|
||||
mbed_val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call);
|
||||
pal_ipc_close(*handle);
|
||||
|
@ -229,8 +215,7 @@ val_status_t mbed_val_get_secure_test_result(psa_handle_t *handle)
|
|||
psa_invec data[1] = {{&test_data, sizeof(test_data)}};
|
||||
|
||||
status_of_call = pal_ipc_call(*handle, data, 1, &resp, 1);
|
||||
if (status_of_call != PSA_SUCCESS)
|
||||
{
|
||||
if (status_of_call != PSA_SUCCESS) {
|
||||
status = VAL_STATUS_CALL_FAILED;
|
||||
mbed_val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call);
|
||||
}
|
||||
|
@ -246,12 +231,11 @@ val_status_t mbed_val_get_secure_test_result(psa_handle_t *handle)
|
|||
@param -handle - return connection handle
|
||||
* @return val_status_t
|
||||
*/
|
||||
val_status_t mbed_val_ipc_connect(uint32_t sid, uint32_t minor_version, psa_handle_t *handle )
|
||||
val_status_t mbed_val_ipc_connect(uint32_t sid, uint32_t minor_version, psa_handle_t *handle)
|
||||
{
|
||||
*handle = pal_ipc_connect(sid, minor_version);
|
||||
|
||||
if (*handle < 0)
|
||||
{
|
||||
if (*handle < 0) {
|
||||
return VAL_STATUS_CONNECTION_FAILED;
|
||||
}
|
||||
|
||||
|
@ -276,8 +260,7 @@ val_status_t mbed_val_ipc_call(psa_handle_t handle, psa_invec *in_vec, size_t in
|
|||
|
||||
call_status = pal_ipc_call(handle, in_vec, in_len, out_vec, out_len);
|
||||
|
||||
if (call_status != PSA_SUCCESS)
|
||||
{
|
||||
if (call_status != PSA_SUCCESS) {
|
||||
return VAL_STATUS_CALL_FAILED;
|
||||
}
|
||||
|
||||
|
@ -309,7 +292,7 @@ val_status_t mbed_val_wd_reprogram_timer(wd_timeout_type_t timeout_type)
|
|||
return VAL_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,52 +24,52 @@
|
|||
|
||||
/* typedef's */
|
||||
typedef struct {
|
||||
val_status_t (*print) (print_verbosity_t verbosity,
|
||||
val_status_t (*print)(print_verbosity_t verbosity,
|
||||
const char *string, uint32_t data);
|
||||
val_status_t (*set_status) (uint32_t status);
|
||||
uint32_t (*get_status) (void);
|
||||
void (*test_init) (uint32_t test_num, char8_t *desc,
|
||||
val_status_t (*set_status)(uint32_t status);
|
||||
uint32_t (*get_status)(void);
|
||||
void (*test_init)(uint32_t test_num, char8_t *desc,
|
||||
uint32_t test_bitfield);
|
||||
void (*test_exit) (void);
|
||||
val_status_t (*err_check_set) (uint32_t checkpoint, val_status_t status);
|
||||
val_status_t (*target_get_config) (cfg_id_t cfg_id, uint8_t **data, uint32_t *size);
|
||||
val_status_t (*execute_non_secure_tests) (uint32_t test_num, client_test_t *tests_list,
|
||||
void (*test_exit)(void);
|
||||
val_status_t (*err_check_set)(uint32_t checkpoint, val_status_t status);
|
||||
val_status_t (*target_get_config)(cfg_id_t cfg_id, uint8_t **data, uint32_t *size);
|
||||
val_status_t (*execute_non_secure_tests)(uint32_t test_num, client_test_t *tests_list,
|
||||
bool_t server_hs);
|
||||
val_status_t (*switch_to_secure_client) (uint32_t test_num);
|
||||
val_status_t (*execute_secure_test_func) (psa_handle_t *handle, test_info_t test_info,
|
||||
val_status_t (*switch_to_secure_client)(uint32_t test_num);
|
||||
val_status_t (*execute_secure_test_func)(psa_handle_t *handle, test_info_t test_info,
|
||||
uint32_t sid);
|
||||
val_status_t (*ipc_connect) (uint32_t sid, uint32_t minor_version,
|
||||
psa_handle_t *handle );
|
||||
val_status_t (*ipc_call) (psa_handle_t handle, psa_invec *in_vec,
|
||||
val_status_t (*ipc_connect)(uint32_t sid, uint32_t minor_version,
|
||||
psa_handle_t *handle);
|
||||
val_status_t (*ipc_call)(psa_handle_t handle, psa_invec *in_vec,
|
||||
size_t in_len, psa_outvec *out_vec,
|
||||
size_t out_len);
|
||||
void (*ipc_close) (psa_handle_t handle);
|
||||
val_status_t (*get_secure_test_result) (psa_handle_t *handle);
|
||||
val_status_t (*nvmem_read) (uint32_t offset, void *buffer, int size);
|
||||
val_status_t (*nvmem_write) (uint32_t offset, void *buffer, int size);
|
||||
val_status_t (*wd_timer_init) (wd_timeout_type_t timeout_type);
|
||||
val_status_t (*wd_timer_enable) (void);
|
||||
val_status_t (*wd_timer_disable) (void);
|
||||
val_status_t (*wd_reprogram_timer) (wd_timeout_type_t timeout_type);
|
||||
val_status_t (*set_boot_flag) (boot_state_t state);
|
||||
val_status_t (*get_boot_flag) (boot_state_t *state);
|
||||
int32_t (*crypto_function) (int type, ...);
|
||||
uint32_t (*its_function) (int type, ...);
|
||||
uint32_t (*ps_function) (int type, ...);
|
||||
int32_t (*attestation_function) (int type, ...);
|
||||
void (*ipc_close)(psa_handle_t handle);
|
||||
val_status_t (*get_secure_test_result)(psa_handle_t *handle);
|
||||
val_status_t (*nvmem_read)(uint32_t offset, void *buffer, int size);
|
||||
val_status_t (*nvmem_write)(uint32_t offset, void *buffer, int size);
|
||||
val_status_t (*wd_timer_init)(wd_timeout_type_t timeout_type);
|
||||
val_status_t (*wd_timer_enable)(void);
|
||||
val_status_t (*wd_timer_disable)(void);
|
||||
val_status_t (*wd_reprogram_timer)(wd_timeout_type_t timeout_type);
|
||||
val_status_t (*set_boot_flag)(boot_state_t state);
|
||||
val_status_t (*get_boot_flag)(boot_state_t *state);
|
||||
int32_t (*crypto_function)(int type, ...);
|
||||
uint32_t (*its_function)(int type, ...);
|
||||
uint32_t (*ps_function)(int type, ...);
|
||||
int32_t (*attestation_function)(int type, ...);
|
||||
} val_api_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t (*framework_version) (void);
|
||||
uint32_t (*version) (uint32_t sid);
|
||||
psa_handle_t (*connect) (uint32_t sid, uint32_t minor_version);
|
||||
psa_status_t (*call) (psa_handle_t handle,
|
||||
uint32_t (*framework_version)(void);
|
||||
uint32_t (*version)(uint32_t sid);
|
||||
psa_handle_t (*connect)(uint32_t sid, uint32_t minor_version);
|
||||
psa_status_t (*call)(psa_handle_t handle,
|
||||
const psa_invec *in_vec,
|
||||
size_t in_len,
|
||||
psa_outvec *out_vec,
|
||||
size_t out_len
|
||||
);
|
||||
void (*close) (psa_handle_t handle);
|
||||
void (*close)(psa_handle_t handle);
|
||||
} psa_api_t;
|
||||
|
||||
typedef void (*test_fptr_t)(val_api_t *val, psa_api_t *psa);
|
||||
|
|
|
@ -76,7 +76,7 @@ typedef enum _MISCELLANEOUS_CONFIG_ID_ {
|
|||
/**
|
||||
Assign group type to each system component
|
||||
**/
|
||||
typedef enum _COMPONENT_GROUPING_{
|
||||
typedef enum _COMPONENT_GROUPING_ {
|
||||
UART = GROUP_SOC_PERIPHERAL,
|
||||
TIMER = GROUP_SOC_PERIPHERAL,
|
||||
WATCHDOG = GROUP_SOC_PERIPHERAL,
|
||||
|
@ -100,7 +100,7 @@ typedef struct _TARGET_CFG_HDR_ {
|
|||
uint32_t version;
|
||||
/* Header Size */
|
||||
uint32_t size;
|
||||
}target_cfg_hdr_t;
|
||||
} target_cfg_hdr_t;
|
||||
|
||||
typedef enum {
|
||||
LEVEL1 = 0x1,
|
||||
|
|
Loading…
Reference in New Issue