Steps and Workflow
ocall.h
(脚本查找这个文件),这是在飞地内
* 函数签名
*ocalls_header.h
(this has 声明 for keyedge datatypes, e.g., keyedge str, var length arrays)
* 还可以包含特定于程序的结构头(如mystruct.h
)
* 如果mysthuct.h
有一个字符串或一个 car length 数组会发生什么host.c
(定义函数,在飞地之外,在主机中)- 包括
ocalls_host.h
(这个文件是由我们的工具自动生成的) - the function definition need not use any of the keyedge str and so on
- 需要在飞地的初始化之前调用
register_functions()
- 即使没有 keyedge,keystone 也能做到这一点
- 具体来说,这是 调用桥/函数表,获取数字并跳转到函数
- 包括
- Make file changes
- vault
- new keyedge vault
- 处理
ocalls.h
并调用flatcc
- keyedge 在构建主机和 enclave 二进制文件之前
- 工具步骤
- keyedge处理
keyedge处理
首先为ocalls
组装用户定义的函数keyedge处理
使用ocalls.h
来生成4个文件keyedge处理
keyedge 中的main.cpp
3.1 ---
parser.cpp
- 获取输入,调用 clang,创建 AST
- 遍历 AST,收集函数名、签名、结构
- 将它们存储在自定义数据结构中
3.2 ---
emitter.cpp
- 通过我们的自定义数据结构
- 创建 4 个文件(基于 cout、ofstream)
ocalls.fbs
: flatcc 文件,具有 flatcc 格式的函数信息ocalls_common.h
: 具有 enclave 和主机都使用的声明,具有包含函数表中的函数调用号的桥ocalls_eapp.h
: 有声明和实施 ; 模板如下所示:- 序列化来自飞地的所有参数---->执行呼叫---->反序列化返回----> 释放输入的序列化缓冲---->所有这一切都使用 flatcc 格式---->无法释放返回值缓冲区---->现在输出缓冲区大小为 1KB---->因为我们没有事先计算返回大小----> 我们可以通过为 flatcc 的每个已知数据类型预先计算大小来改进这一点
ocalls_host.h
: 有声明和实施- 三个步骤:
- 解析输入,我们将输入缓冲区指针作为函数的输入
- 调用函数
- 将值写入一个新的缓冲区
- 将 flatcc 值从那里复制到共享 buf
- 它通过调用
edge_call_data_ptr()
知道 keystone 提供的输出共享缓冲区地址 - 用来在主机中调用该函数的包装器
- 从内存输入,不返回,因为 flatcc
- 可以改进:将副本数从 4 减少到 2
- 目前没有检查,我们只是使用调用中提供的大小
- 也有 register_functions() 的函数定义
- 三个步骤:
3.3 ---
flatcc (from the build script)
: 告诉 flatcc 这是 fbs 文件- creates 5 files
ocall_reader.h
,ocall_builder.h
- 当我们读取一些东西(反序列化)或构建一个flatcc结构体(序列化)时,我们需要包含这些文件
- we include this in
ocall_eapps.h
andocall_host.h
ocall_verifier.h
- 缓冲区是否可读或格式正确
- 还没有被使用,我们至少应该在飞地内使用它以确保安全
flatbuffers_common_reader.h
- included in
ocall_reader.h
- keyedge 不会在任何地方明确包含这个
- included in
flatbuffers_common_builder.h
- included in the
ocall_builder.h
- keyedge does not include this explicitly anywhere(keyedge 不会在任何地方明确包含这个)
- included in the
- creates 5 files
3.4 ---
flatcc runtime libraries
: 当我们运行顶级 make 时,它使用 risc-v gcc 工具链生成这些库flatccrt.a
- src/runtime:
builder.c
,emitter.c
,refmap.c
,verifier.c
- use libc functions such as
realloc
,malloc
(see slack list for details) - 五个functions:
strcmp
,strncmp
,_assert_fail
,memchr
,posix_memalign
- 这些都没有在eyrie rt中实现,所以我们为这些内容添加了我们自己的实现(从互联网上获取)
comman_header.h
has it- this file is included in the
eapp.c
- 需要将这些实现转移到eyrie RT上
- need these for linking flatccrt.a
- src/runtime:
- 链接步骤 — 生成与 v-ault 相同的东西(eyrie、eapp、host)
- keyedge处理
- Testing with demo
- make
- does not use vault
- demo has multiple files, not as simple as
host.c
andeapp.c
- 基本偏移量和参数的一些问题
- 目前我们的 keyedge 版本中缺少检查
- interesting signatures we have in this case are
- inputs
- print 缓冲区的字符串
- 用于发送报告的不同类型的可变长度数组
- return
- 针对公钥的固定大小的数组
- 可变长度的return for input message
- inputs
- make