Exemple #1
0
TEE_Result ta_storage_cmd_next_enum(uint32_t param_types, TEE_Param params[4])
{
	TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a);

	ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
			  (TEE_PARAM_TYPE_VALUE_INPUT,
			   TEE_PARAM_TYPE_MEMREF_OUTPUT,
			   TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE));

	if (params[1].memref.size < sizeof(TEE_ObjectInfo))
		return TEE_ERROR_SHORT_BUFFER;

	if (params[2].memref.size < TEE_OBJECT_ID_MAX_LEN)
		return TEE_ERROR_SHORT_BUFFER;

	params[1].memref.size = sizeof(TEE_ObjectInfo);

	return TEE_GetNextPersistentObject(oe,
			(TEE_ObjectInfo *)params[1].memref.buffer,
			params[2].memref.buffer, &params[2].memref.size);
}
Exemple #2
0
static void rename_per_obj_and_enum_and_open_renameObj()
{
	printf("  ####   rename_per_obj_and_enum_and_open_renameObj   ####\n");

	TEE_Result ret;
	TEE_ObjectHandle object = NULL;
	TEE_ObjectHandle object2 = NULL;
	uint32_t flags = 0xffffffff ^ TEE_DATA_FLAG_EXCLUSIVE;
	TEE_ObjectEnumHandle iter_enum = NULL;
	TEE_ObjectInfo info;
	void *new_ID = NULL;
	size_t new_ID_len = 15;
	void *ret_ID = NULL;
	size_t ret_ID_len = TEE_OBJECT_ID_MAX_LEN;

	new_ID = malloc(new_ID_len);
	ret_ID = malloc(ret_ID_len);
	if (ret_ID == NULL || new_ID == NULL) {
		printf("Fail: malloc ID\n");
		goto err;
	}
	RAND_bytes(new_ID, new_ID_len);

	gen_rand_per_data_obj(&object, 20);
	if (object == NULL) {
		printf("Fail: gen rand obj\n");
		goto err;
	}

	ret = TEE_AllocatePersistentObjectEnumerator(&iter_enum);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter alloc\n");
		goto err;
	}

	ret = TEE_StartPersistentObjectEnumerator(iter_enum, TEE_STORAGE_PRIVATE);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter start\n");
		goto err;
	}

	for(;;) {
		ret = TEE_GetNextPersistentObject(iter_enum, &info, ret_ID, &ret_ID_len);
		if (ret == TEE_SUCCESS) {
			/* continue */
		} else if (ret == TEE_ERROR_ITEM_NOT_FOUND) {
			break;
		} else {
			printf("Fail: get next\n");
			goto err;
		}
	}

	ret = TEE_RenamePersistentObject(object, new_ID, new_ID_len);
	if (ret != TEE_SUCCESS) {
		printf("Fail: renam\n");
		goto err;
	}

	TEE_ResetPersistentObjectEnumerator(iter_enum);

	for(;;) {
		ret = TEE_GetNextPersistentObject(iter_enum, &info, ret_ID, &ret_ID_len);
		if (ret == TEE_SUCCESS) {
			/* continue */
		} else if (ret == TEE_ERROR_ITEM_NOT_FOUND) {
			break;
		} else {
			printf("Fail: get next\n");
			goto err;
		}
	}

	ret = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE, (void *)ret_ID,
				       ret_ID_len, flags, &object2);
	if (ret != TEE_SUCCESS) {
		printf("Fail: per open\n");
		goto err;
	}

err:
	TEE_CloseAndDeletePersistentObject(object);
	TEE_CloseObject(object2);
	TEE_FreePersistentObjectEnumerator(iter_enum);
	free(ret_ID);
	free(new_ID);
}
Exemple #3
0
static void gen_per_objs_and_iter_with_enum()
{
	printf("  ####   gen_per_objs_and_iter_with_enum   ####\n");

	TEE_Result ret;
	TEE_ObjectHandle obj1 = NULL;
	TEE_ObjectHandle obj2 = NULL;
	TEE_ObjectHandle obj3 = NULL;
	TEE_ObjectHandle obj_rsa = NULL;
	TEE_ObjectEnumHandle iter_enum1 = NULL;
	TEE_ObjectEnumHandle iter_enum2 = NULL;
	TEE_ObjectInfo info;
	void *ID = NULL;
	size_t ID_len = TEE_OBJECT_ID_MAX_LEN;

	ID = malloc(ID_len);
	if (ID == NULL) {
		printf("Fail: gen_rand_data_obj(ID mem)\n");
		goto err;
	}

	gen_rand_per_data_obj(&obj1, 10);
	gen_rand_per_data_obj(&obj2, 20);
	gen_rand_per_data_obj(&obj3, 30);
	gen_RSA_per_obj_with_data(&obj_rsa, 50);

	if (obj1 == NULL || obj2 == NULL || obj3 == NULL || obj_rsa == NULL) {
		printf("Fail: create err\n");
		goto err;
	}

	ret = TEE_AllocatePersistentObjectEnumerator(&iter_enum1);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter alloc\n");
		goto err;
	}

	ret = TEE_AllocatePersistentObjectEnumerator(&iter_enum2);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter alloc\n");
		goto err;
	}

	ret = TEE_StartPersistentObjectEnumerator(iter_enum1, TEE_STORAGE_PRIVATE);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter start\n");
		goto err;
	}

	ret = TEE_StartPersistentObjectEnumerator(iter_enum2, TEE_STORAGE_PRIVATE);
	if (ret != TEE_SUCCESS) {
		printf("Fail: iter start\n");
		goto err;
	}

	ret = TEE_GetNextPersistentObject(iter_enum1, &info, ID, &ID_len);
	if (ret == TEE_ERROR_GENERIC) {
		printf("Fail: iter1 next\n");
		goto err;
	}

	for(;;) {
		ret = TEE_GetNextPersistentObject(iter_enum2, &info, ID, &ID_len);
		if (ret == TEE_SUCCESS) {
			/* nothing */
		} else if (ret == TEE_ERROR_ITEM_NOT_FOUND) {
			break;
		} else {
			printf("Fail: get next\n");
			goto err;
		}
	}

	TEE_FreePersistentObjectEnumerator(iter_enum2);
	iter_enum2 = NULL;

	TEE_ResetPersistentObjectEnumerator(iter_enum1);

	for(;;) {
		ret = TEE_GetNextPersistentObject(iter_enum1, &info, ID, &ID_len);
		if (ret == TEE_SUCCESS) {
			/* nothing */
		} else if (ret == TEE_ERROR_ITEM_NOT_FOUND) {
			break;
		} else {
			printf("Fail: get next\n");
			goto err;
		}
	}

err:
	TEE_CloseAndDeletePersistentObject(obj1);
	TEE_CloseAndDeletePersistentObject(obj2);
	TEE_CloseAndDeletePersistentObject(obj3);
	TEE_CloseAndDeletePersistentObject(obj_rsa);
	TEE_FreePersistentObjectEnumerator(iter_enum1);
	TEE_FreePersistentObjectEnumerator(iter_enum2);
	free(ID);
}