Skip to content

kbs: zeroize JWE key material to prevent recovery from memory#183

Merged
jialez0 merged 1 commit into
openanolis:mainfrom
jialez0:trustee/coco-pickup-jwe-zeroize
Jun 9, 2026
Merged

kbs: zeroize JWE key material to prevent recovery from memory#183
jialez0 merged 1 commit into
openanolis:mainfrom
jialez0:trustee/coco-pickup-jwe-zeroize

Conversation

@jialez0

@jialez0 jialez0 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

背景

吸收上游 confidential-containers/trustee 的 JWE 密钥材料 zeroize 安全加固,降低密钥在内存/core dump/cold-boot 场景下被恢复的风险。

  • 上游 commit:confidential-containers/trustee 2274aa44(kbs: zeroize JWE key material to prevent recovery from memory)

改动内容

  • kbs/src/jwe.rs:将 ECDH 共享密钥 z、KDF 派生的 wrapping key、CEK、以及 RSA 路径的 AES 对称密钥用 zeroize::Zeroizing 包装,drop 时清零。
  • kbs/Cargo.toml:为 aes-gcm / aes / polyval 启用 zeroize feature(使 AES、GHASH key schedule 也被各自 crate 清零);将 zeroize 依赖转为常驻(从 encrypted-db feature 列表移除)。

说明:aes-kwKekAes256 派生了 Copy,无法 ZeroizeOnDrop,其内部 AES key schedule 无法覆盖(与上游一致的已知限制)。

适配说明(相对上游)

按本 fork 的 jwe.rs 布局重写(仅 P-256、使用 concat_kdf::derive_key_intoaes_kw::Kek API、thread_rng / log),而非直接 cherry-pick coco 的不同实现。

兼容性

  • 纯内部安全加固,外部不可观测。
  • 不新增/修改/删除任何 API、配置项或 wire-format。
  • 不改变默认行为;现有部署不受影响。

验证

  • cargo check -p kbs 通过。
  • cargo test -p kbs --lib jwe:: —— 3 个 JWE 兼容性测试全部通过(EC ECDH-ES+A256KW / RSA-OAEP-256 / RSA1.5,均用 josekit 解密回验),证明加密逻辑未被破坏。

@shankailun-aliyun

Copy link
Copy Markdown
Collaborator

@jialez0 ,您好,您的请求已接收,请耐心等待结果。

@shankailun-aliyun

Copy link
Copy Markdown
Collaborator

@jialez0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start

Sensitive key material in the JWE encryption paths -- the ECDH shared
secret, its KDF-derived wrapping key, and the CEK -- could survive in
heap or stack memory after use, making it recoverable via a memory
disclosure primitive, process core dump, or cold-boot attack.

Wrap all of these in Zeroizing so they are overwritten on drop. Enable
the zeroize feature on aes-gcm, aes, and polyval so the AES and GHASH key
schedules are also cleared by the crates themselves.

Note: the AES key schedule inside aes-kw's KekAes256 cannot be covered
because it derives Copy, precluding ZeroizeOnDrop.

Adapted from confidential-containers/trustee 2274aa44bc01f2e231fe5d0a1654203f820302ec
to this fork's jwe.rs layout (P-256 only, concat-kdf crate, aes-kw Kek API,
thread_rng/log). Purely internal hardening: no API, config, or wire-format
change; externally unobservable.

Signed-off-by: Jiale Zhang <xinjian.zjl@alibaba-inc.com>
@jialez0 jialez0 force-pushed the trustee/coco-pickup-jwe-zeroize branch from ed477f0 to 495b27e Compare June 8, 2026 08:17
@shankailun-aliyun

Copy link
Copy Markdown
Collaborator

@jialez0 ,您好,您的请求已接收,请耐心等待结果。

@shankailun-aliyun

Copy link
Copy Markdown
Collaborator

@jialez0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start

@jialez0 jialez0 merged commit 9246a52 into openanolis:main Jun 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants