Example #1
0
TEE_Result TA_EXPORT TA_CreateEntryPoint(void)
{
	TEE_Result ret;
	uint64_t initial_value = 0;
	TEE_ObjectHandle counter;

	OT_LOG(LOG_ERR, "Calling the create entry point");

	ret = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE, &object_id, sizeof(object_id),
				       TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE,
				       &counter);
	if (ret == TEE_ERROR_ITEM_NOT_FOUND) {
		OT_LOG(LOG_DEBUG, "TEE_OpenPersistentObject failed, creating persistent object");

		ret = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE, &object_id, sizeof(object_id),
						 TEE_DATA_FLAG_ACCESS_READ |
						 TEE_DATA_FLAG_ACCESS_WRITE,
						 NULL, &initial_value, sizeof(initial_value),
						 &counter);
		if (ret != TEE_SUCCESS)
			OT_LOG(LOG_ERR, "TEE_CreatePersistentObject failed: 0x%x", ret);
		else
			OT_LOG(LOG_DEBUG, "TEE_CreatePersistentObject succesful");
	}

	TEE_CloseObject(counter);
	return ret;
}
Example #2
0
static void gen_rsa_key_pair_and_save_read()
{
	printf("  ####   gen_rsa_key_pair_and_save_read   ####\n");

	TEE_Result ret;
	TEE_ObjectHandle handler;
	TEE_ObjectHandle handler2;
	size_t key_size = 512;
	char objID[] = "56c5d1b260704de30fe7af67e5b9327613abebe6172a2b4e949d84b8e561e2fb";
	size_t objID_len = 64;
	uint32_t flags = 0xffffffff ^ TEE_DATA_FLAG_EXCLUSIVE;
	void * data;
	size_t data_len = 12;

	data = malloc(data_len);
	if (data == NULL)
		goto err;
	RAND_bytes(data, data_len);

	ret = TEE_AllocateTransientObject(TEE_TYPE_RSA_KEYPAIR, key_size, &handler);

	if (ret == TEE_ERROR_OUT_OF_MEMORY) {
		printf("Fail: no mem\n");
		goto err;
	}

	if (ret == TEE_ERROR_NOT_SUPPORTED) {
		printf("Fail: no sup\n");
		goto err;
	}

	ret = TEE_GenerateKey(handler, key_size, NULL, 0);

	if (ret != TEE_SUCCESS) {
		printf("Fail: bad para\n");
		goto err;
	}

	ret = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE, (void *)objID,
					 objID_len, flags, handler, data, data_len, NULL);

	if (ret != TEE_SUCCESS) {
		printf("Fail: per creation\n");
		goto err;
	}

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

err:
	TEE_FreeTransientObject(handler);
	TEE_CloseAndDeletePersistentObject(handler2);

	free(data);
}
Example #3
0
static TEE_Result open_rb_state(uint32_t default_lock_state,
				TEE_ObjectHandle *h)
{
	uint32_t flags = TEE_DATA_FLAG_ACCESS_READ |
			 TEE_DATA_FLAG_ACCESS_WRITE;
	TEE_Result res;

	res = TEE_OpenPersistentObject(storageid, rb_obj_name,
				       sizeof(rb_obj_name), flags, h);
	if (!res)
		return TEE_SUCCESS;

	return create_rb_state(default_lock_state, h);
}
Example #4
0
static TEE_Result read_persist_value(uint32_t pt,
				      TEE_Param params[TEE_NUM_PARAMS])
{
	const uint32_t exp_pt = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
						TEE_PARAM_TYPE_MEMREF_INOUT,
						TEE_PARAM_TYPE_NONE,
						TEE_PARAM_TYPE_NONE);
	uint32_t flags = TEE_DATA_FLAG_ACCESS_READ |
			 TEE_DATA_FLAG_ACCESS_WRITE;
	TEE_Result res;
	TEE_ObjectHandle h;

	char name_full[TEE_OBJECT_ID_MAX_LEN];
	uint32_t name_full_sz;
	uint32_t count;

	if (pt != exp_pt)
		return TEE_ERROR_BAD_PARAMETERS;

	char *name_buf = params[0].memref.buffer;
	uint32_t name_buf_sz = params[0].memref.size;

	char *value = params[1].memref.buffer;
	uint32_t value_sz = params[1].memref.size;

	res = get_named_object_name(name_buf, name_buf_sz,
				    name_full, &name_full_sz);
	if (res)
		return res;

	res = TEE_OpenPersistentObject(storageid, name_full,
				       name_full_sz, flags, &h);
	if (res) {
		EMSG("Can't open named object value, res = 0x%x", res);
		return res;
	}

	res =  TEE_ReadObjectData(h, value, value_sz, &count);
	if (res) {
		EMSG("Can't read named object value, res = 0x%x", res);
		goto out;
	}

	params[1].memref.size = count;
