您现在的位置是:主页 > news > 旅游景点推广策划方案/个人seo外包
旅游景点推广策划方案/个人seo外包
admin2025/4/22 3:56:06【news】
简介旅游景点推广策划方案,个人seo外包,js导入wordpress,没备案可以做网站么目录一、基本文件操作流程1.1 安全文件的创建1.2 安全文件的读取(待完善)接上文: OP-TEE内核学习笔记(一)(安全存储)—— GP 安全存储 API OP-TEE内核学习笔记(一)&#…
目录
- 一、基本文件操作流程
- 1.1 安全文件的创建
- 1.2 安全文件的读取(待完善)
接上文:
OP-TEE内核学习笔记(一)(安全存储)—— GP 安全存储 API
OP-TEE内核学习笔记(一)(安全存储)—— 密钥和文件结构
了解了以上基本概述后,我们接下来看一下详细的安全文件的基础操作,了解OPTEE是如何处理安全文件的数据的。
因为OPTEE
中没有文件系统的功能,需要借助tee_supplicant
守护进程来完成访问文件系统的工作。读写安全文件也是类似的过程,TA
发送RPC
请求给tee_supplicant
,tee_supplicant
完成参数的解析和数据操作。
一、基本文件操作流程
当 TA 调用 GP 可信存储 API 提供的写入函数以将数据写入持久性对象时,将调用在 TEE 可信存储服务中实现的相应系统调用,而后者又会调用一系列 TEE 文件操作来存储数据。然后,TEE 文件系统将加密数据,并通过一系列 RPC 消息将 REE 文件操作命令和加密数据发送给 REE。REE将接收消息并相应地将加密数据存储到 Linux 文件系统。读取文件以类似的方式处理。架构图如图所示:
/** Returns the appropriate tee_file_operations * for the specified storage ID.* The value TEE_STORAGE_PRIVATE will select * the REE FS if available, otherwise RPMB.*/const struct tee_file_operations ree_fs_ops = {.open = ree_fs_open,.create = ree_fs_create,.close = ree_fs_close,.read = ree_fs_read,.write = ree_fs_write,.truncate = ree_fs_truncate,.rename = ree_fs_rename,.remove = ree_fs_remove,.opendir = ree_fs_opendir_rpc,.closedir = ree_fs_closedir_rpc,.readdir = ree_fs_readdir_rpc,
};const struct tee_file_operations rpmb_fs_ops = {.open = rpmb_fs_open,.create = rpmb_fs_create,.close = rpmb_fs_close,.read = rpmb_fs_read,.write = rpmb_fs_write,.truncate = rpmb_fs_truncate,.rename = rpmb_fs_rename,.remove = rpmb_fs_remove,.opendir = rpmb_fs_opendir,.closedir = rpmb_fs_closedir,.readdir = rpmb_fs_readdir,
};static const struct tee_file_operations *file_ops(uint32_t storage_id)
{switch (storage_id) {case TEE_STORAGE_PRIVATE:
#if defined(CFG_REE_FS)return &ree_fs_ops; /* TEE_STORAGE_PRIVATE * ree fs 服务可用,则直接使用ree fs文件系统 */
#elif defined(CFG_RPMB_FS)return &rpmb_fs_ops;
#else
#error At least one filesystem must be enabled.
#endif
#ifdef CFG_REE_FScase TEE_STORAGE_PRIVATE_REE:return &ree_fs_ops;
#endif
#ifdef CFG_RPMB_FScase TEE_STORAGE_PRIVATE_RPMB:return &rpmb_fs_ops;
#endifdefault:return NULL;}
}
以下安全文件的操作以REE_FS
为例进行分析。
1.1 安全文件的创建
在TA中调用TEE_CreatePersistentObject
接口时会创建安全文件。在创建安全文件时会初始化安全文件的数据区域。在OP-TEE
内核空间调用对应的读写接口syscall_storage_obj_create
函数来完成对安全文件中数据的创建。
TEE_CreatePersistentObject -> syscall_storage_obj_create -> tee_svc_storage_init_file -> ree_fs_open
我们看一下其中的open
函数ree_fs_open
static TEE_Result ree_fs_open(struct tee_pobj *po, size_t *size,struct tee_file_handle **fh)
{
...res = get_dirh(&dirh);res = ree_fs_open_primitive(false, dfh.hash, &po->uuid, &dfh, fh);
...
}
我们看一下其中的ree_fs_open
函数get_dirh
static TEE_Result get_dirh(struct tee_fs_dirfile_dirh **dirh)
{if (!ree_fs_dirh) {TEE_Result res = open_dirh(&ree_fs_dirh);if (res) {*dirh = NULL;return res;}}ree_fs_dirh_refcount++;assert(ree_fs_dirh);assert(ree_fs_dirh_refcount);*dirh = ree_fs_dirh;return TEE_SUCCESS;
}static void put_dirh_primitive(bool close)
{assert(ree_fs_dirh_refcount);assert(ree_fs_dirh);ree_fs_dirh_refcount--; /* 引用次数为0,则将ree_fs_dirh置为空 */if (!ree_fs_dirh_refcount || close)close_dirh(&ree_fs_dirh);
}static void close_dirh(struct tee_fs_dirfile_dirh **dirh)
{tee_fs_dirfile_close(*dirh);*dirh = NULL;
}
通过ree_fs_dirh_refcount
全局变量 来控制是创建dirf.db
文件,还是打开dirf.db
文件。ree_fs_dirh_refcount
引用次数为0,则ree_fs_dirh为空,需要打开dirf.db
文件。
往下,我们继续看一下其中的ree_fs_open
函数ree_fs_open_primitive
函数:
TEE_Result tee_fs_dirfile_open(bool create, uint8_t *hash,const struct tee_fs_dirfile_operations *fops,struct tee_fs_dirfile_dirh **dirh_ret)
{
...dirh->fops = fops;res = fops->open(create, hash, NULL, NULL, &dirh->fh);
...
}static const struct tee_fs_dirfile_operations ree_dirf_ops = {.open = ree_fs_open_primitive,.close = ree_fs_close_primitive,.read = ree_fs_read_primitive,.write = ree_fs_write_primitive,.commit_writes = ree_dirf_commit_writes,
};
tee_ree_fs.c
中的 ree_fs_open_primitive
函数
static TEE_Result ree_fs_open_primitive(bool create, uint8_t *hash,const TEE_UUID *uuid,struct tee_fs_dirfile_fileh *dfh,struct tee_file_handle **fh)
{
...if (create)res = tee_fs_rpc_create_dfh(OPTEE_MSG_RPC_CMD_FS,dfh, &fdp->fd);elseres = tee_fs_rpc_open_dfh(OPTEE_MSG_RPC_CMD_FS, dfh, &fdp->fd);if (res != TEE_SUCCESS)goto out;res = tee_fs_htree_open(create, hash, uuid, &ree_fs_storage_ops,fdp, &fdp->ht);
...
}
TEE_Result tee_fs_htree_open(bool create, uint8_t *hash, const TEE_UUID *uuid,const struct tee_fs_htree_storage *stor,void *stor_aux, struct tee_fs_htree **ht_ret)
{
...if (create) {const struct tee_fs_htree_image dummy_head = { .counter = 0 };/* 在创建`dirf.db`文件过程中会产生一个随机数作为FEK,* 且在调用`update_root`函数时会产生另外一个随机数作为加密`FEK`的`IV`值* 并保存到`head.iv`中。每次文件的更新时,该IV值都会被新的随机数替代。 * */res = crypto_ops.prng.read(ht->fek, sizeof(ht->fek));if (res != TEE_SUCCESS)goto out;res = tee_fs_fek_crypt(ht->uuid, TEE_MODE_ENCRYPT, ht->fek,sizeof(ht->fek), ht->head.enc_fek);if (res != TEE_SUCCESS)goto out;/* 初始化root node, 计算ht->root.node.hash 后续校验时使用 */res = init_root_node(ht);/* 哈希树上内容通过后序遍历方式同步到安全存储文件上 */res = tee_fs_htree_sync_to_storage(&ht, hash);res = rpc_write_head(ht, 0, &dummy_head);} else {/* 读取dirf.db文件,调用rpc_read_node rpc_read* 读取dirf.db中的root node信息* 其中函数调用过程:init_head_from_data -> * rpc_read_node -> rpc_read */res = init_head_from_data(ht, hash);if (res != TEE_SUCCESS)goto out;/* 解密出root node内容并校验 */res = verify_root(ht);if (res != TEE_SUCCESS)goto out;/* 读取dirf.db中所有node信息并创建文件的节点树 */res = init_tree_from_data(ht);if (res != TEE_SUCCESS)goto out;/* #计算各节点内容的hash值,并与保存的hash进行比对,来校验整个hashtree是否合法 */res = verify_tree(ht);
...
}
安全文件创建完成之后,会将初始化数据加密后写入到安全文件中,然后更新整个安全文件的tee_fs_htree_node_image
区域以及保存在文件头的tee_fs_htree_image
区域,到此安全文件创建就已完毕。
为后续能够通过dirf.db
文件找到该安全文件,则还需要更新dirf. db
文件的内容,主要是更新dirf.db
文件数据区域中的dirfile_entry
数据。
1.2 安全文件的读取(待完善)
TA
对安全文件进行读写操作是通过调用TEE_ReadObjectData
和TEE_WriteObjectData
函数来实现的。这两个函数的执行最终会进入OP-TEE
的内核空间中。
在OP-TEE
内核空间调用对应的读写接口syscall_storage_obj_read
和syscall_storage_obj_write
函数来完成对安全文件中数据的读写操作。