keystone workflow

Steps and Workflow

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值