out:
	TEE_CloseObject(h);

	return res;
}
Example #5
0
static TEE_Result get_counter_value(uint64_t *mem_data)
{
	TEE_ObjectHandle counter;
	TEE_Result ret;
	uint64_t previous_value = 0, next_value = 0;
	uint32_t bytes_read;

	/* Open the object here if it exists */
	ret = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE, &object_id, sizeof(object_id),
				       TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE,
				       &counter);
	if (ret != TEE_SUCCESS) {
		OT_LOG(LOG_ERR, "TEE_OpenPersistentObject failed: 0x%x", ret);
	} else {
		OT_LOG(LOG_ERR, "TEE_OpenPersistentObject succesful");

		ret = TEE_ReadObjectData(counter, (void *)&previous_value, sizeof(uint64_t),
					 &bytes_read);
		if (ret != TEE_SUCCESS) {
			OT_LOG(LOG_ERR, "TEE_ReadObjectData failed: 0x%x", ret);
			goto end_ctr;
		}

		*mem_data = previous_value;

		/* Increment the value */
		next_value = ++previous_value;

		OT_LOG(LOG_ERR, "New counter value: %d", (int)next_value);

		/* Set data position back to the start of object */
		ret = TEE_SeekObjectData(counter, 0, TEE_DATA_SEEK_SET);
		if (ret != TEE_SUCCESS) {
			OT_LOG(LOG_ERR, "TEE_SeekObjectData failed: 0x%x", ret);
			goto end_ctr;
		}

		/* Write the new counter value back to the persistent object */
		ret = TEE_WriteObjectData(counter, (void *)&next_value, sizeof(uint64_t));
		if (ret != TEE_SUCCESS)
			OT_LOG(LOG_ERR, "TEE_WriteObjectData failed: 0x%x\n", ret);
	}

end_ctr:
	TEE_CloseObject(counter);
	return ret;
}
Example #6
0
TEE_Result ta_storage_cmd_open(uint32_t param_types, TEE_Param params[4])
{
	TEE_Result res;
	TEE_ObjectHandle o;

	ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
			  (TEE_PARAM_TYPE_MEMREF_INPUT,
			   TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE,
			   TEE_PARAM_TYPE_NONE));

	res = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE,
					params[0].memref.buffer,
					params[0].memref.size,
					params[1].value.a, &o);

	params[1].value.b = (uintptr_t)o;
	return res;
}
Example #7
0
static TEE_Result ta_stroage_benchmark_chunk_access_test(uint32_t nCommandID,
		uint32_t param_types, TEE_Param params[4])
{
	TEE_Result res;
	size_t data_size;
	size_t chunk_size;
	TEE_ObjectHandle object = TEE_HANDLE_NULL;
	uint8_t *chunk_buf;
	uint32_t *spent_time_in_ms = &params[2].value.a;
	bool do_verify;

	ASSERT_PARAM_TYPE(param_types, TEE_PARAM_TYPES(
					TEE_PARAM_TYPE_VALUE_INPUT,
					TEE_PARAM_TYPE_VALUE_INPUT,
					TEE_PARAM_TYPE_VALUE_OUTPUT,
					TEE_PARAM_TYPE_NONE));

	data_size = params[0].value.a;
	chunk_size = params[0].value.b;
	do_verify = params[1].value.a;

	if (data_size == 0)
		data_size = DEFAULT_DATA_SIZE;

	if (chunk_size == 0)
		chunk_size = DEFAULT_CHUNK_SIZE;

	IMSG("command id: %u, test data size: %zd, chunk size: %zd\n",
			nCommandID, data_size, chunk_size);

	chunk_buf = TEE_Malloc(chunk_size, TEE_MALLOC_FILL_ZERO);
	if (!chunk_buf) {
		EMSG("Failed to allocate memory");
		res = TEE_ERROR_OUT_OF_MEMORY;
		goto exit;
	}

	fill_buffer(chunk_buf, chunk_size);
	res = prepare_test_file(data_size, chunk_buf, chunk_size);
	if (res != TEE_SUCCESS) {
		EMSG("Failed to create test file, res=0x%08x",
				res);
		goto exit_free_chunk_buf;
	}

	res = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE,
			filename, sizeof(filename),
			TEE_DATA_FLAG_ACCESS_READ |
			TEE_DATA_FLAG_ACCESS_WRITE |
			TEE_DATA_FLAG_ACCESS_WRITE_META |
			TEE_DATA_FLAG_OVERWRITE,
			&object);
	if (res != TEE_SUCCESS) {
		EMSG("Failed to open persistent object, res=0x%08x",
				res);
		goto exit_remove_object;
	}

	switch (nCommandID) {
	case TA_STORAGE_BENCHMARK_CMD_TEST_READ:
		res = test_read(object, data_size, chunk_buf,
				chunk_size, spent_time_in_ms);
		break;

	case TA_STORAGE_BENCHMARK_CMD_TEST_WRITE:
		res = test_write(object, data_size, chunk_buf,
				chunk_size, spent_time_in_ms);
		break;

	case TA_STORAGE_BENCHMARK_CMD_TEST_REWRITE:
		res = test_rewrite(object, data_size, chunk_buf,
				chunk_size, spent_time_in_ms);
		break;

	default:
		res = TEE_ERROR_BAD_PARAMETERS;
	}

	if (res != TEE_SUCCESS)
		goto exit_remove_object;

	if (do_verify)
		res = verify_file_data(object, data_size,
				chunk_buf, chunk_size);


exit_remove_object:
	TEE_CloseAndDeletePersistentObject1(object);
exit_free_chunk_buf:
	TEE_Free(chunk_buf);
exit:

	return res;
}
/**
 * @brief 
 */
void test_storage_api()
{
    uint32_t storageID=TEE_OBJECT_STORAGE_PRIVATE,
             r_flags=TEE_DATA_FLAG_ACCESS_READ,
             w_flags=TEE_DATA_FLAG_ACCESS_WRITE,
             rw_flags=(TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE),
             a_attribute_val=0x00000005,b_attribute_val=0x00000007,
			 pop_ret_val,attribute_cnt=0x00000003,seek_ret_val,open_seek_retval,
			 crt_ret_val,write_ret_val,open_write_retval,read_ret_val,
			 open_read_retval,open_ret_val,open_delete_retval,allocate1_ret_val,
			 allocate2_ret_val,rd_trunc_cnt=0x00000000,open_truncate_retval,
			 trunc_size=0x0000000A,truncate_ret_val,rdtest_truncated_retval,
			 optest_truncated_retval,rdtest_written_retval,
			 optest_written_retval,rd_write_cnt=0x00000000,read_cnt=0x00000000,
			 trunc_cnt=0x00000000,open_rename_retval,de_a,
			 rd_rename_cnt=0x00000000,optest_renamed_retval,rename_ret_val,
			 rdtest_renamed_retval,optest_deleted_retval;

    typedef signed int int32_t;
    int32_t offset=0x00000003;
    size_t objectIDLen=0x00000040,read_size=0x0000000F,rd_trunc_size=0x0000000A,
	   	   rd_write_size=0x0000002C,rd_rename_size=0x0000000C;
    void* open_objectID="/test.dir/test.txt";
	void* rename_objectID="/test.dir/new.txt";
    void* initialData="This a sierraware created sample initial data\n";
    void* create_objectID="/test.dir/crt.txt";
    void* read_objectID="/test.dir/read.txt";
    void* write_objectID="/test.dir/write.txt";
    void* seek_objectID="/test.dir/seek.txt";
    void* delete_objectID="/test.dir/delete.txt";
	void* trunc_objectID="/test.dir/truncate.txt";
    char  wrie_buffer[255]={"This a sierraware created sample test string\n"};
    char  read_buffer[255],rd_trunc_buffer[255],rd_write_buffer[255],
		  rd_rename_buffer[255];
    void* attrsbuffer="This will get populated sometimes in the test fn\n";
    void* p_buffer="And finally we tested GP_INTERNAL_STORAGE APP\n";

    TEE_ObjectHandle crtattributes;
    TEE_ObjectHandle *first_object;
    TEE_ObjectHandle *second_object;

    TEE_Whence whence;
    whence=0x00000000;
	
	sw_printf("-----------Allocating Memory For Create Object--------------\n");
    first_object=(TEE_ObjectHandle*)TEE_Malloc(sizeof(TEE_ObjectHandle),0);
    sw_printf("-------Allocating Memory For Create Object members----------\n");
    allocate1_ret_val=TEE_AllocateTransientObject(TEE_TYPE_AES,0x00000800,
													 first_object);
    sw_printf("the allocate transient function returns value is %x \n", 
			   allocate1_ret_val);

    crt_ret_val=TEE_CreatePersistentObject(storageID,create_objectID,
			objectIDLen,w_flags,crtattributes,initialData,
			(size_t)(sw_strlen((char*)initialData)),first_object);

    sw_printf("The create Persistent object funtion \
returns value is  %x \n \n",crt_ret_val);

    sw_printf("------------Allocating Memory For open Object---------------\n");
    second_object=(TEE_ObjectHandle*)TEE_Malloc(sizeof(TEE_ObjectHandle),0);
	sw_printf("------------Allocating Memory For open Object members-------\n");
    allocate2_ret_val=TEE_AllocateTransientObject(TEE_TYPE_RSA_KEYPAIR,
													 0x00000800,second_object);
    sw_printf("the allocate transient function returns value is %x \n",
			   allocate2_ret_val);

    open_ret_val=TEE_OpenPersistentObject(storageID,open_objectID,objectIDLen,
                                            r_flags,second_object);
    sw_printf("The open Persistent object funtion returns value is %x \n \n",
			   open_ret_val);

    sw_printf("*****Reset the open object***** \n");
    TEE_ResetTransientObject(*second_object);

	open_read_retval=TEE_OpenPersistentObject(storageID,read_objectID,
									objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",open_read_retval);

    read_ret_val=TEE_ReadObjectData(*second_object,(void*)&read_buffer,
							read_size,&read_cnt);

    sw_printf("The Read Persistent funtion returns value is %x \n \n",
			   read_ret_val);

    sw_printf("*****Reset the read object***** \n");
    TEE_ResetTransientObject(*second_object);
	
	open_write_retval=TEE_OpenPersistentObject(storageID,write_objectID,
									  objectIDLen,w_flags,second_object);
    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",open_write_retval);

    write_ret_val=TEE_WriteObjectData(*second_object,(void*)&wrie_buffer,
                         (size_t)(sw_strlen((char*)&wrie_buffer)));
    sw_printf("The write Persistent funtion returns value is %x \n \n",
			   write_ret_val);

    sw_printf("*****Reset the write object***** \n");
    TEE_ResetTransientObject(*second_object);

	optest_written_retval=TEE_OpenPersistentObject(storageID,write_objectID,
										objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",optest_written_retval);

    rdtest_written_retval=TEE_ReadObjectData(*second_object,
						  (void*)&rd_write_buffer,rd_write_size,
						  &rd_write_cnt);

    sw_printf("The Read Persistent funtion returns value is %x \n \n",
			   rdtest_written_retval);

	sw_printf("******TESTING:write persistent object*******\n");
    if(rdtest_written_retval==1) {
        sw_printf("SUCCESS \n");
    }
    else {
        sw_printf("FAILURE \n");
    }

    sw_printf("*****Reset the read object***** \n");
    TEE_ResetTransientObject(*second_object);

	open_truncate_retval=TEE_OpenPersistentObject(storageID,trunc_objectID,
							objectIDLen,w_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",open_truncate_retval);

	truncate_ret_val=TEE_TruncateObjectData(*second_object,trunc_size);
	sw_printf("The truncate Persistent funtion returns value is %x \n \n",
			   truncate_ret_val);

	sw_printf("*****Reset the truncate object***** \n");
    TEE_ResetTransientObject(*second_object);
	
	optest_truncated_retval=TEE_OpenPersistentObject(storageID,trunc_objectID,
								objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",optest_truncated_retval);

    rdtest_truncated_retval=TEE_ReadObjectData(*second_object,
							(void*)&rd_trunc_buffer,rd_trunc_size,
							&rd_trunc_cnt);

    sw_printf("The Read Persistent funtion returns value is %x \n \n",
			   rdtest_truncated_retval);

	sw_printf("******TESTING:truncate persistent object*******\n");
    if(rdtest_truncated_retval==1) {
        sw_printf("SUCCESS \n");
    }
    else {
        sw_printf("FAILS \n");
    }

    sw_printf("*****Reset the read object***** \n");
    TEE_ResetTransientObject(*second_object);

	open_rename_retval=TEE_OpenPersistentObject(storageID,open_objectID,
										objectIDLen,rw_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",open_rename_retval);

	rename_ret_val=TEE_RenamePersistentObject(*second_object,rename_objectID,
												objectIDLen);
    sw_printf("The rename Persistent funtion returns value is %x \n \n",
			   rename_ret_val);

    sw_printf("*****Reset the rename object***** \n");
    TEE_ResetTransientObject(*second_object);

	optest_renamed_retval=TEE_OpenPersistentObject(storageID,rename_objectID,
								objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",optest_renamed_retval);

    rdtest_renamed_retval=TEE_ReadObjectData(*second_object,
						   (void*)&rd_rename_buffer,rd_rename_size,
						   &rd_rename_cnt);

    sw_printf("The Read Persistent funtion returns value is %x \n \n",
			   rdtest_renamed_retval);

	sw_printf("******TESTING:rename persistent object*******\n");
    if(rdtest_renamed_retval==1) {
        sw_printf("SUCCESS \n");
    }
    else {
        sw_printf("FAILS \n");
    }

    sw_printf("*****Reset the read object***** \n");
    TEE_ResetTransientObject(*second_object);

    open_seek_retval=TEE_OpenPersistentObject(storageID,seek_objectID,
								   objectIDLen,rw_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",open_seek_retval);

    seek_ret_val=TEE_SeekObjectData(*second_object,offset,whence);
    sw_printf("The seek Persistent funtion returns value is %x \n \n",
			   						seek_ret_val);

    sw_printf("*****Reset the seek object***** \n");
    TEE_ResetTransientObject(*second_object);

    open_delete_retval=TEE_OpenPersistentObject(storageID,delete_objectID,
					   			   objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion returns value is %x \n",
			   					open_delete_retval);

    TEE_CloseAndDeletePersistentObject(*second_object);
	
	sw_printf("*****Reset the close object***** \n");
    TEE_ResetTransientObject(*second_object);

	optest_deleted_retval=TEE_OpenPersistentObject(storageID,delete_objectID,
									objectIDLen,r_flags,second_object);

    sw_printf("The open Persistent object funtion \
returns value is %x \n \n",optest_deleted_retval);

	sw_printf("******TESTING:close and delete persistent object*******\n");
	if(optest_deleted_retval!=1) {
		sw_printf("SUCCESS \n");
	}
	else {
		sw_printf("FAILS\n");
	}
	
	sw_printf("*****Reset the seek object***** \n");
    TEE_ResetTransientObject(*second_object);

    TEE_Attribute* attref;
    attref=(TEE_Attribute*)TEE_Malloc(sizeof(TEE_Attribute),0);
    TEE_InitRefAttribute(attref,0x00000001,p_buffer,
						(size_t)(sw_strlen((char*)p_buffer)));
    TEE_Free((void*)attref);

	TEE_Attribute* attval;
    attval=(TEE_Attribute*)TEE_Malloc(sizeof(TEE_Attribute),0);
    TEE_InitValueAttribute(attval,0x20000000,a_attribute_val,b_attribute_val);
    TEE_Free((void*)attval);

    TEE_Attribute attributes[3];
	attributes[0].attributeID=0x20000000;
    attributes[0].content.value.a=0x0000000A;
    attributes[0].content.value.b=0x0000000B;

	attributes[1].attributeID=0x00000275;
	attributes[1].content.ref.length=(size_t)(sw_strlen((char*)attrsbuffer));
    attributes[1].content.ref.buffer=TEE_Malloc
		(attributes[1].content.ref.length,0);
    TEE_MemCpy(attributes[1].content.ref.buffer,attrsbuffer,
		(u32)(attributes[1].content.ref.length));

	attributes[2].attributeID=0x23425676;
    attributes[2].content.value.a=0x0000001E;
    attributes[2].content.value.b=0x0000001F;

    pop_ret_val=TEE_PopulateTransientObject(*second_object,attributes,
											attribute_cnt);

	sw_printf("the populate transient function returns value is %x \n",
			   pop_ret_val);
	
	sw_printf("*****Reset the populate object***** \n");
    TEE_ResetTransientObject(*second_object);

    TEE_CopyObjectAttributes(*second_object,*first_object);

	sw_printf("*****free the create object by call TEE_FreeTransientObject \
fn***** \n");
    TEE_FreeTransientObject(*first_object);

    sw_printf("*****free the common object by call TEE_FreeTransientObject \
fn***** \n");
    TEE_FreeTransientObject(*second_object);
    sw_printf("--------------Program Successfully Terminated--------------\n");	
}
Example #9
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);
}