google/go-configfs-tsm

GitHub: google/go-configfs-tsm

Google 开源的 Go 库,封装 Linux configfs/tsm 子系统,为可信执行环境提供厂商无关的远程证明报告生成接口。

Stars: 9 | Forks: 8

# go-configfs-tsm 本库封装了用于 Trusted Security Module 操作的 configfs/tsm Linux 子系统。 ## `report` 库 本库封装了 configfs/tsm/report 子系统,用于安全地生成 attestation report。 TSM `report` 子系统提供了一个与厂商无关的接口,用于为可信执行环境 (TEE) 的状态收集签名文档,以便进行远程验证。为简便起见,我们将此文档称为“attestation report”,尽管其他来源有时将其称为“quote”。 签名密钥预期可追溯至制造商。证书 可能存在于 `auxblob` 属性中,或作为 `outblob` 中 report 的一部分。 attestation report 交互的核心功能是输入 nonce,输出 report。 为了可测试性,我们抽象了创建 configfs report 条目、读写属性以及最终回收资源所需的文件操作。 ``` func Get(client configfsi.Client, req *report.Request) (*report.Response, error) ``` 其中 ``` type Request struct { InBlob []byte Privilege *Privilege GetAuxBlob bool } type Response struct { Provider string OutBlob []byte AuxBlob []byte } type Privilege struct { Level int } ``` Provider 可能未实现 `AuxBlob` 传递机制,因此如果 `GetAuxBlob` 为 true,则仍必须检查 `AuxBlob` 的长度是否为 0。 ### 错误 由于这是一个基于文件的系统,操作始终有可能 因权限错误而失败。默认情况下,TSM 系统需要 root 访问权限。 主机还可能对请求添加速率限制,使得读取 outblob 时 因 `EBUSY` 而失败。内核可能会也可能不会代表用户进行重试。 最后,由于 TSM report 系统仅在读取 `outblob` 或 `auxblob` 时请求 attestation report,因此输入 属性有可能已被干扰进程更改为意外值。这种干扰是用户空间的一个 bug,内核为简便起见并未阻止。 干扰通过 `generation` 属性显现。当 `generation` 与 `report` 包追踪的预期值不匹配时, `report.Get` 返回 `*report.GenerationErr` 或包装了 `*report.GenerationErr` 的 error。 使用 `func GetGenerationErr(error) *GenerationErr` 可从 error 中提取 `*GenerationErr` (前提是该 error 是或包含 `*report.GenerationErr`)。如果存在该错误,调用者 应尝试找出干扰源并将其移除。同时, 调用者可以重试。 ## `configfsi.Client` 接口 大多数用户只想使用来自 `linuxtsm.MakeClient` 的 client。 真实硬件上的 client 仅仅是文件系统,因为 configfs 交互将直接与硬件交互。但在单元测试中,我们可以 模拟补丁系列 v7 中提出的行为 ``` type Client interface { MkdirTemp(dir, pattern string) (string, error) ReadFile(name string) ([]byte, error) WriteFile(name string, contents []byte) error RemoveAll(path string) error } ``` `RemoveAll` 函数是唯一一个命名奇特的 method,因为真正的 接口只会在 report 目录下执行 `rmdir` (即 Golang 中的 [`os.Remove`](https://pkg.go.dev/os#Remove)),即使其下方存在 明显文件。通常不允许删除非空目录, 因此 `RemoveAll` 这个名称更能清晰地表达其作用。 ## `linuxtsm` 包 `linuxtsm` 包定义了 `configfsi.Client` 的一个实现,包含 ``` func MakeClient() (configfsi.Client, error) ``` 为了进一步提供便利,`linuxtsm` 为结合了 `report.Get` 的 `MakeClient` 提供了一个别名,即 ``` func GetReport(req *report.Request) (*report.Response, error) ``` 其用法与 `report.Get` 相同。 ## `faketsm` 包 `faketsm.Client` 实现允许测试按名称为子系统提供自定义行为: ``` type Client struct { Subsystems map[string]configfsi.Client } ``` `faketsm.ReportSubsystem` 类型实现了一个模拟 并发行为和 `generation` 属性语义的 client。为了同样能测试负面行为,该子系统允许用户覆盖 `Mkdir`、`ReadFile`、 现有条目的值,以及 `WriteFile` 的 error 行为。 ## 免责声明 这不是 Google 官方支持的产品。
标签:EVTX分析, Go, Linux内核, Ruby工具, 可信执行环境, 日志审计, 机密计算, 系统编程, 远程证明