# CBOR 对象签名与加密

**CBOR 对象签名与加密（CBOR Object Signing and Encryption，COSE）** 是一项 IETF 协议，为以简明二进制对象表示（Concise Binary Object Representation，CBOR）编码的数据提供密码学签名、消息认证码（MAC）和加密。CBOR 是一种紧凑的二进制数据格式，标准化为 STD 94（RFC 8949）。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 现行规范为 RFC 9052《COSE：结构与流程》，它与关于初始算法的 RFC 9053 一同废弃了 2017 年的原始规范 RFC 8152。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup> COSE 之于 CBOR，正如 JOSE（JSON 对象签名与[加密](https://www.edgepedia.org/zh/encryption)，包括 JWS 和 JWE）之于 JSON，其动机是 CBOR 对受限节点和受限节点网络的适用性。<sup>[3](https://www.ietf.org/proceedings/95/cose.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 现行规范 | RFC 9052（结构与流程），2022 年 8 月；与 RFC 9053（初始算法）一同废弃 RFC 8152<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> |
| 底层格式 | CBOR（STD 94，RFC 8949）；所有 COSE 消息结构均建立在 CBOR 数组类型之上<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> |
| 消息类型 | COSE_Sign（多签名者）、COSE_Sign1（单签名者，CBOR 标签 18）、COSE_Mac/COSE_Mac0，以及加密结构<sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup> |
| 通用结构 | 数组前三个元素：受保护的头部参数（bstr）、不受保护的头部参数（map）、内容（明文或密文，可分离）<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> |
| 头部参数 | alg（标签 1）、内容类型（3）、kid（4）、IV（5）、部分 IV（6）；计数器签名（7）已被 RFC 9338 废弃<sup>[5](https://www.iana.org/assignments/cose)</sup> |
| 密钥部署 | WebAuthn 凭证公钥以 COSE_Key 格式编码，使用 COSEAlgorithmIdentifier 值，如 -7（ES256）、-8（EdDSA）和 -257（RS256）<sup>[6](https://www.w3.org/TR/webauthn-3/?trk=article-ssr-frontend-pulse_little-text-block)</sup> |
| 已知局限 | 无统一填充机制；对于 RFC 9053 定义的所有内容加密算法，消息长度会暴露内容差异<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> |

## 目的及其与 JOSE 的关系

COSE 的诞生，是为了让 JOSE 工作组为 JSON 开发的基本安全服务——签名、MAC 和加密消息格式——能够应用于 CBOR 数据。<sup>[3](https://www.ietf.org/proceedings/95/cose.html)</sup> CBOR 是一种为受限设备和网络设计的简明二进制序列化格式，而 COSE 被称为在每一个字节和每一次内存分配都至关重要的场景中的首选密码学消息格式，应用包括物联网、固件更新（SUIT）、证明（EAT）、W3C [WebAuthn](https://www.edgepedia.org/zh/webauthn) 和数字凭证。<sup>[7](https://www.wolfssl.com/announcing-wolfcose-1-0-0-standards-based-cose-signing-encryption-and-authentication-for-constrained-environments/)</sup>

相关工作在安全领域一个同名 IETF 工作组中组织进行；RFC 8152 是 2017 年 7 月发布的原始规范，由 Jim Schaad 撰写。<sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup>

## 消息结构

所有 COSE 消息结构均建立在 CBOR 数组类型之上，前三个元素始终承载相同的信息：经编码并包裹在字节串（bstr）中的受保护头部参数、作为 CBOR map 的不受保护头部参数，以及消息内容，即相应的明文或[密文](https://www.edgepedia.org/zh/ciphertext)。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 内容可以是分离的，意味着它与 COSE 结构分开传输；此时内容位置仍出现在消息中，但持有 nil 值而非字节。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 第三个元素之后的元素取决于具体的消息类型。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup>

COSE 消息采用分层（layer）的概念来区分不同类型的密码学概念。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 对于加密消息的每个接收者，接收者层持有该接收者那份加密的 CEK 以及所用加密方法的详情。<sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup> 这种分层允许将同一份加密内容投递给多个接收者，每个接收者收到的是用不同密钥包裹的同一 CEK。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup>

消息结构的 CBOR 标签并非必需，因为每种安全消息都有唯一标识，但带标签的编码确实存在：带标签的 COSE_Sign 结构由 CBOR 标签 98 标识，单签名者 COSE_Sign1 消息使用标签 18。<sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup><sup> • </sup><sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup> 已为 COSE 内容注册了媒体类型，包括带 cose-type 参数的 application/cose，以及用于传递密钥的独立类型 application/cose-key 和 application/cose-key-set。<sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup>

## 头部参数与密钥

头部参数在 IANA COSE 注册表中以整数标签标识。RFC 9052 定义的参数包括 alg（标签 1，一个 int 或 tstr，命名来自 COSE 算法注册表的密码学算法）、内容类型（标签 3，标识载荷的内容类型）、kid（标签 4，密钥标识符）、IV（标签 5，完整初始化向量）和部分 IV（标签 6）。<sup>[5](https://www.iana.org/assignments/cose)</sup> RFC 8152 中定义的计数器签名参数（标签 7）已被 RFC 9338 废弃，后者定义了现行的计数器签名结构。<sup>[5](https://www.iana.org/assignments/cose)</sup><sup> • </sup><sup>[8](https://datatracker.ietf.org/doc/html/rfc9338)</sup>

密钥以 COSE_Key 结构表示，这是一个 CBOR map，字段包括 kty（密钥类型，标签 1）、kid（标签 2）、alg（标签 3）、key_ops（标签 4，允许的操作）和 Base IV（标签 5）；COSE_KeySet 是此类密钥的数组。<sup>[2](https://www.rfc-editor.org/info/rfc8152/)</sup> 应用程序还可以使用“crit”参数将头部参数标记为关键，此时应用程序必须在处理消息之前强制执行相关的安全考量。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup>

## 签名、MAC 与加密服务

COSE 支持两种不同的签名结构：COSE_Sign 携带正文并允许一个或多个签名者，COSE_Sign1 携带单个签名。<sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup> 在 RFC 9052 撰写之时，COSE 仅定义了带附录的签名可供使用，尽管有人对带消息恢复的签名算法表达了兴趣，因为这类算法可以减小体积；使用此类恢复签名时，可恢复字节的最大数量为原始载荷的长度。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 如果签名值的长度不是 8 位的整数倍，算法必须规定填充方式。<sup>[4](https://datatracker.ietf.org/doc/html/rfc9052)</sup>

MAC 结构（COSE_Mac 和 COSE_Mac0）使用共享密钥提供消息认证，加密结构则提供内容机密性。算法本身，如 AES-GCM、AES-CCM、HMAC、ECDSA 和 EdDSA，在配套文档 RFC 9053 中规定，并注册于 IANA COSE 算法注册表。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup><sup> • </sup><sup>[5](https://www.iana.org/assignments/cose)</sup> 另一份独立文档 RFC 9054 定义了 COSE 哈希算法，支持间接签名及其他用途；哈希结构携带哈希算法标识符、哈希值，以及指向进行哈希运算的原始值的指针，该值可以是文件、网络对象、消息中的某个位置或应用特定的内容。<sup>[9](https://www.rfc-editor.org/rfc/rfc9054.html)</sup>

RFC 9338 定义的计数器签名允许第二方对已有的 COSE 消息签名。计数器签名头部参数可作为不受保护属性出现在 COSE_Sign1、COSE_Signature、COSE_Encrypt、COSE_recipient、COSE_Encrypt0、COSE_Mac 和 COSE_Mac0 结构中，且计数器签名只能使用带附录的签名算法。<sup>[8](https://datatracker.ietf.org/doc/html/rfc9338)</sup> 简化计数器签名结构主要面向加密群组消息设计，此类场景中消息的发起者必须可识别。<sup>[10](https://datatracker.ietf.org/meeting/interim-2025-iesg-21/agenda/iesg-drafts.pdf)</sup>

## 应用

COSE 部署最广泛的用途是 Web 认证。在 WebAuthn 中，认证器创建的凭证公钥按 RFC 9052 第 7 节的定义以 COSE_Key 格式编码，使用 CTAP2 规范化 CBOR 编码，且必须包含持有 COSEAlgorithmIdentifier 值的“alg”参数。<sup>[6](https://www.w3.org/TR/webauthn-3/?trk=article-ssr-frontend-pulse_little-text-block)</sup> 希望支持广泛认证器的依赖方被建议至少包含算法标识符 -8（EdDSA）、-7（ES256）和 -257（RS256）。<sup>[6](https://www.w3.org/TR/webauthn-3/?trk=article-ssr-frontend-pulse_little-text-block)</sup> 安全支付确认规范同样对浏览器绑定的密钥对使用 COSEAlgorithmIdentifier 值和 COSE_Key 编码。<sup>[11](https://www.w3.org/TR/2026/CRD-secure-payment-confirmation-20261013/)</sup>

在远程证明中，实体证明令牌（Entity Attestation Token，EAT，RFC 9711）使用 COSE 保护；基础配置文件要求使用 COSE_Sign1，验证者必须持有正确的密钥才能执行 EAT 验证的密码学部分，例如检查 COSE 签名。<sup>[12](https://www.ietf.org/rfc/rfc9711.pdf)</sup> COSE 也是其他基于 CBOR 的 IETF 工作的安全层，COSE 工作组持续开发文档，包括后量子签名算法（如 FN-DSA）的序列化，以及 COSE 在 EDHOC 密钥交换和 Bundle Protocol Security 中的使用。<sup>[13](https://www.potaroo.net/ietf/html/ids-wg-cose.html)</sup><sup> • </sup><sup>[14](https://datatracker.ietf.org/doc/search?activedrafts=on&by=group&group=&name=cose&rfcs=on&sort=status)</sup>

## 安全考量

RFC 9052 强调了若干实现要求。私钥材料必须受到保护，且对两种不同算法使用同一密钥可能泄露密钥信息，因此密钥应限制为单一算法。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 将“direct”接收者算法与第二种接收者算法组合会使直接密钥暴露给第二接收者，规范第 8.5 节禁止将“direct”接收者算法与其他模式组合。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> RFC 9053 中的若干算法还限制了密钥在泄露信息之前可使用的次数。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup>

通过消息长度进行[流量分析](https://www.edgepedia.org/zh/traffic-analysis)是一项有据可查的局限：规范未提供统一的填充方法，对于 RFC 9053 定义的所有内容加密算法，观察者都可以根据长度区分两条不同的消息，例如“YES”和“NO”。因此，如果应用需要防止或阻碍此类分析，必须记录内容填充的方式。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup> 应用还被要求检查与密钥相关的限制（如算法和新鲜度），确认请求在给定应用状态下是合理的，并强制执行消息中携带的安全考量，包括“crit”头部参数所指明的那些。<sup>[1](https://www.rfc-editor.org/rfc/rfc9052.html)</sup>

## References

1. [Schaad, J. (2022). CBOR Object Signing and Encryption (COSE): Structures and Process. RFC 9052.](https://www.rfc-editor.org/rfc/rfc9052.html)
2. [Schaad, J. (2017). CBOR Object Signing and Encryption (COSE). RFC 8152.](https://www.rfc-editor.org/info/rfc8152/)
3. [IETF Proceedings 95: COSE working group session.](https://www.ietf.org/proceedings/95/cose.html)
4. [RFC 9052, Datatracker HTML version.](https://datatracker.ietf.org/doc/html/rfc9052)
5. [IANA: CBOR Object Signing and Encryption (COSE) registry.](https://www.iana.org/assignments/cose)
6. [W3C. Web Authentication: An API for accessing Public Key Credentials, Level 3.](https://www.w3.org/TR/webauthn-3/?trk=article-ssr-frontend-pulse_little-text-block)
7. [wolfSSL. Announcing wolfCOSE 1.0.0: Standards-based COSE signing, encryption, and authentication for constrained environments.](https://www.wolfssl.com/announcing-wolfcose-1-0-0-standards-based-cose-signing-encryption-and-authentication-for-constrained-environments/)
8. [Schaad, J. (2022). CBOR Object Signing and Encryption (COSE): Countersignatures. RFC 9338.](https://datatracker.ietf.org/doc/html/rfc9338)
9. [Schaad, J. (2022). CBOR Object Signing and Encryption (COSE): Hash Algorithms. RFC 9054.](https://www.rfc-editor.org/rfc/rfc9054.html)
10. [IESG interim meeting agenda material on COSE countersignatures.](https://datatracker.ietf.org/meeting/interim-2025-iesg-21/agenda/iesg-drafts.pdf)
11. [W3C. Secure Payment Confirmation, Candidate Recommendation Draft.](https://www.w3.org/TR/2026/CRD-secure-payment-confirmation-20261013/)
12. [Lundblade, L. et al. (2025). The Entity Attestation Token (EAT). RFC 9711.](https://www.ietf.org/rfc/rfc9711.pdf)
13. [Potaroo: CBOR Object Signing and Encryption (cose) Internet Drafts.](https://www.potaroo.net/ietf/html/ids-wg-cose.html)
14. [IETF Datatracker: COSE working group document search.](https://datatracker.ietf.org/doc/search?activedrafts=on&by=group&group=&name=cose&rfcs=on&sort=status)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › 安全治理与互联网政策 › 密码协议 › 协议标准与规范

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cbor-object-signing-and-encryption

English original: https://www.edgepedia.org/cbor-object-signing-and-encryption
